一、映射
在matlab中,矢量y正交映射到矢量x上的定义如下:
子空间映射是一个例子,其中矩阵的功率线性代数记号非常重要。
代码实现如下:
>> 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 >>
>> 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 >>