function result = NewtonF2(x,fcn,Dfcn,tol)
% Function for Newton iteration in 1D
% x     is the initial guess for a root
% fcn  = string for the name of the function
% Dfcn = string name of file that computes the derivative function
% tol   is the absolute tolerance
% Usage: r=NewtonF2(1,'problem5p3F1','problem5p3FD1',eps)
% OUTPUT: result for
% ('    loop       x        f(x)     derivative    dx');
% K. Ming Leung, 03/18/03

dx = 1; 
result = [];    % to store intermediate results 
loop = 0;
%disp('    loop       x        f(x)     derivative    dx');
while abs(dx) > tol;
    fx = feval(fcn,x);  % evaluate function at x
    fp = feval(Dfcn,x); % evaluate derivative of function at x
    dx = -fx/fp;
    result = [result; [loop x fx fp dx]];
    x = x+dx;           % Book does it this way
    loop = loop+1;
end;

