% Numerical Analysis(2nd ed) machine assignment 1.2 
% compute the derivatve dy/dx of y = e^x at x = 0
% from difference of quotients d(h) = (e^h - 1)/h 
fprintf('i \t h1 \t\t\t\t h2 \t\t\t\t d1 \t\t\t\t d2 \n')
for i = 5:5:55;
    h1 = 2^(-i);
    h2 = 2.2^(-i);
    d1 = (exp(h1) - 1) / h1;
    d2 = (exp(h2) - 1) / h2;
    x = [i, h1, h2, d1, d2];
    if (i == 5 || i == 45 || i == 50)
        fprintf('%1.0f \t %1.16f \t\t %1.16f \t\t %1.16f \t\t %1.16f \n'...
            ,i, h1, h2, d1,d2)
    else
        fprintf('%1.0f \t %1.16e \t %1.16e \t %1.16e \t %1.16e \n', ...
             i, h1, h2, d1,d2)
    end
end
