function p2
  tol = 5e-7;
  itcount = 0;
  this = 0;
  last = 0;
  
  while 1
    last2 = last;
    last = this;
    this = f(last);
    itcount = itcount + 1;

    if (itcount == 1)
      x0 = sqrt(1/2);
      k = abs(-2*x0*exp(-x0^2));
      est_itcount = log(tol*(1-k)/abs(this-last))/log(k);
      disp(sprintf('Estimated number of iterations: %g', est_itcount))
    end
    if (itcount >= 2)
      fprime = (this-last)/(last-last2);
      err = abs(fprime/(fprime-1))*abs(this-last);
      disp(sprintf('Iteration:%d value:%g error:%g', itcount, this, err))
    else
      disp(sprintf('Iteration:%d value:%g', itcount, this))
    end
    if (itcount > 2) && (err < tol)
      break
    end
  end
end
function y = f(x)
  y = exp(-x^2);
end
