function table2_6

%  Solve  f(x) = 0  using Newton

%  Input:
%	x = starting point
%	tol = tolerance for stopping
%	f(x) and df(x) are at end of file

% Solution of  exp(-x)-(2+x) = 0  to 20 digits
%xe=-0.4428544010023885831;

x=0;
tol=10^(-10);

k=0;
err=10*tol;
fprintf('\n RIE = relative iterative error \n\n')
fprintf(' k  \t   x_k \t\t\t  RIE  \n')
while err>tol
    k=k+1;
    z=f(x)/df(x);
    x=x-f(x)/df(x);
    err=abs(z/x);
    fprintf(' %i \t  %19.15f \t  %5.1e  \n',k,x,err)
    %fprintf('\\, %i \\, & \\,\\, %19.15f \\,\\, & \\,\\, %5.1e  \\\\\\hline \n',k,x,err)
end
fprintf('\n\n')


function g=f(x)
%g=x^3+2*x+2;
g=exp(-x)-(2+x);

function g=df(x)
%g=3*x^2+2;
g=-exp(-x)-1;



