Math-305, Numerical Methods & Matrices
Bisection Method to Approximate a Zero of a Function

Dr. Kevin G. TeBeest

NOTE:   This is NOT a code. Pseudo-code is a simple way to represent an algorithm in a logical and readable form.
It allows the code writer to focus on the logic of the algorithm without being distracted by details of
language-specific syntax in which the code is to be written. A pseudo-code is the logic the code-writer could follow
to TRANSLATE the algorithm into a SPECIFIC programming language like Fortran, Maple, Python, Matlab, C++, etc.
     
      
      **********************************************************
      BISECTION ALGORITHM  (Pseudocode)        Dr. Kevin TeBeest

      To approximate a zero of a continuous function f(x) on an 
      interval [a,b] where f(a) and f(b) have opposite signs.

      INPUT:
          a       -  left endpoint of starting interval
          b       -  right endpoint of starting interval
          MAXITS  -  maximum number of iterations to allow
          TOL     -  tolerance to stop iterating
      **********************************************************

      1.  input a, b, TOL, MAXITS

      2.  set  xL = a
          set  xR = b
          set  yL = f(xL)
          set  yR = f(xR)
          set  ym = TOL + 1.0

      3.  Repeat while | xR - xL | > TOL 

          a.  set  xm = ( xL + xR ) / 2
              set  ym = f(xm)

          b.  IF yL and ym have opposite signs, then
                 set  xR = xm
                 set  yR = ym 
              otherwise
                 set  xL = xm
                 set  yL = ym

          c.  print desired results: 
                 for example:   N, xL, xR, xm, |ym|, |xR - xL| 
                 In reality we probably would not print xL and xR at each iteration.

HINTS:
  1. Two quantities u and v have opposite signs if their product is negative.
  2. Avoid using lower case letter l (ell). It is easily confused with the number 1.


Return to Section 1.1

Return to course web site