The Bisection Method is perhaps the first of the root-finding methods because it works like our minds do. If we know a root exists in an interval [a,b], all we have to do is keep cutting the interval in half and look in the more appropriate half. How do we do that?
A Bisection Method
First, note that the bisection method relies upon functions
This function must be continuous on [a,b]. Further, almost all bisection codes rely on the fact that f(a)*f(b)0 at x=a and x=b. We couldn’t verify the existence of roots. Functions such as g(x)=sin(x)+3 have no roots on any interval! Consequently, without further automation, we must check for f(a)*f(b)<0.The bisection method approximates the root atp_i=(a+b)/2.If f(a)*f(p_i)<0, then we pick b=p_i. Otherwise a=p_i. We continually shrink the interval until abs(b-a)< eps.
A version of the bisection method written for MATLAB or Octave is posted at bisect.m. This code requires a function given by handle and an interval [a,b]. Additional options include maximum iterations, tolerance on the root and tolerance on the function value.
I hope this is useful for coursework in basic numerical analysis classes or for basic root finding.