Matlab function for calculating phase of complex number

8 次查看(过去 30 天)
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

回答(1 个)

John D'Errico
John D'Errico 2016-8-9
编辑:John D'Errico 2016-8-9
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 个评论
Walter Roberson
Walter Roberson 2016-8-10
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by