matlab基础学习(5)之映射和正交基
一、映射
在matlab中,矢量y正交映射到矢量x上的定义如下:
Px(y) = /(x^2)*x
对于长度为N的列矢量y映射到长度为N的列矢量x上的计算方法如下:
yx = (x' * y) * (x' * x) ^ (-1) * x
更一般的, 长度为N的列矢量y映射到M维的子空间的 N x M的矩阵x,计算方法如下:
yX = X * (X' * X)^(-1) * X' * y
正交映射,像任何的有限维线性操作符,可通过矩阵表示,对于N x M矩阵,计算方法为:
PX = X * (X' * X)^(-1) * X'
PX被称为映射矩阵。
子空间映射是一个例子,其中矩阵的功率线性代数记号非常重要。
代码实现如下:
>> X = [[1;2;3],[1;0;1]]
X =
1 1
2 0
3 1
>> PX = X*(X'*X)^(-1) * X'
PX =
0.66666666666667 -0.33333333333333 0.33333333333333
-0.33333333333333 0.66666666666667 0.33333333333333
0.33333333333333 0.33333333333333 0.66666666666667
>> y = [2; 4;6]
y =
2
4
6
>> yX= PX* y
yX =
2.00000000000000
4.00000000000000
6.00000000000000
>>
二、正交基
在matlab中,函数orth()对于给定的矢量集空间计算正交基。
在matlab中输入help orth查看orth的使用:
>> help orth
ORTH Orthogonalization.
Q = ORTH(A) is an orthonormal basis for the range of A.
That is, Q'*Q = I, the columns of Q span the same space as
the columns of A, and the number of columns of Q is the
rank of A.
Class support for input A:
float: double, single
See also svd, rank, null.
Reference page in Help browser
doc orth
>>
以下通过对N=3的线性独立的基利用orth()进行正交化。
>> v1 = [1;2;3]
v1 =
1
2
3
>> v2 = [1;-2;3]
v2 =
1
-2
3
>> v1' * v2
ans =
6
>> V=[v1,v2]
V =
1 1
2 -2
3 3
>> W= orth(V)
W =
-0.31622776601684 0.00000000000000
0.00000000000000 -1.00000000000000
-0.94868329805051 0.00000000000000
>> W= orth(V)
W =
-0.31622776601684 0.00000000000000
0.00000000000000 -1.00000000000000
-0.94868329805051 0.00000000000000
>> W1=W(:,1)
W1 =
-0.31622776601684
0.00000000000000
-0.94868329805051
>> W2=W(:,2)
W2 =
0.00000000000000
-1.00000000000000
0.00000000000000
>> W1' * W2
ans =
-3.157438761082832e-016
>> W1'*W1
ans =
1.00000000000000
>> W2'*W2
ans =
1
>> W'*W
ans =
1.00000000000000 -0.00000000000000
-0.00000000000000 1.00000000000000
>> x = 2 * v1 - 3 * v2
x =
-1
10
-3
>> c1 = x' * W1
c1 =
3.16227766016838
>> c2 = x' * W2
c2 =
-10
>> xw = c1 * W1 + c2 * W2
xw =
-1.00000000000000
10.00000000000000
-3.00000000000000
>> error = x - xw
error =
1.0e-014 *
0.13322676295502
0
0.08881784197001
>> norm(error)
ans =
1.601186416994689e-015
>> x = [1; 0; 0]
x =
1
0
0
>> ca = x' * W1
ca =
-0.31622776601684
>> c1 = x' * W1
c1 =
-0.31622776601684
>> c2 = x' * W2
c2 =
1.387778780781446e-016
>> xw = c1 * W1 + c2 * W2
xw =
0.10000000000000
-0.00000000000000
0.30000000000000
>> error = x - xw
error =
0.90000000000000
0.00000000000000
-0.30000000000000
>> norm(error)
ans =
0.94868329805051
>> W* error
??? Error using ==> mtimes
Inner matrix dimensions must agree.
>> W'* error
ans =
1.0e-015 *
-0.16653345369377
-0.09984698057522
>>