%exponential function Taylor Poly approximation demo
%Fred Park Whittier College 2016
%Math 141A

x = [-5:0.01:5];
figure(2) 
n = 15; %order of polynimial

Pn=1; %initialization, zero ordder poly

for i=1:n
    Pn = (x.^i)/factorial(i) + Pn;
    plot(x,exp(x),'b-',x,Pn,'r-') %plot in iteration
    title(['Taylor Poly approx of order = ' num2str(i)])
    axis([-5 5 -20 160]) %x and y range of values
    pause
end