In the previous mini-lab, you wrote functions to simulate random walks in one and two space dimensions. In this mini-lab, we will use those functions in applications of random walks.
(This problem is taken from Exercise 8.32 in the Langtangen textbook.)
walk1D
from the previous mini-lab
so that the probability of going to the right is r
and the probability of going to the left is 1-r
.
You will need to draw random numbers in the interval [0,
1)
rather than integers in {1, 2}
.
np
particles
after 100 steps.
r*ns - (1-r)*ns
as np
approaches infinity.
(This problem is taken from Exercise 8.33 in the Langtangen textbook.)
walk1D
function from the previous
mini-lab to measure to measure how many steps it takes for one
particle to reach a given point x = xp
. The value
for xp
should be given by the user.
xp = 5, 50, 5000,
50000
.
xp
on one axis, number
of steps on the other).
(This problem is taken from Exercise 8.35 in the Langtangen textbook.)
walk2D
so that the movement is in a
random direction. To get a random direction for movement, we
need to use a random angle, such as in the following:
theta = 2.0 * math.pi * random.random()Then
cos(theta)
and sin(theta)
get
added to the x and y positions, respectively, for the particle.
(This problem is taken from Exercise 8.37 from the Langtangen textbook.)
walk2D
function so that the
walkers (i.e. the particles) cannot walk outside a
rectangular area A = [xL, xH] x
[yL, yH]
. Do not move the
particle if its new position is outside A.
A
, it should move one space in the opposite
direction instead.
(This problem is taken from Exercise 8.39 in the Langtangen textbook and builds on the 2D random walk with walls exercise.)
Suppose we have a box with a wall dividing the box into two
equally sized parts. In one part we have a gas where the molecules
are uniformly distributed in a random fashion. At t =
0
we remove the wall. The gas molecules will now move
around and eventually fill the whole box.
This physical process can be simulated by a 2D random walk inside
a fixed area A
as introduced in the previous exercise.
(In reality, the motion is three-dimensional, but we'll just do it
in two dimensions. You are welcome to work on a three-D model if
you'd like the challenge.)
walk2D
function so that the fixed
area is the inerval [0, 1/2] x [0, 1]
. Then start the random
walk and see what happens. Simulate for a long time. Is the result
what you would expect?
(This problem is from Exercise 8.40 in the Langtangen textbook.)