Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

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[1] = 100; Tnew[2] = 900; Tnew[3] = 1.7; Tnew[4] = 30; Told[1] = 0;
Told[2] = 0; Told[3] = 0; Told[4] = 0; maxiteration = 100;
Tol = 0.001;
  While[iter < maxiteration, iter++; If[maxerr > Tol, To = Tn];
    Tn[[1]] = (ji*hi + To[[2]] + To[[3]])/4;
    Tn[[2]] = (ji*r + To[[1]] + To[[4]])/4;
    Tn[[3]] = (ji*s + To[[1]] + To[[4]])/4;
    Tn[[4]] = (ji*t + To[[2]] + To[[3]])/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