%This is a for class example of Taylor series approximation dx=1./100; x=[-2:dx:2]; %create a vector of ones the same size of x s1=ones(size(x)); s2=s1-x; %the dot in "x.^2" is to square each element of x separately s3=s2+x.^2/2; s4=s3-x.^3/6; plot(x,s1,'--') %the hold on means the next plot is overlaid on the old plot--type hold off to unset this hold on plot(x,s2,'-.') plot(x,s3,':') plot(x,s4) plot(x,exp(-x),'.'); xlabel('x') ylabel('y') title('Taylor Series Approximation of exp(-x)') text(1,7,'s1 --') text(1,6.5,'s2 -.') text(1,6.0,'s3 :') text(1,5.5,'s4 -') text(1,5.0,'exp(-x) fat line') hold off;