%
% Bisection Method:
%
%     Compute a root of f(x) on (a,b) with an error no
%     larger than tol. If trace=1 then the output
%
%        a  c  b  f(a)  f(c)  f(b)
%
%     will be printed to the screen at each step (hit
%     return to procede to next iterate).
%
%
function [root,x]=Bisect(a,b,tol,trace)
%
% Error control code:
%
  n=1;
  x(n)=a;
  if f(a)*f(b)>0
     error('Input error: sign(f(a))=sign(f(b))')
     end
  leng=b-a;
  tol=min(tol,leng/2);
%
% Bisection algoritm:
%
while leng>tol,
  c=(a+b)/2;
  n=n+1;
  x(n)=c;
  u=f(a);
  v=f(b);
  w=f(c);
  if trace==1
    [a c b u w v]
    pause
    end
  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  
root=c;

  

      
    