Main Content

atan2

Symbolic four-quadrant inverse tangent

Description

P = atan2(Y,X) computes the four-quadrant inverse tangent (arctangent) of Y and X.

Symbolic arguments X and Y are assumed to be real, and atan2(Y,X) returns values in the interval [-pi,pi].

example

Examples

collapse all

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

P = [atan2(1,1), atan2(pi,4), atan2(Inf,Inf)]
P = 1×3

    0.7854    0.6658    0.7854

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

P = [atan2(sym(1),1), atan2(sym(pi),sym(4)), atan2(Inf,sym(Inf))]
P = 

(π4atan(π4)π4)

Compute the limits of this symbolic expression.

syms x
P_minusinf = limit(atan2(x^2/(1 + x),x),x,-Inf)
P_minusinf = 

-3π4

P_plusinf = limit(atan2(x^2/(1 + x),x),x,Inf)
P_plusinf = 

π4

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]);
P = atan2(Y,X)
P = 

(π3π6π4π2)

Input Arguments

collapse all

y-coordinates, specified as a symbolic number, variable, expression, or function, or as a vector, matrix, or array of symbolic numbers, variables, expressions, or functions. All numerical elements of Y must be real.

Inputs Y and X must either be the same size or have sizes that are compatible (for example, Y is an M-by-N matrix and X is a scalar or 1-by-N row vector). For more information, see Compatible Array Sizes for Basic Operations.

x-coordinates, specified as a symbolic number, variable, expression, or function, or as a vector, matrix, or array of symbolic numbers, variables, expressions, or functions. All numerical elements of X must be real.

Inputs Y and X must either be the same size or have sizes that are compatible (for example, Y is an M-by-N matrix and X is a scalar or 1-by-N row vector). For more information, see Compatible Array Sizes for Basic Operations.

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(Y,X) belong to the closed interval [-pi,pi]. Meanwhile, results returned by atan(Y/X) 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.

  • 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).

Version History

Introduced in R2013a

See Also

| | | |