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 ) ];
Where,
>>size(SOLS)
ans =
10 3
and:
>> size(E)
ans =
9 4
SOLS is a complex single matrix and E is a real single matrix and A should be a complex single matrix of size 9x10.
I replaced A = E*[SOLS' ; ones(1,10 ) ];
with
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
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.
What caused this difference? How to convert the matlab command correctly to C?
Here are examples of matrices:
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
and
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…