Complex-step-compatible atan2()

atan2() or arctan2() function that is compatible with complex-step derivative operations.
14 Downloads
Updated 27 Oct 2021

View License

The function atan2(Y,X) [or arctan2(Y,X)] is the four quadrant arctangent of the elements of X and Y such that -pi <= atan2(Y,X) <= pi.
MATLAB atan2() reports an error when inputs are complex. This function reproduces MATLAB atan2() results for real inputs, but can be used with complex inputs to enable complex-step derivative operations.
There is an output discontinuity at T = pi and -pi. However, the output derivative is continuous, so, at T = pi and -pi, this function calculates the derivative analytically and adds complex-step-equivalent perturbations to the output.
Because the function remains discontinuous, the user should carefully consider before using atan2() output for gradient-based optimization.
Complex step is a numerical differentiation technique. See description:

Cite As

Anthony Ricciardi (2024). Complex-step-compatible atan2() (https://www.mathworks.com/matlabcentral/fileexchange/101193-complex-step-compatible-atan2), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2016b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0