% Program for generalized bisection 

% Step 1: Input -- We assume a, b, and epsilon have been
% assigned when this script is invoked.  We also need to
% have defined a function f(x), such that we want to
% solve for f(x) = 0.

% Step 2: Check for a sign change --

fa = f(a); fb = f(b);
if fa*fb > 0 then
   echo 'There is no sign change, so bisection cannot proceed.'
   success = 0
else
   % Step 3: bisection loop
   N = floor((log(b-a)/epsilon) / log(2))+1 