2012-08-10 164 views
1

我有8个罪和余弦,我试图象征性地定义,如下所示使用Matlab。我的目标是使用所有这些罪和余弦象征性地构建8×8的矩阵H(累积Givens旋转矩阵),并最终看到该H正交投影矩阵的公式是什么。我可以这样做,使用下面的代码G7*G6*...*G0*I,其中I是身份8x8,Gi是与元素(i:i + 1,i:i + 1)对应的Givens旋转。最简单的方法来创建符号正交矩阵

c_0 = sym('c_0'); 
c_1 = sym('c_1'); 
c_2 = sym('c_2'); 
c_3 = sym('c_3'); 
c_4 = sym('c_4'); 
c_5 = sym('c_5'); 
c_6 = sym('c_6'); 
c_7 = sym('c_7'); 

s_0 = sym('s_0'); 
s_1 = sym('s_1'); 
s_2 = sym('s_2'); 
s_3 = sym('s_3'); 
s_4 = sym('s_4'); 
s_5 = sym('s_5'); 
s_6 = sym('s_6'); 
s_7 = sym('s_7'); 

% create H orthogonal matrix using the sin and cos symbols 
% filling in the first rotation 
I=eye(9,9) 
H = I; 
H(1:2,1:2) = [c_0 -s_0; s_0 c_0] 

% build the 2nd rotation and update H 
G = I; 
G(2:3,2:3) = [c_1 -s_1; s_1 c_1] 
H = G*H 

% build the 3rd rotation and update H 
G = I; 
G(3:4,3:4) = [c_2 -s_2; s_2 c_2] 
H = G*H 

% build the 4rth rotation and update H 
G = I; 
G(4:5,4:5) = [c_3 -s_3; s_3 c_3] 
H = G*H 

% build the 5th rotation and update H 
G = I; 
G(5:6,5:6) = [c_4 -s_4; s_4 c_4] 
H = G*H 

% build the 6th rotation and update H 
G = I; 
G(6:7,6:7) = [c_5 -s_5; s_5 c_5] 
H = G*H 

% build the 7th rotation and update H 
G = I; 
G(7:8,7:8) = [c_6 -s_6; s_6 c_6] 
H = G*H 

% build the 8th rotation and update H 
G = I; 
G(8:9,8:9) = [c_7 -s_7; s_7 c_7] 
H = G*H 

代码失败,出现以下错误,无法找到如何解决此问题:

The following error occurred converting from sym to double: 
Error using mupadmex 
Error in MuPAD command: DOUBLE cannot convert the input expression into a double array. 
If the input expression contains a symbolic variable, use the VPA function instead. 

Error in build_rotH_test (line 26) 
H(1:2,1:2) = [c_0 -s_0; s_0 c_0] 
+1

我inital的想法是,你得到的错误,因为* H *是双,尝试做* H =符号(I); *我不知道这是否会使所有的工作,但它应该消除你的错误。 – Ghaul 2012-08-10 13:33:21

+0

谢谢。我已经知道了。我会尽快发布解决方案,只要我被允许。问题是Matlab不允许将符号变量与实际值(如眼球产生的)结合起来,所以我也将零和零作为变量来构建,然后工作正常。 – 2012-08-10 13:36:42

回答

1

我解决了它这样的。注意我意识到我需要每次旋转的转置,所以我可以构建并应用H'* x,即G7'*G6'*...*G0'*I这就是为什么在解决方案中翻转了错误符号的原因。

clear all; 

% defining 0 and 1 as symbols too, solves the problem 
sym_0 = sym('0'); 
sym_1 = sym('1'); 

c0 = sym('c0'); 
c1 = sym('c1'); 
c2 = sym('c2'); 
c3 = sym('c3'); 
c4 = sym('c4'); 
c5 = sym('c5'); 
c6 = sym('c6'); 
c7 = sym('c7'); 

s0 = sym('s0'); 
s1 = sym('s1'); 
s2 = sym('s2'); 
s3 = sym('s3'); 
s4 = sym('s4'); 
s5 = sym('s5'); 
s6 = sym('s6'); 
s7 = sym('s7'); 

% create H orthogonal matrix using the sin and cos symbols 
% filling in the first rotation 
I = repmat(sym_0,9,9); 
for i=1:9 
    I(i,i)=sym_1; 
end 
H = I 
H(1:2,1:2) = [c0 s0; -s0 c0] 

% build the 2nd rotation and update H 
G = I; 
G(2:3,2:3) = [c1 s1; -s1 c1] 
H = G*H; 

% build the 3rd rotation and update H 
G = I; 
G(3:4,3:4) = [c2 s2; -s2 c2] 
H = G*H; 

% build the 4rth rotation and update H 
G = I; 
G(4:5,4:5) = [c3 s3; -s3 c3] 
H = G*H; 

% build the 5th rotation and update H 
G = I; 
G(5:6,5:6) = [c4 s4; -s4 c4] 
H = G*H; 

% build the 6th rotation and update H 
G = I; 
G(6:7,6:7) = [c5 s5; -s5 c5] 
H = G*H; 

% build the 7th rotation and update H 
G = I; 
G(7:8,7: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 0, 0, 0, 0, 0, 0, 0, 1] 


G = 

[ 1, 0, 0, 0, 0, 0, 0, 0, 0] 
[ 0, 1, 0, 0, 0, 0, 0, 0, 0] 
[ 0, 0, 1, 0, 0, 0, 0, 0, 0] 
[ 0, 0, 0, 1, 0, 0, 0, 0, 0] 
[ 0, 0, 0, 0, 1, 0, 0, 0, 0] 
[ 0, 0, 0, 0, 0, 1, 0, 0, 0] 
[ 0, 0, 0, 0, 0, 0, c6, s6, 0] 
[ 0, 0, 0, 0, 0, 0, -s6, c6, 0] 
[ 0, 0, 0, 0, 0, 0, 0, 0, 1] 


G = 

[ 1, 0, 0, 0, 0, 0, 0, 0, 0] 
[ 0, 1, 0, 0, 0, 0, 0, 0, 0] 
[ 0, 0, 1, 0, 0, 0, 0, 0, 0] 
[ 0, 0, 0, 1, 0, 0, 0, 0, 0] 
[ 0, 0, 0, 0, 1, 0, 0, 0, 0] 
[ 0, 0, 0, 0, 0, 1, 0, 0, 0] 
[ 0, 0, 0, 0, 0, 0, 1, 0, 0] 
[ 0, 0, 0, 0, 0, 0, 0, c7, s7] 
[ 0, 0, 0, 0, 0, 0, 0, -s7, c7] 


H = 

[      c0,      s0,      0,     0,    0,   0,   0,  0, 0] 
[     -c1*s0,     c0*c1,     s1,     0,    0,   0,   0,  0, 0] 
[     c2*s0*s1,    -c0*c2*s1,     c1*c2,     s2,    0,   0,   0,  0, 0] 
[    -c3*s0*s1*s2,    c0*c3*s1*s2,    -c1*c3*s2,    c2*c3,    s3,   0,   0,  0, 0] 
[   c4*s0*s1*s2*s3,   -c0*c4*s1*s2*s3,   c1*c4*s2*s3,   -c2*c4*s3,   c3*c4,   s4,   0,  0, 0] 
[  -c5*s0*s1*s2*s3*s4,  c0*c5*s1*s2*s3*s4,  -c1*c5*s2*s3*s4,  c2*c5*s3*s4,  -c3*c5*s4,  c4*c5,  s5,  0, 0] 
[  c6*s0*s1*s2*s3*s4*s5, -c0*c6*s1*s2*s3*s4*s5,  c1*c6*s2*s3*s4*s5, -c2*c6*s3*s4*s5,  c3*c6*s4*s5, -c4*c6*s5,  c5*c6,  s6, 0] 
[ -c7*s0*s1*s2*s3*s4*s5*s6, c0*c7*s1*s2*s3*s4*s5*s6, -c1*c7*s2*s3*s4*s5*s6, c2*c7*s3*s4*s5*s6, -c3*c7*s4*s5*s6, c4*c7*s5*s6, -c5*c7*s6, c6*c7, s7] 
[ s0*s1*s2*s3*s4*s5*s6*s7, -c0*s1*s2*s3*s4*s5*s6*s7, c1*s2*s3*s4*s5*s6*s7, -c2*s3*s4*s5*s6*s7, c3*s4*s5*s6*s7, -c4*s5*s6*s7, c5*s6*s7, -c6*s7, c7]