function [xout,fout,n] = newton3_tdelillo(f,fprime,x0,tol)
% Newton iteration for solving f(x) = 0
% intial guess x0, tolerance tol
% take n Newton steps for now
x = x0;
errx=2;
n=0;
while (errx > tol) && (abs(f(x)) > tol)
  n = n+1;  
  xlast = x;  
  x = x - f(x)/fprime(x);
  errx = abs(x - xlast)
  if n > 50, break, end
end 
  xout = x;
  fout = f(x);