Matlab function for calculating phase of complex number

8 visualizzazioni (ultimi 30 giorni)
Hello and good day to all,
Matlab has a built in function to calculate amplitude and phase of a complex number using abs(number) and angle(number) funstions. I have a question regarding phase part. Lets suppose we have a complex number in the form z=x+jy (x being your real and y your imaginary part). When you want to calculate the phase of this number the formula is phase=arctan(y/x). In addition to this formula we have to take care of sign's of real and imaginary part (especially real part)and correspondingly we add (+/-) pi to the calculated value. Does matlab "angle function" consider this thing because all examples I saw have only positive real parts. Thank you

Risposte (1)

John D'Errico
John D'Errico il 9 Ago 2016
Modificato: John D'Errico il 9 Ago 2016
Actually, the formula is
atan2(y,x)
atan2 handles the problem properly, working in all 4 quadrants. If you don't believe me, just look in the angle function itself. There you will find only one line of code:
p = atan2(imag(h), real(h));
Yep.
angle(-1-0.5i)
ans =
-2.67794504458899
  4 Commenti
Walter Roberson
Walter Roberson il 10 Ago 2016
That would not work correctly for (0,0) because the 0/0 would give rise to NaN and atan(NaN) is NaN which would pollute the rest of the calculation.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by