  function Roots = FindRoots(F,xMin,xMax)
% F is a handle to a function of a single variable that is 
%        defined on the interval [xMin,xMax].
% Roots is a row vector (possibly empty) of roots of F in the interval.

% Initialization...
  xMin0 = xMin;
  xMax0 = xMax;
  Roots = [];
  x = linspace(xMin,xMax);
  y = F(x);
  [a,b] = BWindow(x,y,Roots, '' );

  while a>=xMin && a<=xMax
%   Keep searching    
    dx = xMax-xMin;
    L = xMin + dx/4;
    R = xMax - dx/4;
%   Process the mouseclick
    if a < L  || a > R
        % Zoom Out. Do not go beyond initial interval.
        xMin = max(a-dx,xMin0);
        xMax = min(a+dx,xMax0);
        message = 'Zoomed out.'
    elseif abs(b) <= max(abs(y)) 
        % Zoom In. Do not go beyond initial interval.
        xMin = max(a-dx/4,xMin0);
        xMax = min(a+dx/4,xMax0);
        message ='Zoomed in.'; 
    else
        % Use Bisection to get a root.
        if F(L)*F(R)<0
           % Make sure [L,R] is a bracketing interval.
           xStar = Bisection(F,L,R)
           Roots = [Roots xStar];
           message ='Bisection applied. Root found!'; 
        else 
           message= 'Cannot apply bisection as F(L) and F(R) have the same sign'; 
        end
    end
    x = linspace(xMin,xMax);
    y = F(x);
    [a,b] = BWindow(x,y,Roots, message);   
end
        
            
        
    