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

 Respuesta aceptada

Matt J
Matt J el 28 de Jul. de 2022
Editada: Matt J el 28 de Jul. de 2022
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 comentarios

J B
J B el 28 de Jul. de 2022
Editada: J B el 28 de Jul. de 2022
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 el 28 de Jul. de 2022
Thanks for the additional example, @Stephen23. In the context, that now makes sense. Much appreciated.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

J B
el 28 de Jul. de 2022

Comentada:

J B
el 28 de Jul. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by