Pseudo-code
The following pseudo-code is from page
52:
Numerical Methods for Mathematics, Science and Engineering,
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
}
| Pterm :=
Pnew {Current
iterate
}
| Pnew :=
g(Pterm) {Compute
new iterate
}
| 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