Math-305, Numerical Methods & Matrices
Newton's 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 ANY specific programming language like Fortran, Maple, Java, Python, Matlab, C++, etc.
      
      ***************************************************************************
      *  NEWTON's ALGORITHM (pseudo-code)                                       *
      *  by Prof. Kevin TeBeest                                                 *
      *                                                                         *
      *  To approximate a zero of a differentiable function f(x),               *
      *  starting with an initial value believed close to the zero.             *
      *                                                                         *
      *  INPUT:                                                                 *
      *     f        -  ftn f(x) whose zero we seek                             *
      *     fprime   -  the derivative f'(x)                                    *
      *     x0       -  starting value believed to be close to the zero         *
      *    MAXITS    -  maximum number of iterations to allow                   *
      *    TOL       -  tolerance to stop iterating                             *
      *                                                                         *
      *  The program requires the function f(x) and its derivative              *
      *  fprime(x) = f'(x). These must be entered as functions and NOT as       *
      *  expressions.                                                           *
      ***************************************************************************

      1.  input x0, TOL, MAXITS, f, fprime

      2.  Repeat while  | f(x0) |  > TOL

          a.  set  y0 = f(x0)
              set  yp = fprime(x0)
     
          b.  set  x1 = x0 - y0/yp

          c.  print iter #, x1, and f(x1)
          
          d.  set x0 = x1




NOTE: the formula for Newton's method is

x1   =   x0   –  f (x0) / f ' (x0)    and NOT    x1   =   ( x0   –  f (x0) ) / f ' (x0)


Return to Section 1.3 assignment

Return to course web site