Entering 'a=2-1/2i' returns 'a = 2 + 0.5i'. Entering 'b=2-0.5i' returns 'b = 2 - 0.5i'.
Why does the first example seem to change the sign of the imaginary part?
MATLAB sign change

 採用された回答

Matt J
Matt J 2022 年 7 月 28 日
編集済み: Matt J 2022 年 7 月 28 日

0 投票

Because it is equivalent to 2-1/(2i). In all likelihood, you intended to do this:
a=2-(1/2)*i
a = 2.0000 - 0.5000i

3 件のコメント

J B
J B 2022 年 7 月 28 日
編集済み: J B 2022 年 7 月 28 日
Hi @Matt J, great, thank you for the explanation and correction suggestion. Much appreciated. Thus this seems to be an order-of-operations condition: '2i' is not # times # but rather # times variable, which makes it a variable multiple, which has higher precedence than the '1/2' division. Since 'i' is always and only the square root of -1, a number, I expected the order of operations to be '1/2', then that result times root -1 (i.e., left-to-right evaluation). Thanks for clearing up how MATLAB interprets this.
Stephen23
Stephen23 2022 年 7 月 28 日
Also:
a = 2-i/2
a = 2.0000 - 0.5000i
J B
J B 2022 年 7 月 28 日
Thanks for the additional example, @Stephen23. In the context, that now makes sense. Much appreciated.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

J B
2022 年 7 月 28 日

コメント済み:

J B
2022 年 7 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by