function x = bisect(f, int, tol)
% bisect - bisection algorithm for the scalar equation f(x) = 0
% 
%   Syntax: 
%           x = bisect(f, int, tol)
%   Arguments: 
%           f - function handle pointing to a function file  
%           int - 1x2 matrix specifying an interval int = [a,b]
%           tol - a tolerance 
%   Returns: 
%           x - an approximate solution in the interval int = [a,b]
%   Description:
%           The program bisect uses the bisection algorithm to 
%           compute an approximate solution of the scalar equation
%           f(x) = 0 in the interval int = [a,b].  The function file must 
%           contain the function y = f(x).  The function values f(a) 
%           and f(b) must have opposite signs.  Then the program
%           computes an approximate solution x with the error
%           |x-x_exact| < tol.  It returns an empty value for x if
%           f(a) and f(b) have the same sign.  
%   Examples: 
%          x = bisect(@sin,[1,4],1e-7)   computes pi to 6 decimals
%
%----------------------------------------------------------------------

% Replace the ??'s to get a working bisection solver.  

a=int(1);                  % left endpoint of interval 
b=    ??;                  % right endpoint

fa=f(a);             % evaluate f at a
fb=  ??;             % evaluate f at b

while b-a ??  

  x=??;             % compute midpoint x of (current) interval [a b]
  fx=??;            % evaluate f at midpoint

  if fx==0          % root at x
    return;
  end 

  if fa*fx<0        % root in the left half of the interval
    b=??;           % move b
    fb=??           % update fb
  else              % root in the right half of the interval
    ??               
  end

end

x=??   % compute the midpoint one more time 

