function [p0,k,err,y] = newton(f,df,p0,delta,epsilon,max1) %--------------------------------------------------------------------------- %NEWTON Newton's method is used to locate a root. % Sample calls % [p,k,err,y] = newton('f',df,p0,delta,epsilon,max1) % Inputs % f name of the function % df name of the function's derivative input % p0 starting value % delta convergence tolerance for p0 % epsilon convergence tolerance for y0 % max1 maximum number of iterations % Return % p0 solution: the root % k actual number of iterations % err error estimate in the solution p0 % y solution: the function value %--------------------------------------------------------------------------- for k=1:max1 p1 = p0 - feval(f,p0)/feval(df,p0); err = abs(p1-p0); relerr = 2*err/(abs(p1)+delta); p0 = p1 y = feval(f,p0) if (err