       # Iterative Type Programming

```    Below is a program that I wrote as the solution to the temperatures
at different nodes in a "gridwork" (a homework problem). I am still not
as proficient with Mathematica as I would like to be and would like
some opinions on a better way to write an iterative type program. One
of the requirements was to always use the latest values when solving
the equations (Gauss-Seidel). I really feel like I fumbled through this
thing! Also, at the time the only way I could get it to converge was by
making it iterate until "maxiter" was met, but I wanted to have it
iterate until the "tol" was met, any suggestions on how to do this as
well?

Off[General::spell]; gs :=
Tn = Array[Tnew, 4];
To = Array[Told, 4];
error = Array[err, 4];
iter = 0;
ji = 10;
hi = 15;
r = 30;
s = 35;
t = 50;
Tnew = 100; Tnew = 900; Tnew = 1.7; Tnew = 30; Told = 0;
Told = 0; Told = 0; Told = 0; maxiteration = 100;
Tol = 0.001;
While[iter < maxiteration, iter++; If[maxerr > Tol, To = Tn];
Tn[] = (ji*hi + To[] + To[])/4;
Tn[] = (ji*r + To[] + To[])/4;
Tn[] = (ji*s + To[] + To[])/4;
Tn[] = (ji*t + To[] + To[])/4];
Do[err[i] = Abs[Told[i] - Tnew[i]], {i, 1, 4}]; maxerr = Max[error];
On[General::spell];
Print[TableForm[N[Tn]]]

```

• Prev by Date: RE: Question about Mathematica
• Next by Date: RE: Conic Sections and Quadric Surfaces
• Prev by thread: Re: Any interest (Wolfram or general) in fast multiply?
• Next by thread: Re: Iterative Type Programming