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.
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 Exchange에서 Loops 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