atan2

Four-quadrant inverse tangent

Syntax

Description

example

P = atan2(Y,X) returns the Four-Quadrant Inverse Tangent (tan-1) of Y and X, which must be real. The atan2 function acts on Y and X element-wise to return P, which is the same size as Y and X.

Examples

expand all

Find Four-Quadrant Inverse Tangent of a Point

Find the four-quadrant inverse tangent of the point y = 4, x = -3.

atan2(4,-3)
ans =
    2.2143

Convert Complex Number to Polar Coordinates

Convert 4 + 3i into polar coordinates.

z = 4 + 3i;
r = abs(z)
theta = atan2(imag(z),real(z))
r =
     5
theta =
    0.6435

The radius r and the angle theta are the polar coordinate representation of 4 + 3i.

Alternatively, use angle to calculate theta.

theta = angle(z)
theta =
    0.6435

Convert r and theta back into the original complex number.

z = r*exp(i*theta)
z =
   4.0000 + 3.0000i

Plot Four-Quadrant Inverse Tangent

Plot atan2(Y,X) for -4<Y<4 and -4<X<4.

Define the interval to plot over.

[X,Y] = meshgrid(-4:0.1:4,-4:0.1:4);

Find atan2(Y,X) over the interval.

P = atan2(Y,X);

Use surf to generate a surface plot of the function. Note that plot plots the discontinuity that exists at Y=0 for all X<0.

surf(X,Y,P);
view(45,45);

Input Arguments

expand all

Y — Real valued inputnumber | vector | matrix | multidimensional array

Real valued input, specified as a number, vector, matrix, or multidimensional array.

Data Types: single | double

X — Real valued inputnumber | vector | matrix | multidimensional array

Real valued input, specified as a number, vector, matrix, or multidimensional array.

Data Types: single | double

More About

expand all

Four-Quadrant Inverse Tangent

The four-quadrant tangent inverse, atan2(Y,X), returns values in the closed interval [-pi,pi] based on the values of Y and X as shown in the graphic.

In contrast, atan(Y,X) returns results which are limited to the interval (-pi/2,pi/2), which is the right side of this diagram.

See Also

| | | |

Was this topic helpful?