%
% Bisection Method:
%
%     Compute a root of FUNC(x) on (a,b) with an error no
%     larger than tol. If trace=1 then the output
%
%        a  c  b  FUNC(a)  FUNC(c)  FUNC(b)
%
%     will be printed to the screen at each step (hit
%     return to procede to next iterate).
%
%     Enter FUNC as a string as in Bisect('f',a,b,tol,trace)
%
%
function [output,trace]=BisectF(FUNC,a,b,tol)
%
% Error control code:
%
  u=feval(FUNC,a);
  v=feval(FUNC,b);
  if u*v>0
     error('Input error: sign(f(a))=sign(f(b))')
     end
  leng=b-a;
  tol=min(tol,leng/2);
%
% Bisection algoritm:
%
i=0;
while leng>tol,
  c=(a+b)/2;
  i=i+1;
  trace(i)=c;
  u=feval(FUNC,a);
  v=feval(FUNC,b);
  w=feval(FUNC,c);
  output=c;
  if w==0
    length=0;
    end
  if w*u>0 
       a=c;
       leng=leng/2;
    else
       b=c;
       leng=leng/2;
    end
end  
output=c;

  

      
    