Skip to main content
1-Visitor
June 6, 2012
Question

Programing, random walk applications

  • June 6, 2012
  • 3 replies
  • 5389 views

This is a program I am having a problem getting to run. It is using a random walk to determine a "temperature" at a point (xo,yo) in a square plate. The temperature distribution is T(x,y) with the boundaries held at specified temperatures. There is no heat transfer in the z-direction. The method is solving for

T(x,y) one point at a time for the LaPlace equation.

The method is based on the relaxation technique, where at at given point there is 1/4 probability to move in the four directions x+, x-, y+, y-. Several random walks are performed from (xo,yo), each time reaching a different boundary. The frequency of how often one reaches a given boundary out of N random walk trials times the temperature of that boundary will estimate T(xo,yo) =( Sfi*Ti). (This is a problem given in NUMBER CRUNCHING, by Paul J. Nahin. He writes great books)

The attached Mathcad 14.0 program which includes a schematic of the heat transfer scenario, What I think is the program algorithm and the Mathcad program is attached. I have tried several "permutations" of the program and still can't get it to work. Help, please.

3 replies

23-Emerald V
June 7, 2012

Can you provide a bit more information about the algorithm?

I'm confused about the quantities involved here: the first diagram seems to imply that T represents temperature but x & y imply distance (over 0 to 1, which contradicts the xo and yo initial values)

Furthermore, , I can't see how it ever gets into the while loop, as T4 = T2 and T isn't updated at any stage, so the relation T4<y<T2 is never true,

Your "if xdir<0.5" section doesn't appear to agree with the flowchart, which seems to require both xdir and ydir be less than 0.5 to increment x and y?

Stuart

PS. It's unusual to see one-line multiple assignments done as part of a boolean expression; it works but could be confusing to some readers by implying that it's part of the logic.

1-Visitor
June 14, 2012

This problem is in Nahin's book - Number Crunching. The "exchange" of (x,y) - (Tx, Ty) works out because he chose one side to have a temperature of 100 C and the other three side as 0 C. It is a unit square divided into 100 parts and the temperature is divided into 100 parts. Ordinarily one would have to choose a different "delta" for space and temperature.

As I mentioned, I thought I had the algorithm correct, but not sure. Also, I never have any luck setting up a "while loop". The idea is to random walk in the unit plane until one of the edges is reached. At each point one has four choices: + or - 1 x and + or - 1y ( in temperature units). Depending on which edge is reached a frequency( fi, i =1,2,3 or 4) of one is recorded for that edge. After many random walks, the quantity: sum fiTi then estimates the steady state temperature ( via solution of the LaPlace) for the starting point or (xo, yo).

Nahin sets up this problem in Matlab - I may be able to scan his program. I tried to duplicate his program in Mathcad and obviously didn't succeed.

Don R.

24-Ruby III
June 15, 2012

Donald Regula wrote:

...This problem is in Nahin's book - Number Crunching...

Some of the pages of this book can be found here:

http://books.google.ru/books?id=pxz8G-KF3ZgC&printsec=frontcover&hl=ru#v=onepage&q&f=false

Donald Regula wrote:

...Nahin sets up this problem in Matlab - I may be able to scan his program...

Can you provide some screenshots?

24-Ruby IV
June 7, 2012

The Mathcad program language has not the goto operator.

Therefore better use not flowcharts but structure symbols for graphical descriptions of Mathcad programs.

See please - http://twt.mpei.ac.ru/ochkov/Mathcad_14/MathcadWorkSheetAsFlowChartEng.pdf

19-Tanzanite
June 7, 2012

More like the attached I think (though you'll probably need far more than 360 trials to get a decent result).

Alan

Note: Don't confuse displacement and temperature!! Unfortunately, your displacements (x and y) run from 0 to 100, and your temperatures are either 0 or 100. This doesn't mean you can sensibly compare a displacement and a temperature.

19-Tanzanite
June 7, 2012

On second thoughts, my previous effort always made an x-direction change before a y-direction change. The direction changes should be random, so the attached is better.

Alan

PS I agree that Paul Nahin writes great books!