
% Example 2.5, page 3.1
% 
% solve exp(x)-2*x-1 = 0
% vs. function iteration method 


% three rearrangements:
% (1) x = (exp(x)-1)/2
% (2) x = exp(x)-x-1
% (3) x = ln(2x+1)

clear, clc
format short g

% starting point: 
p1 = 1.5; p2 = 1.5; p3 = 1.5;

% iterative solutions
x = zeros(8,3);

% iteration
for k = 1:8
    x(k,:) = [p1,p2,p3];
    p1 = (exp(p1)-1)/2;
    p2 = exp(p2)-p2-1;
    p3 = log(2*p3+1);
end

disp('  #Iterations       eq1          eq2          eq3')
disp([[1:8]' x])