function [p1, err, i, y] = secant(f,p0,p1,tol1,tol2,max)
for i=1:max
   p2=p1-feval(f,p1)*(p1-p0)/(feval(f,p1)-feval(f,p0));
   err=abs(p2-p1);
   relerr=2*err/(abs(p2)+eps);
   p0=p1;
   p1=p2;
   y=feval(f,p1);
   if (err<tol2) | (relerr<tol2) | abs(y)<tol1, break, end
end
