Compute sin(X*pi) accurately
Calculate Sine of Multiples of π
Compare the accuracy of
Create a vector of values.
X = [0 1/2 1 3/2 2];
Calculate the sine of
X*pi using the normal
Y = sin(X*pi)
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 .
ans = 1.2246e-16
sinpi to calculate the same values. In this case, the results are exact.
Z = sinpi(X)
Z = 1×5 0 1 0 -1 0
ans = 0
X — Input array
scalar | vector | matrix | multidimensional array | table | timetable
Input array, specified as a scalar, vector, matrix, multidimensional array, table, or timetable.
Complex Number Support: Yes
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version HistoryIntroduced in R2018b
R2023a: Perform calculations directly on tables and timetables
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.