在Matlab中乘以复杂矩阵 [英] Multiplying complex matrices in Matlab

查看:114
本文介绍了在Matlab中乘以复杂矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将代码从matlab移植到C.为了将此行转换为C:

I'm trying to port a code from matlab to C. In order to convert this line to C:

A = E*[SOLS' ; ones(1,10 ) ]; 

在哪里

>>size(SOLS)

ans =

10     3

和:

>> size(E)

ans =

 9     4

SOLS是一个复杂的单个矩阵,E是一个实际的单个矩阵,A应该是大小为9x10的一个复杂的单个矩阵.

SOLS is a complex single matrix and E is a real single matrix and A should be a complex single matrix of size 9x10.

我将A = E*[SOLS' ; ones(1,10 ) ];替换为

for i=1:9
  for j=1:10
    A1(i,j)=E(i,1)*SOLS(j,1))+E(i,2)*SOLS(j,2))+E(i,3)*SOLS(j,3))+E(i,4);
   end
end

复杂的合成矩阵元素的实部与A相同,而虚部则不同.

The complex resultant matrix elements have the same real part as A but a different imaginary part.

>> real(A)=real(A1)
imag(A) and `imag(A1)` are different.

是什么导致了这种差异?如何将matlab命令正确转换为C?

What caused this difference? How to convert the matlab command correctly to C?

以下是矩阵的示例:

    E =

    0.2248         0         0         0
   -0.4487   -0.1632   -0.1955    0.6355
    0.4379   -0.0651   -0.1032   -0.0754
   -0.4008    0.3513    0.2707   -0.5936
   -0.2294   -0.7853   -0.3290   -0.4648
    0.0385    0.2623   -0.6363   -0.0978
   -0.5716    0.0851    0.0943    0.0587
    0.1160   -0.3911    0.5964    0.0947
    0.0363   -0.0039   -0.0092   -0.0018

    SOLS =

   1.0e+02 *

  -0.2410 + 0.0000i   2.3741 + 0.0000i  -0.0646 + 0.0000i
   0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0113 - 0.0046i
   0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0113 + 0.0046i
  -0.0028 + 0.0000i  -0.0114 + 0.0000i  -0.0038 + 0.0000i
   0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0024 - 0.0043i
   0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0024 + 0.0043i
   0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0007 - 0.0191i
   0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0007 + 0.0191i
  -0.0080 + 0.0000i   0.0064 + 0.0000i   0.0108 + 0.0000i
  -0.7289 + 0.0000i   4.9347 + 0.0000i   0.3841 + 0.0000i

推荐答案

在MATLAB中,SOLS'执行复杂的共轭转置操作,即元素{i,j}变为元素{j,i}并转换其值作为a + 1i*b --> a -1i*b.要保留复杂值的相位,请使用SOLS.',如下所示:

In MATLAB, SOLS' performs the complex conjugate transpose operation, that is element {i,j} becomes element {j,i} and its value is transformed as a + 1i*b --> a -1i*b. To retain the phase of your complex values use SOLS.' as follows:

A = E*[SOLS.' ; ones(1,10 ) ];

此外,这是您要执行循环的方式(当然可以转换为适当的C):

In addition this is how you want to perform the loop (translating of course to proper C):

for i=1:size(E,1)
  for j=1:size(SOLS,1)
        A1(i,j)=0;
        for k = 1:size(SOLS,2)
            A1(i,j)= A1(i,j) + E(i,k)*SOLS(j,k);
        end
        A1(i,j)= A1(i,j) + E(i,k+1);
   end
end

然后

A1 - A

ans =

   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0

这篇关于在Matlab中乘以复杂矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆