%% Calculate Sine of Multiples of π
% Compare the accuracy of sinpi(X) vs. sin(X*pi).
%
% Create a vector of values.

X = [0 1/2 1 3/2 2];

%
% Calculate the sine of X*pi using the normal sin function.

Y = sin(X*pi)

%
% The results contain small numerical errors due to the fact that pi is a floating-point approximation of the true value of \pi. For instance, Y(3) is not exactly zero even though \sin \left(\pi \right)=0.

Y(3)

%
% Use sinpi to calculate the same values. In this case, the results are exact.

Z = sinpi(X)

%

Z(3)

%
% Copyright 2018 The MathWorks, Inc.