FULL PROGRAM:
clear % clear memory
sv=0; % initialize variable 'A'.
disp('The first 10 terms of the series are:'); %Display in command window *
% * the text in purple.
for i=1:10 %for loop with i=0 to i=9 which are the first 10 terms of series.
sv=1/factorial(i-1); %Eulers Formula calculated for each term 'i'
fprintf('Term %i is: %0.15f\n',i,sv) % display the result of each *
% * value of A seperately
end % close forloop pertaining to displaying values 0-9.
figure; hold on % 'hold on' for the for loop to make sure the plotable *
% *figure is not over written by each iteration.
for j=0:9 % For loop
sv=sv+1/factorial(j);
plot(j,sv,'b--x');
end
title('Graph Showing Eulers Formula and Convergance Line at y=e')
fprintf('The sum of the first 10 terms is:%0.15f \n',sv)
pd=((sv-exp(1))/((exp(1)+sv)/2))*100;
fprintf('The percentage difference between the above and MatLab value for')
fprintf(' e is:%0.15f%%',pd)
plot([0,9],[exp(1),exp(1)],'r-')
legend('blue x markers','y=e', 'location','southeast')
hold off
