atan2

Symbolic four-quadrant inverse tangent

Description

example

atan2(Y,X) computes the four-quadrant inverse tangent (arctangent) of Y and X. If Y and X are vectors or matrices, atan2 computes arctangents element by element.

Examples

Four-Quadrant Inverse Tangent for Numeric and Symbolic Arguments

Compute the arctangents of these parameters. Because these numbers are not symbolic objects, you get floating-point results.

[atan2(1, 1), atan2(pi, 4), atan2(Inf, Inf)]
ans =
    0.7854    0.6658    0.7854

Compute the arctangents of these parameters which are converted to symbolic objects:

[atan2(sym(1), 1), atan2(sym(pi), sym(4)), atan2(Inf, sym(Inf))]
ans =
[ pi/4, atan(pi/4), pi/4]

Limit of Four-Quadrant Inverse Tangent

Compute the limits of this symbolic expression:

syms x
limit(atan2(x^2/(1 + x), x), x, -Inf)
limit(atan2(x^2/(1 + x), x), x, Inf)
ans =
-(3*pi)/4
 
ans =
pi/4

Four-Quadrant Inverse Tangent of Array Input

Compute the arctangents of the elements of matrices Y and X:

Y = sym([3 sqrt(3); 1 1]);
X = sym([sqrt(3) 3; 1 0]);
atan2(Y, X)
ans =
[ pi/3, pi/6]
[ pi/4, pi/2]

Input Arguments

collapse all

Input, specified as a number, vector, matrix, array, or a symbolic number, array, function, or expression. If Y is a number, it must be real. If Y is a vector or matrix, it must either be a scalar or have the same dimensions as X. All numerical elements of Y must be real.

Input, specified as a number, vector, matrix, array, or a symbolic number, array, function, or expression. The function also accepts a vector or matrix of symbolic numbers, variables, expressions, functions. If X is a number, it must be real. If X is a vector or matrix, it must either be a scalar or have the same dimensions as Y. All numerical elements of X must be real.

More About

collapse all

Four-Quadrant Inverse Tangent

If X ≠ 0 and Y ≠ 0, then

atan2(Y,X)=atan(YX)+π2sign(Y)(1sign(X))

Results returned by atan2 belong to the closed interval [-pi,pi]. Results returned by atan belong to the closed interval [-pi/2,pi/2].

Tips

  • Calling atan2 for numbers (or vectors or matrices of numbers) that are not symbolic objects invokes the MATLAB® atan2 function.

  • If one of the arguments X and Y is a vector or a matrix, and another one is a scalar, then atan2 expands the scalar into a vector or a matrix of the same length with all elements equal to that scalar.

  • Symbolic arguments X and Y are assumed to be real.

  • If X = 0 and Y > 0, then atan2(Y,X) returns pi/2.

    If X = 0 and Y < 0, then atan2(Y,X) returns -pi/2.

    If X = Y = 0, then atan2(Y,X) returns 0.

Alternatives

For complex Z = X + Y*i, the call atan2(Y,X) is equivalent to angle(Z).

See Also

| | | |

Introduced in R2013a