function x = secantfast(f,x0,x1)
% SECANTFAST  More efficient secant method.  Solves f(x) = 0.
%   Requires two initial guesses x0 ~= x1.  Seeks only 8 digit accuracy.
%   Only one function evaluation per step.  Reports intermediate estimates for x.
% Example:
% >> format long
% >> secantfast(@(x) x-cos(x), 0.7, 0.8)
% x =  0.738565440250903
% x =  0.739078362144669
% x =  0.739085133992362
% x =  0.739085133215159
% ans =  0.739085133215159
% >> fsolve(@(x) x-cos(x), 0.7)   % compare to built-in
% ans =  0.739085133215161
 
f0 = feval(f,x0);
while abs(x0-x1)/abs(x1) > 1e-8
  f1 = feval(f,x1);
  x = x1 - f1 * (x1 - x0) / (f1 - f0)
  x0 = x1;
  f0 = f1;
  x1 = x;
end
