Math-305, Numerical Methods & Matrices
False Position 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 ANY specific programming language like Fortran, Maple, Java, Python, Matlab, C++, etc.
      
      
      **********************************************************

      FALSE POSITION ALGORITHM              Dr. Kevin G. 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
         f       -  the function whose zero we seek
         MAXITS  -  maximum number of iterations to allow
         TOL     -  tolerance to stop iterating
      **********************************************************

      1.  input a, b, f, TOL, MAXITS

      2.  set  xL = a
          set  xR = b
          set  yL = f(xL)
          set  yR = f(xR)
          set  ym = TOL + 1
      
      3.  Repeat for N from 1 to MAXITS as long as |ym| > TOL

          a.  set  xm = ( xL*yR – xR*yL ) / ( yR – yL )
              set  ym = f(xm)

          b.  print desired results:
                for example: N, xL, xm, xR, ym

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


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.2 assignment