%
% File name: taylor.m
% Author: Suh-Yuh Yang at NCU 
% Date: September 21, 2018  
%

x= -3:0.01:3;
y=sin(x);
p1=x;
p3=x-(x.^3)/6.0;
p5=x-(x.^3)/6.0+(x.^5/120);
plot(x, y, 'r', x, p1,'b', x, p3, 'm', x, p5, 'k');
grid on;
xlabel('x-axis');
ylabel('y-axis');
title('Partial sums of the Taylor series for sin(x) at c=0');
legend('f(x)=sin(x)', 'p_1(x)=x', 'p_3(x)=x-x^3/6', 'p_5(x)=x-x^3/6+x^5/120',2);