cospi

Accurate cosine of X times pi.

Category: Mathematics > Elementary Math

Syntax

Y = cospi(X)

Returns cos(pi*X) computed accurately.

Description

cospi(X) computes cos(pi*X) without first forming the rounded product pi*X. This makes the result exact at integers and half integers: cospi(0.5) is exactly 0, whereas cos(pi/2) is about 6.1e-17. It is the natural choice when the angle is naturally a multiple of pi.

Input arguments

X
Numeric array of any size.

Output arguments

Y
Array of the same size as X.

Example

Exact values at half integers

cospi([0 0.5 1 1.5])
cospi(1/3)
Output
ans = 1×4

     1     0    -1     0
ans = 0.5000

See also

cos sinpi cosd