recent links: article Main Page

From NewWiki

This is the HTML version of the notebook:Diffusion.nb

Simulating diffusion

This notebook performs a simple simulation of a collection of particles being released in a partitioned container where gaps in the container allow particles to pass through.

First of all we simulate brownian motion. A brownian motion step, will move a random direction, but fixed distance, from the current position.

r = 0.25 ;

bmstep[{x_, y_}] := Block[{x2, y2, θ},       &nbs ... nbsp;     If[! barrierq[{x, y}, {x2, y2}], {x2, y2}, bmstep[{x, y}]]] ;

Now we define the container. This is done with a test to decide whether a barrier has been crossed. The brownian motion function only allows the motion if no barrier is crossed.

In this example the container is bounded by x==0, y==0, x==10, y==10 and with a partition at x==5 but a hole in thepartition between y==4 and y==5

barrierq[{x_, y_}, {x2_, y2_}] := Which[       &n ... sp; Max[x, x2] >5&&Min[x, x2] <5&&y2>5, True, True, False]

Here we show the paths of 50 particles over 300 steps. Most are contained in the start area, but some pass through the hole.

Show[Table[ListPlot[NestList[bmstep, {0, 0}, 300], PlotJoinedTrue, DisplayFunctionIdentity], {50}], DisplayFunction$DisplayFunction, PlotRangeAll]

[Graphics:HTMLFiles/Diffusion_5.gif]

⁃Graphics⁃

We can watch an animation of the particles gradually escaping, and sometimes returning, until equal numbers can be found in each half of the box.

data = Table[{0, 0}, {100}] ;

Do[ListPlot[data, PlotRange {{0, 10}, {0, 10}}, Epilog {Line[{{5, 0}, {5, 4}}], Line[{{5, 10}, {5, 5}}]}] ; data = Map[bmstep, data] ;, {1000}]


Created by Mathematica  (May 26, 2005) Valid XHTML 1.1!
Retrieved from Diffusion.nb .
Personal tools