%COSINE EXAMPLE clear format compact x=-1:.001:4; tic p81=1-x.^2/2+x.^4/24-x.^6/(24*30)+x.^8/(24*30*56); toc, tic p81=1-x.*x/2+x.*x.*x.*x/24- x.*x.*x.*x.*x.*x/(24*30)+x.*x.*x.*x.*x.*x.*x.*x/(24*30*56); toc, tic p82=1-x.*x/2.*(1-x.*x/12.*(1-x.*x/30.*(1-x.*x/56))); toc, tic xs=x.*x; p83=1-xs/2.*(1-xs/12.*(1-xs/30.*(1-xs/56))); toc p2=1-xs/2; p4=1-xs/2.*(1-xs/12); p6=1-xs/2.*(1-xs/12.*(1-xs/30)); p8=1-xs/2.*(1-xs/12.*(1-xs/30.*(1-xs/56))); plot(x,p2,x,p4,x,p6,x,p8) grid on xlabel('x-axis'), ylabel('y-axis') title('Taylor Series Approx to Cosine')