%computes error in approximation of f(x) = e^x by 
%nth degree Taylor polynomial centered at 0

f = @(x) exp(x);
n = 3;      %degree of Taylor polynomial approximation
x = 1;
Pn = 0;     %value of nth degree Taylor polynomial at x

for k=0:n
    Pn = Pn + x^k/factorial(k);
end

disp('value of Taylor polynomial at x')
Pn

disp('value of f at x')
f(x)

disp('Taylor's theorem upper bound for error')
f(x)*x^(n+1)/factorial(n+1)

disp('actual error in Taylor polynomial approximation')
f(x) - Pn



    