Problem 3

Question

Brownian motion is the motion of a particle, such as a smoke or dust particle, in a gas, as it is buffeted by random collisions with gas molecules. Make a simple computer simulation of such a particle in two dimensions as follows. The particle is confined to a square grid or lattice \(L \times L\) squares on a side, so that its position can be represented by two integers \(i, j=0 \ldots L-1\). It starts in the middle of the grid. On each step of the simulation, choose a random direction-up, down, left, or right-and move the particle one step in that direction. This process is called a random walk. The particle is not allowed to move outside the limits of the lattice-if it tries to do so, choose a new random direction to move in. Write a program to perform a million steps of this process on a lattice with \(L=101\) and make an animation on the screen of the position of the particle. (We choose an odd length for the side of the square so that there is one lattice site exactly in the center.) Note: The visual package doesn't always work well with the randon package, but if you import functions from visual first, then from random, you should avoid problems.

Step-by-Step Solution

Verified
Answer
The simulation runs one million steps by randomly moving the particle within a 101x101 grid, visualizing the path using matplotlib.
1Step 1: Set Up the Grid
Define the lattice size as L=101, an odd number that ensures a central starting point. This grid will be a two-dimensional array with indices ranging from 0 to L-1.
2Step 2: Initialize the Particle's Position
Set the initial position of the particle at the center of the grid. For an LxL grid with L=101, the center is at coordinates (50, 50).
3Step 3: Choose a Random Direction
For each step of the simulation, select a random direction. The four possible directions are up, down, left, and right.
4Step 4: Check the Boundaries
Before moving the particle, check if the direction will lead the particle off the grid. If it does, choose a different random direction.
5Step 5: Move the Particle
If the chosen direction does not lead outside the grid, update the particle's position accordingly.
6Step 6: Repeat the Steps
Repeat steps 3 to 5 for one million iterations to simulate the particle's random walk.
7Step 7: Visualize the Motion
Create an animation to display the particle's position on the screen as it moves through the grid. Ensure the visualization library is imported before the random library to avoid compatibility issues.
8Step 8: Python Implementation
Using Python, the code can be structured as follows:```pythonimport visualimport randomimport matplotlib.pyplot as plt# Step 1: Set up the griddefine L = 101# Step 2: Initialize the particle's positionx = L // 2y = L // 2# Create lists to store the particle's path for visualizationpath_x = [x]path_y = [y]# Step 6: Repeat the steps for a million iterationsfor _ in range(1000000): # Step 3: Choose a random direction direction = random.choice(['up', 'down', 'left', 'right']) # Step 4: Check the boundaries and move the particle if direction == 'up' and y < L-1: y += 1 elif direction == 'down' and y > 0: y -= 1 elif direction == 'left' and x > 0: x -= 1 elif direction == 'right' and x < L-1: x += 1 # Append the new position to the path lists path_x.append(x) path_y.append(y)# Step 7: Visualize the motionplt.plot(path_x, path_y)plt.show()```

Key Concepts

random walkparticle motioncomputer simulation
random walk
The concept of a random walk is fundamental to understanding Brownian motion. In this exercise, the particle's movement is represented by a random walk on a 2D grid. A random walk involves taking steps in random directions with no specific pattern. For each step, a direction (up, down, left, or right) is chosen at random.
This method mimics the seemingly random movement observed in nature, such as the motion of pollen grains and dust particles when suspended in the air. The behavior over time tends to show patterns of diffusion and is essential for modeling various physical processes.
By simulating a million steps, we can observe how the random walk leads to the particle's erratic path across the grid. Despite the randomness, certain trends, such as clusters and areas of higher density, can emerge with enough steps.
particle motion
Particle motion in a Brownian motion simulation refers to the discrete steps the particle takes based on the random walk algorithm. The particle starts from a central point and moves one unit in a random direction per iteration.
  • The particle is confined within a square lattice of size 101x101.
  • Each possible move is constrained to the boundaries of this lattice.
  • If the particle attempts to move beyond the grid, a new random direction is chosen.
This setup ensures that the particle remains within the visible area of the simulation. Over many iterations, the particle's path will display a combination of straight segments and turns, reflecting the randomness of each step's direction. This simulation helps students visualize and understand the concept of Brownian motion and the impact of random forces on particles.
computer simulation
Using computer simulation to model Brownian motion allows us to visualize complex phenomena that would be challenging to observe manually. In this exercise, Python is used to create the simulation. Here are key components of the simulation:
  • Setting up the grid: A 101x101 grid is defined to represent the space in which the particle moves.
  • Initializing the particle: The particle starts at coordinates (50, 50), which is the center of the grid.
  • Random direction selection: At every step, the particle randomly chooses one of four possible directions (up, down, left, or right).

The simulation uses loops and random number generation to perform a million steps of random motion while ensuring the particle remains confined within the grid. Visualization tools, such as Matplotlib, are used to plot the particle's path, providing a visual representation of its motion.
This combination of computational techniques helps illustrate theoretical concepts and makes abstract ideas tangible. Additionally, by testing different scenarios and parameters, students can explore how various factors influence the motion and behavior of particles in different environments.