% solution to Problem 3, Homework set #1
% this script iteratively solves the integral
% of x^n * exp(x-1) over [0,1] by the algorithm
% E_n = 1-n*E_(n-1), where E_0 = 1 - 1/e

  %allocate space for values of E_n up to E_50.
  E = zeros(1,50)

    %set E_1 = 1- 1/exp(1);
    E(1) = 1- 1/exp(1);

    %compute remaining  values E_i iteratively, 
    %depending on previous value found
    for i=2:50
      E(i) = 1-(i-1)*E(i-1);
    end

    %display final answers, in scientic notation with 16 digits
    format long e
    E
