function x = bisect(f, a, b, eps) n = 0; while 1 n = n + 1; c = (a + b) / 2; if f(a)*f(c) > 0 a = c; else b = c; end if abs(f(c)) < eps break end end fprintf('%d iterations\n', n); x = c;