sinpi
Sine of pi times x, exact at integer and half-integer multiples.
Category: Mathematics > Elementary Math
Syntax
Y = sinpi(X)
Returns sin(pi*X) for each element, with the product pi*X never rounded.
Description
sin(pi*x) suffers from the fact that pi*x is only approximately a multiple of pi. sinpi reduces x to a small range before using pi, so the result is exactly 0 for every integer x, and exactly 1 or -1 at odd half-integers: sinpi(1) is 0, whereas sin(pi) is 1.2246e-16.
It is natural in code that uses frequencies in cycles, as in sinpi(2*f*t).
Input arguments
X- Real array, measured in half-turns (multiples of pi).
Output arguments
Y- Array of the same size as
X, with values between -1 and 1.
Example
Exact multiples
sinpi([0 0.5 1 1.5 2])
sin(pi)
Output
ans = 1×5
0 1 0 -1 0
ans = 1.2246e-16