% example: instability of an algorithm based on a
% recurrent formula for I(k)=int_1^e (ln(x))^k dx:
%  I(k)=e-k*I(k-1)
% forward (unstable) and backward (stable) approaches
I(1)=1; J(50)=0; e=exp(1);
for n=2:50
    I(n)=e-n*I(n-1); % forward calculation
    k=50-n+2; J(k-1)=(e-J(k))/k;  % backward
end
fprintf('  n               I_forward      I_backward, I(50)=0\n')
for n=1:25 % first 25 integrals:
    fprintf('%4i    %19.7f     %16.7f   \n',n,I(n),J(n))
end