sinpi - Compute sin(X*pi) accurately - MATLAB (original) (raw)
Main Content
Compute sin(X*pi) accurately
Syntax
Description
Y = sinpi([X](#mw%5Faaf95f81-d1af-457b-8e56-51714dc8cc99))
computessin(X*pi)
without explicitly computing X*pi
. This calculation is more accurate than sin(X*pi)
because the floating-point value of pi
is an approximation of π. In particular:
- For integers,
sinpi(n)
is exactly zero. - For odd integers,
sinpi(n/2)
is +1 or -1.
Examples
Compare the accuracy of sinpi(X)
vs. sin(X*pi)
.
Create a vector of values.
Calculate the sine of X*pi
using the normal sin
function.
Y = 1×5
0 1.0000 0.0000 -1.0000 -0.0000
The results contain small numerical errors due to the fact that pi
is a floating-point approximation of the true value of π. For instance, Y(3)
is not exactly zero even though sin(π)=0.
Use sinpi
to calculate the same values. In this case, the results are exact.
Input Arguments
Input array, specified as a scalar, vector, matrix, multidimensional array, table, or timetable.
Data Types: single
| double
| table
| timetable
Complex Number Support: Yes
Extended Capabilities
Thesinpi
function fully supports tall arrays. For more information, see Tall Arrays.
The sinpi
function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2018b
The sinpi
function can calculate on all variables within a table or timetable without indexing to access those variables. All variables must have data types that support the calculation. For more information, see Direct Calculations on Tables and Timetables.