atan2(0,0) is not undefined (NaN)

15 ビュー (過去 30 日間)
Daven Gooden
Daven Gooden 2020 年 8 月 11 日
コメント済み: hosein Javan 2020 年 8 月 11 日
I'm using MATLAB R2020a Home Edition on a Windows® machine. I have a need to calculate atan2(0,0) which, if I am correct should result in NaN (undefined). The answer I get is zero. Is this not bug in the underline algorithm for computation of atan2()?
Thank you in advance.

採用された回答

Star Strider
Star Strider 2020 年 8 月 11 日
That is defined in the IEEE Compliance section of the atan2 documentation.
The result also isd not completely standardised. See the section in the Wikipedia article on Atan2 on Realizations of the function in common computer languages.
  2 件のコメント
Daven Gooden
Daven Gooden 2020 年 8 月 11 日
編集済み: Daven Gooden 2020 年 8 月 11 日
Star Strider thank you for replying! I did not realize the C language implementation of atan2(0,0) == 0 is what MATLAB is using. This is not what I want, but is good to know. I can compensate for that.
Star Strider
Star Strider 2020 年 8 月 11 日
As always, my pleasure!
MATLAB began as a FORTRAN implementation, later switching to C.

サインインしてコメントする。

その他の回答 (2 件)

James Tursa
James Tursa 2020 年 8 月 11 日
  1 件のコメント
Daven Gooden
Daven Gooden 2020 年 8 月 11 日
James thanks for your reply. I now see the "IEEE Compliance" section within the help documentation. That is good information to keep in mind!

サインインしてコメントする。


hosein Javan
hosein Javan 2020 年 8 月 11 日
it is not a bug. although in analytic math it is undefined, the trigonometric functions are usually calculated by their taylor series expansion on numerical softwares. no doubt it results zero. however when you try very small values, it is still correct:
atan2(1e-301,1e-301)*180/pi
ans =
45
  2 件のコメント
Daven Gooden
Daven Gooden 2020 年 8 月 11 日
Thanks Hosein! I appreciate your willingness to help. Your input is very helpful.
hosein Javan
hosein Javan 2020 年 8 月 11 日
don't mention it.

サインインしてコメントする。

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by