function xNew = IterationE(f, x0, tol, exact)
% IterationE(f, x0, tol, exact) calculates the root of equation f(x)=0 
% using the method of iterations, and finds the order of convergence
% given exact root "exact"

fprintf('\n Iteration method solver \n\n');
horzLine = '______________________________________________________';
fprintf(' n |        x(n)        |   error   | log(error)|  f(x(n)) \n%s\n', horzLine);
xOld = x0;

for n = 1:100
    xNew = f(xOld);

    error(n) = abs(xNew-exact);
     
    fprintf('%2d | %18.12g | %9.2e | %9.2e | %9.2e \n', n, xNew, error(n), log(error(n)), f(xNew)-xNew);  
    if  abs(xNew - xOld) < tol
        ConvOrder(error);
        return
    end

    xOld = xNew;
end
fprintf('*** Iteration method failed to converge after 100 iterations');