function result=NewtonF1(x,fcn,tol)
% Function for Newton iteration in 1D
% x     is the initial guess for a root
% fcn   is a string containing the name of the function
% Usage: r=NewtonF1(3,'problem5p8c',eps)
% tol   is the absolute tolerance
% Command line usage:
%           format long; r=NewtonF1(3,'problem5p8c',eps);
% K. Ming Leung, 01/18/03

dx=1; result=[]; loop=0;
disp('    loop       x        f(x)     derivative    dx');
while abs(dx)> tol;
    [fx, fp]=feval(fcn,x);
%    fx=x*x-4*sin(x);fp=2*x-4*cos(x);
    dx=-fx/fp;
    result=[result; [loop x fx fp dx]];
    x=x+dx;    % Book does it this way
    loop=loop+1;
end;
disp(result);
disp('Final root is x=');
disp(x);

