Find a root of f(x)=0 by bisection on a bracketing interval with convergence reporting.
The bisection method finds a root by repeatedly halving a bracketing interval [a, b] where f(a) and f(b) have opposite signs. By the Intermediate Value Theorem, a root must exist in the interval. Each iteration halves the interval, guaranteeing convergence at a linear rate of about 1 bit per iteration.
Bisection step
mid = (a + b) / 2; if f(a)·f(mid) < 0 then b = mid, else a = mid
Error bound
error ≤ (b - a) / 2^n after n iterations
The IVT guarantees a root only when the function crosses zero between a and b. If both have the same sign, the root may not exist in that interval.
Bisection always converges but is slow (linear). Newton's method converges quadratically but can fail if the derivative is zero or the guess is bad.