function Taylor(x)
% Look at Taylor approximations to exp(x) and exp(-x)
close all
N = 60;

% exp(x)...
s = 1;
term = 1;
relErr = zeros(1,N);
for k = 1:N
term = term*x/k;
s = s + term;
relErr(k) = abs(s - exp(x))/exp(x);
end
semilogy(1:N,relErr)

% exp(-x) ...
hold on
s = 1;
term = 1;
relErr = zeros(1,N);
for k = 1:N
term = -term*x/k;
s = s + term;
relErr(k) = abs(s - exp(-x))/exp(-x);
end
semilogy(1:N,relErr,'r')
plot(1:N,10^(-16)*ones(1,N),'--k')
hold off
ylabel('Relative Error in Partial Sum.','fontsize',14)
xlabel('Order of Partial Sum.','fontsize',14)
title(sprintf('x = %5.2f',x),'fontsize',14)
set(gca,'fontsize',14)
shg