% iterate0Ln.m
% a straightforward iteration of the sequence
% x(n+1) = 2^(n+1) * ( sqrt(1+x(n)/2^n) - 1 )
% starting with an initial value x(0).
% The sequence is expected to converge to ln(x(0)+1).
% K. Ming Leung, 01/18/2005

clear; format long g;
x0 = 2;
x = x0;
twon = 1; twon1 = 2*twon;
exact = log(x0+1),

for n = 1:55
    x = twon1*(sqrt(1+x/twon)-1);
    fprintf('n = %2d    x(n) = %18.16f    error = %10.2e \n',n,x, x-exact);
    twon = twon1;
    twon1 = 2*twon1;
    % one square root and 5 arithmetic operations per iteration
end

    