function [i,pf,err,p] = fixedpt(g,p0,tol,max)
p(1)=p0;
for i=2:max
   p(i)=feval(g,p(i-1));
   err=abs(p(i)-p(i-1));
   relerr=err/abs(p(i)+eps);
   pf=p(i);
   if (err<tol) | (relerr<tol), break; end
end
if i==max
   disp('maximum number of iterations exceeded')
end
p=p';