You are on page 1of 3

Random-Walk Simulations

Jorge David Vega Bazantes1, ∗


1
School of Physical Sciences and Nanotechnology,
Yachay Tech University, 100119-Urcuqui, Ecuador
(Dated: September 26, 2018)
A random-walk program is part of a wide variety of computational methods known as Monte
Carlo simulations. These methods use pseudo random numbers in order to solve problems that in
other way are difficult to dealt with. The random-walk problem in 2D consists in choosing an initial
point (for instance the origin), and from there adding another point in a different direction based
on 2 pseudo random numbers, which are the values in the x and y axes respectively. The norm
of these two points has to be considered too. Then, we have to add more points, and so on. The
same approach applies when making simulations for the 3D case [1]. If we consider the previous
specifications it is possible to develop a simulation of normal diffusion. In the present work, some
random-walk simulations in 2D and 3D are presented, and some of its implications are discussed.

I. IMPLEMENTATION, PROCEEDINGS, AND we can compute the mean square distance hR2 i given by:
THEORY
K
1 X 2
The code has been implemented according to the in- hR2 i = R (N ) (3)
K n=1 (K)
structions provided by Landau et al. [1]. We choose
random values ∆x0 and ∆y 0 using the library random for

Python. Also notice that each step is normalized in this In my simulations I chose N = 100 steps for K = N =
way: 10 trials. This can be seen in CheckingTheory.py for
the 2D case, and in CheckingTheory3D.py for the 3D
∆x0 ∆y 0 ∆z 0 one.
∆x = , ∆y = , ∆z =
L L L 3. The theoretical arguments can be tested considering
p the previous mathematical background. Also, to validate
where, L = ∆x0 2 + ∆y 0 2 + ∆z 0 2 the theoretical results, I compute a selection of the values
that should accomplish the next condition:
Considering this, I developed some calculations in order
to visualize the walk produced by the algorithm, and to
check if some theoretical considerations are accomplished h∆xi ∆xj6=i i h∆xi ∆yj i
∼ ∼0 (4)
when running the program. The Python libraries mat- R2 R2
plotlib, and math were used too.
1. First of all, it is possible to develop the code for one In addition, if we consider the 3D case, we have to also
trial and N steps, then one can generalize to obtain a K analyse when:
number of trials. In my simulations, five trials were de-
veloped at first considering a random seed a = 1729, and h∆xi ∆zj i h∆yi ∆zj i h∆zi ∆zj6=i i
N = 1000 to see the patterns of each path. The imple- ∼ ∼ ∼0 (5)
R2 R2 R2
mentation of the code is written in the file VariousTri-
als.py for the 2D case, and in VariousTrials3D.py for To compute these kind of expected values one can make
the 3D case. It is important to consider that the radial calculations with the use of multiple f or loop. This is
distance R from the origin is given by: also analysed in the files CheckingTheory.py (2D) and
√ CheckingTheory3D.py (3D) for K trials. The analysis
R = Nr (1) for just one trial is done in CheckingTheory2.py (2D)
and in CheckingTheory3Dp2.py .
where r is the root-mean-square step size. Also, it is ex- p
4. Finally,
√ one can make a plot of R = hR2 (N )i with
pected that after a long walk, the average vector distance
will be: respect to N . According to theory, we would expect to
obtain approximately a relation of direct proportionality,
hRi = hxii + hyij + hzik ∼ 0 (2) or in other words a straight line. In my work I make the
plot for a single trial. This can be seen in the files Check-
2. Also, a run for K = 10 trials was developed so that ingTheory2.py (2D) and CheckingTheory3Dp2.py
(3D).
Additional comment: One can even make √ a plot for
the RK ’s (the R of each trial) in relation to N and still
∗ Electronic address: jorge.vega@yachaytech.edu.ec obtain interesting results, i.e. a straight line.
2

II. RESULTS AND DISCUSSION printed (in the 2D case), and 5 lists (in the 3D case)
respectively. Therefore, observing the results it is possi-
1. When doing the plots for some trials, it can be ble to affirm that (4) and (5) are correct, and also the
observed according to figure. (1) that the vector endpoint algorithms work as expected.

is distributed uniformly in all quadrants. It means that
p
4. The plot R = hR2 (N )i with respect to N is
the distribution of the trials are around the origin. nicely obtained for N = 300 steps in 2D and√3D. Evi-
dently there is a direct proportion of R and N . This
can be seen in figure (3) and figure (4)

FIG. 1: Five trials in 2D for a random seed a = 1729, and


N = 1000 steps


FIG. 3: Plot of R (the radial distance) in relation to the N
for N = 300 steps for the 2D case. This is done in Check-
ingTheory2.py. The plotted points form almost a perfect
straight line. Very little variations appear at the beginning if
that zone is zoomed. The random seed is set to a = 0

FIG. 2: Five trials in 3D for a random seed a = 1729, and


N = 1000 steps

2. Considering equations (1), and (3), it was obtained


hR2 i = 1.0. It is in complete agreement with what
was established in the equations and the algorithms as
N = 100 steps, and R2 = N r, where r = 1 (because
it was imposed a normalization in each step). This re-
sult is shown when running CheckingTheory.py, and √
FIG. 4: Plot of R (the radial distance)in relation to the N
CheckingTheory3D.py for N = 300 steps for the 3D case. This is done in Check-
3. The simulations to test equations (4) and (5) show ingTheory3Dp2.py. The plotted points form almost a per-
that for various trials (in the files CheckingTheory.py fect straight line. Very little variations appear at the begin-
(2D), and CheckingTheory3D.py (3D)) the result is ning if that zone is zoomed. The random seed is set to a = 0
approximately zero. The same remains for a run of one
trial. Notice that when executing the code, two lists are
3

III. CONCLUSIONS more general algorithm with object oriented pro-


gramming, and even movies of the walk’s move-
1. The theoretical results considered in the first part ments.
are in agreement with the random-walker algorithm
for 2D and 3D. Then, one could think about making
a generalization to the case of N dimensions.
2. As was seen in the plots for 2D and 3D the random- IV. ACKNOWLEDGMENTS
walker algorithm would be very useful to under-
stand processes in which molecules and random dis-
placements are involved. Miguel Ángel Suárez acknowledge for teaching in the
course in Computational Physics during the academic pe-
3. For further development, one could implement a riod 2018-2019 at Yachay Tech.

[1] Rubin Landau, Manuel Páez, and Cristian Bordeianu. WILEY-VCH Verlag GmbH Co. KGaA, USA, 2015.
Computational Physics. Problem Solving with Computers.

You might also like