Complex multiplication of matrix of numbers Eigen vs Matlab

Can someone explain to me why the results are different.

Code in 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;

      

Results from 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)

      

And the same as written in 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 results:

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

      

The multiplication testTest * testTest 'in C returns complex numbers with real part 0 and imaginary part 28. Matlab only returns dobule with value 28.

+3


source to share


1 answer


'

in Matlab does transpose and takes complex conjugation ( http://uk.mathworks.com/help/matlab/ref/ctranspose.html ). If you just want to use transpose, use .'

(with dot infront).

Thus, if you change your MATLAB test to

testTest*testTest.'

      



the results should be the same.

If you want a complex transpose in your own, you can go matrix.adjoint()

(or matrix.conjugate().transpose()

)

+6


source







All Articles