function root = newton0(f,df,x,tol,niter)
%
% basic implementation of Newton's method to find a root of f
%
% input:
%   f       string giving function name
%   df      string giving function name for derivative
%   x       initial value for iteration
%   tol     tolerance
%
% We use a simple stopping criteria: the iterates change by at
% most tol, or niter iterations made.

for iter = 1:niter
% evaluate f and f'
  num = feval(f,x);
  den = feval(df,x);
  delx = num/den;
  x = x - delx;
  fprintf('%18.14f\n',x);
  if (abs(delx) <= tol)
    fprintf('tolerance achieved\n');
    root = x;
    return
  end
end
fprintf('maximum number of iterations reached\n');
root = x;
