复数矩阵乘法特征vs Matlab

  • 本文关键字:特征 vs Matlab c++ matlab eigen
  • 更新时间 :
  • 英文 :


谁能给我解释一下为什么结果不一样?

c++代码:

MatrixXcd testTest;
testTest.resize(3,3);
testTest.real()(0,0) = 1;
testTest.real()(0,1) = 2;
testTest.real()(0,2) = 3;
testTest.real()(1,0) = 1;
testTest.real()(1,1) = 2;
testTest.real()(1,2) = 3;
testTest.real()(2,0) = 1;
testTest.real()(2,1) = 2;
testTest.real()(2,2) = 3;
testTest.imag()(0,0) = 1;
testTest.imag()(0,1) = 2;
testTest.imag()(0,2) = 3;
testTest.imag()(1,0) = 1;
testTest.imag()(1,1) = 2;
testTest.imag()(1,2) = 3;
testTest.imag()(2,0) = 1;
testTest.imag()(2,1) = 2;
testTest.imag()(2,2) = 3;
cout<< endl << testTest << endl;
cout<< endl << testTest.transpose() << endl;
cout<< endl << testTest*testTest.transpose() << endl;
cout<< endl << testTest << endl;

c++的结果:

(1,1) (2,2) (3,3)
(1,1) (2,2) (3,3)
(1,1) (2,2) (3,3)
(1,1) (1,1) (1,1)
(2,2) (2,2) (2,2)
(3,3) (3,3) (3,3)
(0,28) (0,28) (0,28)
(0,28) (0,28) (0,28)
(0,28) (0,28) (0,28)
(1,1) (2,2) (3,3)
(1,1) (2,2) (3,3)
(1,1) (2,2) (3,3)

用Matlab写同样的东西:

testTest = [ complex(1,1) complex(2,2) complex(3,3); 
             complex(1,1) complex(2,2) complex(3,3); 
             complex(1,1) complex(2,2) complex(3,3)];
testTest
testTest'
testTest*testTest'
testTest
Matlab结果:

testTest =
1.0000 + 1.0000i   2.0000 + 2.0000i   3.0000 + 3.0000i
1.0000 + 1.0000i   2.0000 + 2.0000i   3.0000 + 3.0000i
1.0000 + 1.0000i   2.0000 + 2.0000i   3.0000 + 3.0000i

ans =
1.0000 - 1.0000i   1.0000 - 1.0000i   1.0000 - 1.0000i
2.0000 - 2.0000i   2.0000 - 2.0000i   2.0000 - 2.0000i
3.0000 - 3.0000i   3.0000 - 3.0000i   3.0000 - 3.0000i

ans =
28    28    28
28    28    28
28    28    28

testTest =
1.0000 + 1.0000i   2.0000 + 2.0000i   3.0000 + 3.0000i
1.0000 + 1.0000i   2.0000 + 2.0000i   3.0000 + 3.0000i
1.0000 + 1.0000i   2.0000 + 2.0000i   3.0000 + 3.0000i

C中testTest * testTest的乘法返回实数部分为0,映像部分为28的复数。Matlab返回值为28的双精度。

'在Matlab中进行转置并取复共轭(http://uk.mathworks.com/help/matlab/ref/ctranspose.html)。如果你只想做转置,使用.'(前面有一个点)。

因此,如果您将MATLAB测试更改为
testTest*testTest.'

结果应该是相同的。

如果你想在本征中得到复转置你可以用matrix.adjoint()(或matrix.conjugate().transpose())

最新更新