function result = bisectionF(fcn, a, b, tol)
% Root finding using bisection method
% function:             fcn (string)
% INPUT:
% starting interval:    given by a and b
% tolerance:            tol
% bisectionF.m
% OUTPUT:
% result = [loop a fa fm]
% K. Ming Leung, 02/01/03

fa = feval(fcn,a);
result = []; loop = 0;
while abs(b-a) > tol
    m = (b+a)/2;
    fm = feval(fcn,m);
    if sign(fa) == sign(fm)
        a = m; fa = fm;
    else 
        b = m;
    end;
    loop = loop+1;
    result = [result ;[loop a fa fm]];
end
