function r = inverseInterpolationF(fcn,a,b,c,tol,maxIt)
% Root finding using inverse interpolation
% a, b, & c are 3 initial guesses to the root.
% See p.234 of Heath, example 5.13
% K. Ming leung, 02/08/03

%clear all;
%fcn='x2m4sinx'; format long;
fa=feval(fcn,a);
fb=feval(fcn,b);
fc=feval(fcn,c);
it=1; h=10; % needed - MATLAB has no do-while loop
r=[];       % for storing intermediate results
while it <= maxIt & abs(h) > tol;
    u=fb/fc; v=fb/fa; w=fa/fc;
    p=v*(w*(u-w)*(c-b)-(1-u)*(b-a));
    q=(w-1)*(u-1)*(v-1);
    h = p/q;
    c=a; fc=fa; % c replaced by the old a
    a=b; fa=fb; % a replaced by the old b
    b=b+h; fb=feval(fcn,b); % new b
    r=[r; [it b fb]]; it=it+1;
end;


