function r=iqi(f,x1,x2,x3,varargin) %IQI Root finding, inverse quadratic interpolation method. % X=IQI(F,X1,X2,X3) attempts to find the solution of F(X)=0 given initial % guesses X1, X2 and X3 using the inverse quadratic interpolation method. % F is a function handle. % % X=IQI(F,X1,X2,X3,P1,P2,...) passes the parameters P1,P2,... to F. % % See also NEWTON, BISECTION, SECANT. % Francisco J. Beron-Vera % $Revision: 1.1 $ $Date: 2006/09/19 13:28:03 $ N=25; x=zeros(1,N); x(1:3)=[x1 x2 x3]; n=0; while abs(x(n+3)-x(n+2))>eps*abs(x(n+3)) n=n+1; if n>N warning('Tolerance not satisfied.') break end a=f(x(n),varargin{:})/f(x(n+1),varargin{:}); b=f(x(n+2),varargin{:})/f(x(n+1),varargin{:}); c=f(x(n+2),varargin{:})/f(x(n),varargin{:}); x(n+3)=... x(n+2)-... (b*(b-a)*(x(n+2)-x(n+1))+(1-b)*c*(x(n+2)-x(n)))/... ((a-1)*(b-1)*(c-1)); end r=x(n+3)