% Unlimited growth of a single roundoff error % % calculate I(n)=e\int_{0}^{1} t^n e^{-t}dt % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % USE I(n)=nI(n-1)-1: format long I=exp(1)-1; fprintf(1,'Iteration #0: I(0)= %13.10f \n', I); for i=1:20 I=i*I-1; fprintf(1,'Iteration: #%3i: I(%3i)= %13.10f \n', i,i,I); end fprintf(1,'\n \n'); % Now let us try compute things backwards % % USE I(n-1)=(I(n)+1)/n I=0.123456789; fprintf(1,'Iteration #20: I(20)= %13.10f \n', I); for i=20:-1:1 I=(I+1)/i; fprintf(1,'Iteration: #%3i: I(%3i)= %13.10f \n', i,i,I); end