%% bisection1
%
xtol = input ( 'Enter tolerance for interval size: ' );
a = input ( 'Enter left  endpoint of change of sign interval: ' );
b = input ( 'Enter right endpoint of change of sign interval: ' );

if ( sign ( f(a) ) * sign ( f(b) ) ~= -1 )
  error ( 'F(A) and F(B) are not of opposite signs!' );
end

while ( xtol < b - a )
%
%  Get the interval midpoint.
%
  c = ( a + b ) / 2.0;
%
%  Choose new interval [C,B] or [A,C].
%
  if ( sign ( f(c) ) == sign ( f(a) ) )
    a = c;
  else
    b = c;
  end

end
%
%  Choose midpoint as estimated zero.
%
x = ( a + b ) / 2.0;
fprintf ( 'Estimated zero F(%20.16g) = %g\n', x, f(x) );
