function x_star = newton( func_name, deriv_name, x_guess )
%
%   Find a solution to the equation f(x) = 0 for the function
%   named func_name using Newton's method.  The derivative f'(x)
%   is provided by the function deriv_name and the initial guess
%   is x_guess.

x_star = x_guess;   % first approximation to answer

for i = 1:20        % repeat procedure no more than 20 times

   f = feval( func_name, x_star );        %  f(x)
   fp = feval( deriv_name, x_star );      %  f'(x)
   delta_x = -f/fp;                       %  the change: -f(x)/f'(x)
   x_star = x_star + delta_x;             %  find new approximation

   if abs( delta_x ) < 0.5e-5*abs( x_star )     % have converged ...
     return                                     % ... exit early
   end

end
