function [P,p0,k,err,y] = newton2(f,df,p0,delta,epsilon,max1) %--------------------------------------------------------------------------- %NEWTON 2 Newton's method is used to locate a root. % Sample calls % [P,p,k,err,y] = newton2(@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 % p solution: the root % y solution: the function value % err error estimate in the solution p0 % %If f and df are defined as M-file functions use the @ notation % call [p0,err,k,y]=newton2(@f,@df,p0,delta,epsilon,max1). %If f and df are defined as anonymous functions use the % call [p0,err,k,y]=newton2(f,df,p0,delta,epsilon,max1). %--------------------------------------------------------------------------- P = [p0]; for k=1:max1 p1 = p0 - feval(f,p0)/feval(df,p0); err = abs(p1-p0); P = [P p1]; relerr = 2*err/(abs(p1)+delta); p0 = p1 y = feval(f,p0) if (err