matlab 复数矩阵相乘,c – 复数矩阵乘法Eigen vs Matlab

有人可以向我解释为什么结果会有所不同.

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的dobule.

解决方法:

因此,如果您将MATLAB测试更改为

testTest*testTest.'

结果应该是一样的.

如果你想在eigen中进行复数转置,那么你可以去matrix.adjoint()(或matrix.conjugate().transpose())

标签:c,matlab,eigen

来源: https://codeday.me/bug/20190824/1710057.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值