function bisect()
a = 1;
b = 2;
tol = 1.0e-5;

fa = f(a);
fb = f(b);

if sign(fa) == sign(fb)
	error('f must have different sign at endpoints')
end

fprintf(1, 'a = %f, b = %f, fa = %f, fb = %f\n', a, b, fa, fb)

while abs(b-a) > 2*tol
   c = (a + b) / 2;
   fc = f(c);

   if sign(fc) ~= sign(fb)
      a = c;  fa = fc;
   else
      b = c;  fb = fc;
   end

   fprintf(1, 'a = %f, b = %f, fa = %f, fb = %f\n', a, b, fa, fb)
end

fprintf(1, 'Approximate root = %f\n', (a+b)/2)

function y = f(x)
y = x.^3-x-1;
