%The following plot the  sin(x) and its Taylor  polynomials. You can modify the number of terms used (n) and the range of approximation a and b  to see how they affect the approximation.  


%set the range of plot: a and b;
a=-5; b=5;
% set the number of terms in Taylor polynomial n
n=3
% set ploterror=1 if you only want to plot the error curve
ploterror=0;

x=(a:0.05:b)';  % set points in x-axis
y=sin(x);
z=0*x;
for i=1:n
  z=z+(-1)^(i+1)*(x.^(2*i-1))/gamma(2*i);
end

if (ploterror ==0)
  plot(x,y,x,z)
endif
if (ploterror==1);
  plot(x,y-z)
endif


