You are on page 1of 23

Homework 6: Random Walks and Diffusion

Johnson Liu
15 May 2016

1 Random Walk in Two Dimensions


The movement of particles in two dimensions within a closed system can be described using equations of
motion that finds the velocity and position for each of the particles during each moment in time. This
approach however, is not feasible when modeling the behavior of a large number of particles. The modeling
of the movement of many particles can be simplified if the collision between the particles are modeled as
random walks performed by each of the particles.
A random walk done by one particle in two dimensions can be modeled using a random number generator.
When working in two dimensions, the simplest motion that a particle can partake includes the movement in
the left, right, up, and down directions. During each step in time, a random number can be generated to
decide in which direction the particle moves. In the simplest case, the particle moves the same distance for
every step in time. The following generator can be used to produce random numbers to decide the direction
in which a particle moves during each time step:

xn+1 = (axn + c)%m , (1)

where xn is the random number produced in the previous time step, xn+1 is the new random number
generated in the current time step, a, c, and m are chosen constants, and % is the modulo operation that
finds the remainder when the quantity axn + c is divided by m. In this case, a, c, and m are chosen to be
75 , 0, and 231 − 1, respectively. When given a starting number for xn , or a seed, the generator shown in
Equation (1) produces a pseudo-random number in the range [1, m) during each iteration. The number can
be divided by m to produce a number in the range (0, 1). In this case, if 0 < xn+1 < 41 , then the particle
moves to the right. If 14 ≤ xn+1 < 24 , then the particle moves to the left. If 24 ≤ xn+1 < 34 , then the particle
moves up. If 34 ≤ xn+1 < 1, then the particle moves down. When working with more than one particle, the
model discussed can be used to decide the movement of each particle during each time step in the simulation.
When modeling the random walk of particles in this fashion, the probability of a particle moving in any of
the four directions is equal to 14 , the movement of each particle is independent of its previous motion, and
the movement of the particles are independent from each other.
Figures 1, 2, 3, 4, and 5 show the movement of four particles contained within a 11x11 grid. The particles
do not collide with each other in this simple case, but their motions are still modeled by random walks in
order to show the behavior that the random walk model produces. In the figures shown, none of the particles
stack on top of each other, but the code used in simulation allows for multiple particles to occupy the same
space during a given time step. Also, when a particle reaches the edge of the grid, the particle appears on
the other side of the grid if it decides to move over the edge.

2 Simple Diffusion in Two Dimensions


A more complicated and interesting case can be explored by extending the 11x11 grid to a 101x101 grid with
12,100 particles instead of four. The 12,100 particles are distributed uniformly across a 11x11 box within the
center of the 101x101 grid. Each index within the box contains 100 particles stacked on top of each other.
Figure 6 shows the 101x101 grid that contains 12,100 particles before the simulation begins. Figures 7
through 16 show the diffusion of the particles over time. In each figure, the scale of the colorbar is modified

1
Figure 1: Random walk of four particles in a 11x11 grid. Time = 0 iterations.

Figure 2: Random walk of four particles in a 11x11 grid. Time = 1 iteration.

2
Figure 3: Random walk of four particles in a 11x11 grid. Time = 2 iterations.

Figure 4: Random walk of four particles in a 11x11 grid. Time = 3 iterations.

3
Figure 5: Random walk of four particles in a 11x11 grid. Time = 4 iterations.

Figure 6: Random walk of 12,100 particles in a 101x101 grid. Time = 0 iterations.

4
Figure 7: Random walk of 12,100 particles in a 101x101 grid. Time = 1 iteration.

Figure 8: Random walk of 12,100 particles in a 101x101 grid. Time = 10 iterations.

5
Figure 9: Random walk of 12,100 particles in a 101x101 grid. Time = 50 iterations.

Figure 10: Random walk of 12,100 particles in a 101x101 grid. Time = 100 iterations.

6
Figure 11: Random walk of 12,100 particles in a 101x101 grid. Time = 200 iterations.

Figure 12: Random walk of 12,100 particles in a 101x101 grid. Time = 500 iterations.

7
Figure 13: Random walk of 12,100 particles in a 101x101 grid. Time = 1000 iterations.

Figure 14: Random walk of 12,100 particles in a 101x101 grid. Time = 2000 iterations.

8
Figure 15: Random walk of 12,100 particles in a 101x101 grid. Time = 3000 iterations.

Figure 16: Random walk of 12,100 particles in a 101x101 grid. Time = 10,000 iterations.

9
according to the highest occupancy of the indices within the grid so that it is easier to see the particles as
they diffuse throughout the grid. Qualitatively, the particles seems to spread over each of the four direction
at equal rates. This is due to the uniform distribution of random numbers that are generated by the random
number generator shown in Equation (1). Figure 17 shows the distribution of random numbers within the
range (0, 1) generated by the generator being used. The amount of numbers within each bin of size 41 are
approximately the same. Overall, the movement in each of the four directions should be approximately
equal when averaging over the many particles that move through a random walk. The overall behavior of
the group of particles is diffusive because there are move ways for each particle to move away from its original
position than there are ways for each particle to move back to its original position. Over time, the group of
particles continue to move further and further away from their initial starting positions. After the passage
of enough iterations, the change in the distribution of particles across the grid begins to become less and
less noticeable. The distribution of particles in Figure 15 where 3000 iterations has passed is qualitatively
the same as that in Figure 16 in which 10,000 iterations have passed.

3 Rate of Diffusion
For a particle moving at a constant velocity, the distance of the particle is proportional to the amount time
that has elapsed since the start of the particle’s motion if that particle does not experience any collisions
with other particles:

x = vt . (2)

For particles in which their motion is obstructed by collisions with other particles however, the average
distance of the particles from their initial positions is proportional to the square root of the time that has
passed:

1 1
(< x2 >) 2 = Dt 2 , (3)

where D is the diffusion constant. One method to approximate the average rate of diffusion for the 12,100
particles in a 101x101 grid case is to find the box that contains about 90% of the total number of particles
after a certain number of iterations has elapsed. The average distance that a particle has traveled is taken
to be half of the length of the box. Figures 18 through 22 show the box that contains about 90% of all the
particles during a given moment in time. Figure 23 shows a graph that plots half the length of the box that
contains about 90% of the particles against the square root of time. The green line shows the fitted line to
the data points while the purple line shows the fitted line through the point (0, 0). The blue points do not
start at (0, 0) since the particles are initially placed throughout a 11x11 grid in the center of the 101x101
grid. The equation for the general trend is in the form of Equation (3). The predicted number of iterations
for it to take about 90% of the particles to reach the edge of the grid according to the equation of the trend
line is about 1,418 iterations. Figure 24 shows the state of the system after 1,418 iterations. The simulation
shows that half the length of the box that contains about 90% of all of the particles in the grid is 45.5,
1
instead of 50 as expected by the equation for the trend line of x vs t 2 . This method for finding the rate of
diffusion is only an approximation.
Another method for finding the rate of diffusion involves the use of the root mean square of the position
of the particles:

N
1 X 2
< rt2 >= 2
(x + yi,t ). (4)
N i=1 i,t

Figure 25 shows the square root of < r2 > plotted against the square root of time for the 12,100 particle
system. The equation of the trend line is still in the form expected by Equation (3).

10
Figure 17: Distribution of random numbers within the range (0, 1) assorted into four bins of size 14 .

Figure 18: Box that contains about 90% of the particles. Time = 1 iteration.

11
Figure 19: Box that contains about 90% of the particles. Time = 25 iterations.

Figure 20: Box that contains about 90% of the particles. Time = 100 iterations.

12
Figure 21: Box that contains about 90% of the particles. Time = 225 iterations.

Figure 22: Box that contains about 90% of the particles. Time = 400 iterations.

13
Figure 23: Half the length of the box versus square root of time.

Figure 24: Box that contains about 90% of the particles. Time = 1418 iterations.

14
Table 1: Number of particles to the right, left, top, and bottom of the origin index at time = 1 iteration.
Direction Number of Particles
Right 2988
Left 2989
Above 3028
Below 3085

4 Entropy
When the particles diffuse across the surface of the 101x101 grid, the entropy of the system increases as the
system becomes less an less orderly. The order of the particles within the grid is at its greatest before the
simulation begins. As time passes, the order of the system decreases and the entropy increases until it reaches
some limiting value. After this point in time, the entropy of the system remains around the limiting value
with the further passing of time. The particles within the grid are no longer diffusing and the distribution
of particles is no longer qualitatively different between successive time steps. When this occurs, the system
has reached equilibrium. Previously, Figures 14, 15, and 16 show that the time it takes for this particular
system to reach equilibrium is somewhere between 2,000 and 10,000 iterations.
The equation for determining the entropy of the system at a particular moment in time is as follows:

X
S=− Pi ln(Pi ) , (5)
i

where i is a subregion of the 101x101 grid and Pi is the probability of finding a particle in subregion i during a
specific moment in time. The probability of finding a particle in subregion i is simply the number of particles
in that subregion divided by the total number of particles contained within the entire grid. Figure 26 shows
a plot of entropy as a function of number of iterations.

5 12,100 Particles Stacked in One Point


Figure 27 shows the 101x101 grid with 12,100 particles stacked on top of each other on a single index within
the grid. Figures 28 through 32 show the diffusion of these particles over time. Initially, the particles seem
to spread out somewhat evenly although not entirely symmetrically. When the number of iterations is small,
the number of particles in each box is not exactly equal to each other. It only looks like each occupied box has
the same number of particles because of the color scale. However, the distribution is still very orderly. The
initial orderly spread of the particles is due to the mechanism in which the particles decide which direction
to move during each iteration. Since each particle has a 41 chance of moving in any of the four directions,
the number of particles to the right, left, top, and bottom of the origin index after the first iteration should
be about the same in each direction. In this case, given the initial conditions set for the random number
generator, Table 1 shows the number of particles in each of the four indices around the origin index at time
= 1 iteration. If the spread of the particles were completely symmetrical, the number of particles in each of
the positions around the origin index would be 3,025.

6 Concentration-Dependent Diffusion
Figures 33 through 37 show the concentration-dependent diffusion of the 12,100 particles within the 101x101
grid. In these simulations, the probability of a particle moving in each of the four directions is adjusted
according to the present concentration of particles in each direction. The higher the concentration in a
particular direction, the less likely a particle will move into that index compared to the other choices of
direction. Ideally, if the diffusion of the particles is concentration-dependent, then it would take less time for
the system to reach equilibrium because the particles spend less time moving into areas of higher concentra-
tion and spend more time exploring areas of lower concentration. However, the behavior of the particles in

15
Figure 25: Square root of RMS plotted against square root of time.

Figure 26: Entropy of the 12,100 particle system as a function of number of iterations.

16
Figure 27: Diffusion of 12,100 particles stacked on one point. Time = 0 iterations.

Figure 28: Diffusion of 12,100 particles stacked on one point. Time = 1 iteration.

17
Figure 29: Diffusion of 12,100 particles stacked on one point. Time = 5 iterations.

Figure 30: Diffusion of 12,100 particles stacked on one point. Time = 10 iterations.

18
Figure 31: Diffusion of 12,100 particles stacked on one point. Time = 100 iterations.

Figure 32: Diffusion of 12,100 particles stacked on one point. Time = 500 iterations.

19
the figures shown seems to be off. Compared with the case in which diffusion is independent of concentration,
the current case produces a result in which the particles tend to move in the right and left directions at a
faster rate than in the top and bottom directions. This could be a result of the concentration dependence of
diffusion, or more likely, there is something wrong with the code.

20
Figure 33: Concentration-dependent diffusion of 12,100 particles within a 101x101 grid. Time = 1 iteration.

Figure 34: Concentration-dependent diffusion of 12,100 particles within a 101x101 grid. Time = 10 iterations.

21
Figure 35: Concentration-dependent diffusion of 12,100 particles within a 101x101 grid. Time = 50 iterations.

Figure 36: Concentration-dependent diffusion of 12,100 particles within a 101x101 grid. Time = 100 itera-
tions.

22
Figure 37: Concentration-dependent diffusion of 12,100 particles within a 101x101 grid. Time = 500 itera-
tions.

23

You might also like