Why does complex number sign change?

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

 采纳的回答

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.
Thanks for the additional example, @Stephen23. In the context, that now makes sense. Much appreciated.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by