cos

Cosine of an angle given in radians.

Category: Mathematics > Elementary Math

Syntax

Y = cos(X)

Returns the cosine of each element of X, in radians.

Description

cos works element by element. The result lies in [-1, 1] for real input and is periodic with period 2*pi. Because pi is not represented exactly, cos(pi/2) is about 6.1e-17 rather than 0; use cosd or cospi for exact results at such angles.

Input arguments

X
Numeric array of any size. Complex values are allowed.

Output arguments

Y
Array of the same size as X.

Example

Cosine of common angles

cos([0 pi/3 pi])
cos(pi/2)
Output
ans = 1×3

    1.0000    0.5000   -1.0000
ans = 6.1232e-17

See also

sin cosd cospi acos