Pseudo-code

The following pseudo-code is from page 52:

Numerical Methods for Mathematics, Science and Engineering,
[Graphics:../Images/FixedPointProg_gr_1.gif] Ed, 1992
John H. Mathews
Prentice-Hall, Inc
ISBN:  0-13-624990-6


Tol := 0.000001                                  {Termination criterion}
Max := 200                                {Maximum number of iterations}
Small := 0.000001                              {Initialize the variable}
K := 0                                          {Initialize the counter}
RelErr := 1                                    {Initialize the variable}

INPUT  Pterm                                 {The initial approximation}
Pnew := g(Pterm)                                   (The first iteration)
      
WHILE  RelErr >= Tol and K <= Max  DO
|      K := K+1                                  {Increment the counter}
|      Pold := Pterm                             {Previous iterate
[Graphics:../Images/FixedPointProg_gr_2.gif]}
|      Pterm := Pnew                                {Current iterate
[Graphics:../Images/FixedPointProg_gr_3.gif]}
|      Pnew := g(Pterm)                       {Compute new iterate
[Graphics:../Images/FixedPointProg_gr_4.gif]}
|      Dg := Pnew - Pterm                           {Difference in g(x)}
|      Delta := |Dg|                                    {Absolute error}
|_____ RelErr := 2*Delta/(|Pnew|+Small)                 (Relative Error}

       Dx := Pterm - Pold                              {Difference in x}
       Slope := Dg/Dx                                           {g'(Pk)}
       
PRINT  "The computed fixed point of g(x) is "  Pnew             {Output}
PRINT  "Consecutive iterates are within "  Delta
IF |Slope| > 1 THEN
   PRINT "The sequence appears to be diverging."
ELSE
   PRINT "The sequence appears to be converging."
ENDIF

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(c) John H. Mathews 2004