Mini-Lab: Applications of Random Walks

 


Introduction

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.



Choose an Application

Choose at least one of the following applications to implement. They have varying degrees of difficulty.
  1. 1D random walk with drift

    (This problem is taken from Exercise 8.32 in the Langtangen textbook.)

    1. Modify your 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}.
    2. Compute the average position of np particles after 100 steps.
    3. Mathematically, it can be shown that the average position approaches r*ns - (1-r)*ns as np approaches infinity.
    4. Print out the average you calculated, along with this mathematical value.

  2. 1D random walk until a point is hit

    (This problem is taken from Exercise 8.33 in the Langtangen textbook.)

    1. Modify your 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.
    2. Test your new function for xp = 5, 50, 5000, 50000.
    3. Plot your results (xp on one axis, number of steps on the other).

  3. Pollen Movements as 2D random walk

    (This problem is taken from Exercise 8.35 in the Langtangen textbook.)

    1. The motion of single particles can often be described as random walks. On a water surface, 1000 grains of pollen are placed in a single point. The movement of the pollen grains can be modeled by a random walk, where for each second each grain will move a random distance along a 2-dimensional vector. Modify your 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.
    2. Test this code with 1 particle, and instead of showing a scatterplot to see the particle movement, plot this particle's x and y positions to see its path.
    3. Now test your code with 2 particles. When you are satisfied that your code is working properly, try 100, then 500, then 1000 particles. You may want to switch back to using a scatterplot to see the particle movement. You may also need to adjust the axis on your plot.

  4. 2D random walk with walls

    (This problem is taken from Exercise 8.37 from the Langtangen textbook.)

    1. Modify your 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.
    2. Variation: if the particle attempts to move outside of A, it should move one space in the opposite direction instead.

  5. Simulate mixing of gas molecules

    (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.)

    1. Modify your walk2D function so that the fixed area is the inerval A = [0, 1] x [0, 1]. Initially place 10000 particles at uniformaly distributed random positions in [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?

  6. Simulate slow mixing of gas molecules

    (This problem is from Exercise 8.40 in the Langtangen textbook.)

    1. Modify the previous exercise so that the wall dividing the box is not completely removed, but instead has a small hole.

Submit