Sign of imaginary value changes after converting to array

When I calculate these complex numbers, they have positive imaginary components. However, in the complex array z, all of the nonzero imaginary components become negative.
I can't find this behavior in the documentation so I do not understand what is going on.
a = 2 + 1j;
b = 1 + 3j;
% a)
z1 = a*b;
% b)
z2 = b*conj(b);
% c)
z3 = a^3;
% d)
z4 = b/a;
z = [z1; z2; z3; z4];

 採用された回答

Steven Lord
Steven Lord 2021 年 2 月 11 日

2 投票

My guess is that you accidentally used the conjugate transpose operator (') instead of the non-conjugate transpose operator (.') somewhere in your code.
v = (1+1i)*(1:5);
imag(v)
ans = 1×5
1 2 3 4 5
x = v.';
imag(x) % non-conjugate
ans = 5×1
1 2 3 4 5
y = v'; % conjugate
imag(y)
ans = 5×1
-1 -2 -3 -4 -5

1 件のコメント

Nicholas Acuna
Nicholas Acuna 2021 年 2 月 11 日
That did it thanks! Didn't know about that operator
I originally had z = [z1 z2 z3 z4]'; and when I switched to [z1; z2;...]; I tried clearing and rerunning the script but I was in debug mode so it didn't actually do anything.

サインインしてコメントする。

その他の回答 (1 件)

James Tursa
James Tursa 2021 年 2 月 11 日

1 投票

Here is what I get:
>> a = 2 + 1j;
>> b = 1 + 3j;
>> z1 = a*b
z1 =
-1.0000 + 7.0000i
>> z2 = b*conj(b)
z2 =
10
>> z3 = a^3
z3 =
2.0000 +11.0000i
>> z4 = b/a
z4 =
1.0000 + 1.0000i
>> z = [z1; z2; z3; z4]
z =
-1.0000 + 7.0000i
10.0000 + 0.0000i
2.0000 +11.0000i
1.0000 + 1.0000i
Try clearing your workspace and starting from scratch. Maybe you inadvertently used different variables?

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by