ATAN2_SAFE

版本 1.0.0.0 (6.8 KB) 作者: Zhigang Xu
To perform the same function as Matlab built-in function atan2 but safely guarded against erroneous
714.0 次下载
更新时间 2008/7/7

查看许可证

This will perform the same function as Matlab built-in function ATAN2 but
safely guarded against erroneous results when the inputs are very small (near to a machine zero).

Due to the round off errors in the numerical calculations, the two
inputs to ATAN2, Y and X, had better be thought as

x=x_exact + (or -) rand*eps;

y=y_exact + (or -) rand*eps;

When the theoretically expected values x_exact and y_exact are
far above the machine accuracy, ATAN2 will give you a good
answer, insensitive to the small unpredictable round off errors.
On the other hand, when one or both of the theoretical values is
zero, ATAN2 becomes very sensitive to the round off errors and
will give an erroneous result. Consider the case where
both x_exact and y_exact are zero, then the call to ATAN2 is
equivalent to the following random experiment

x=(rand-0.5)/0.5*eps;

y=(rand-0.5)/0.5*eps;

theta=atan2(y, x);

Now theta becomes a random number ranging all over between
-pi and pi. (This should apply to ATAN as well).

Since ATAN2(0,0) will give an exact zero, and since the round-off
errors due to the machine accuracy cannot be meaningfully
distinguished from the true zero, we had better clear off (zero out)
the small round off errors before we call ATAN2. To relieve you
from the cleaning burden every time when you need to call ATAN2,
ATAN2_safe automates the cleaning and the calling two steps
for you.

引用格式

Zhigang Xu (2024). ATAN2_SAFE (https://www.mathworks.com/matlabcentral/fileexchange/20134-atan2_safe), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2008a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Analysis of Variance and Covariance 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0

The help message is improved.