function HalleysMethod_log
%Halleys Method; caso particular f(x) = x + ln(x)
 i = 1; p0 = 1; N = 100;     % initial conditions
 error = 0.000000001;        % precision required
 syms 'x'              % Symbolic variables, functions, and expresions in Matlab
 f(x) = x + log(x);    % The function we are root finding.
 dx = diff(f);         %  first and second derivatives of f(x)
 ddx = diff(dx); 
 while i <= N          % Implementation of Halleys Method.
    p = p0 - (f(p0)/dx(p0))*(1 - (f(p0)*ddx(p0)/dx(p0)^2))^(-1);     
    if (abs(p - p0)/abs(p)) < error         %stopping when difference between iterations is below tolerance
       fprintf('Solution is %15.13f; %3.0f iterations.\n', double(p),i)
       return
    end
    i  = i + 1;
    p0 = p;            % update p0
    fprintf('%15.13f; iteration  %3.0f\n', double(p0),i)
 end
 fprintf('Solution did not coverge within %d iterations; required precision of %d \n', N, error) 
end
