Working with complex numbers in the Symbolic Math Toolbox. Why does angle(A) returns atan2(sin(​alpha),cos​(alpha)) instead of just alpha?

25 ビュー (過去 30 日間)
%% Complex number using TRIGONOMETRIC form
% Let's define A as a complex number in polar form, with magnitude M and angle alpha
M = sym('M',{'real','positive'}); % magnitude
alpha = sym('alpha','real'); % angle
assume(alpha>-pi & alpha<pi)
A = M*(cos(alpha) + i*sin(alpha)); % complex number in polar form
% Now, I would expect abs(A) to return M. It does not.
% But, using rewrite and combine, I can get the it to return M
combine(rewrite(abs(A), 'sqrt'), 'sincos')
% Similarly, I would expect the angle(A) to return alpha, but instead we get atan2(sin(alpha), cos(alpha)).
% I tried the simplify and rewrite function, but I could not get the angle(A) to return alpha. Is there a way around this?


Dana 2020 年 9 月 17 日
This seems to be the result of a gap in MATLAB's symbolic logic. Your assumption
assume(alpha>-pi & alpha<pi)
should be enough to conclude that atan2(sin(alpha),cos(alpha))=alpha. However, for some reason MATLAB seems to be applying the one-argument atan rules (rather than the 2-argument atan2 ones) to this problem, wherein atan(sin(alpha)/cos(alpha))=alpha only if -pi/2<alpha<pi/2. You can check this by replacing the above assumption with
assume(alpha>-pi/2 & alpha<pi/2)
and then
>> simplify(angle(A))
ans =
as desired.
I'm not sure if this is a bug, or if there's some good reason for it.
  2 件のコメント
Dana 2020 年 9 月 18 日
編集済み: Dana 2020 年 9 月 18 日
To be clear, depending on your application, you don't necessarily want to restrict the angle to be between -pi/2 and pi/2. There are perfectly good reasons why you might be interested in allowing for any angle between -pi and pi. It's just that, if you don't make the -pi/2,pi/2 restriction then MATLAB won't recognize that atan2(sin(alpha),cos(alpha))=alpha. Under your assumption that alpha is between -pi and pi, it should recognize that, but for some reason it doesn't.
To understand this, for the case of the one-argument atan function it's pretty straightforward. The tan function is not actually invertible: for any angle θ and any integer k, . Thus, for any number a, there are an infinite number of angles ω such that , and this means that tan isn't invertible.
In practice, though, we can pick some b and then define the "inverse" to be the unique angle such that . Ultimately the choice of b is arbitrary, and you can see different choices in different contexts. For the case of the atan function in MATLAB, , so that the relevant range is . This is where that restriction above is coming from.
However, for the atan2 function, we have more information, which expands the range of unique angles from to . MATLAB uses in this case, so we should be able to recover any , but as I say, for some reason MATLAB's symbolic logic isn't recognizing that.


その他の回答 (1 件)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020 年 9 月 17 日
if you want to find the numerical value of alpha, one solution is to use double function:


Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by