function r=bisection(f,a,b,varargin) %BISECTION Root finding, bisection method. % X=BISECTION(F,A,B) attempts to find the solution of F(X)=0 in the % interval [A,B] such that F(A)*F(B) < 0. % % X=BISECTION(F,A,B,P1,P2,...) passes the parameters P1,P2,... to F. % % See also NEWTON, SECANT, IQI. % Francisco J. Beron-Vera % $Revision: 1.1 $ $Date: 2006/09/19 13:28:03 $ if f(a,varargin{:})*f(b,varargin{:})>=0 error('F(A)*F(B) must be negative.') end for k=1:54 r=(a+b)/2; if f(a,varargin{:})*f(r,varargin{:})<0 b=r; else a=r; end %disp(sprintf('%2i %bx',[k r])) disp([sprintf('%2i',k) ' ' num2bin(r)]) en