Home > Python > Application in Statistical Mechanics

Ch. 21.5 1D Random Walk Simulation

Chapters Index
Program 1

1D Random Walk Simulation

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.

Mathematical Problem Formulation

Simulation of 1D Random Walk: The random walk is defined as a series of steps taken in either the positive or negative direction with equal probability.

Program 2

1D Random Walk Simulation

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.

Mathematical Problem Formulation

Simulation of 1D RW
Program 3

1D Random Walk Simulation

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.

Mathematical Problem Formulation

Simulation to generate \( N = 10,000 \) random walks, each consisting of \( T = 1,000 \) time steps. Each step should be a random integer that can either be +1 or -1, representing random walk in one dimension.

Calculate the root mean square (RMS) of the positions, which is the measure of the average displacement from the origin.

Theoretical Background & Computational Mechanics

One-Dimensional Random Walk

In a one-dimensional random walk, an object starts at a fixed position (usually the origin, \( x = 0 \)). At each time step, it takes a step of fixed size (often taken as 1 unit) in either the positive or negative direction. The step direction is determined randomly, with equal probability for each direction.

Mathematically, at each time step \( t \), the position \( X(t) \) can be expressed as:

\[ X(t) = X(t-1) + S(t) \]

where \( S(t) \) is a random variable that takes the value +1 or -1 with equal probability (i.e., \( P(S(t) = +1) = 0.5 \) and \( P(S(t) = -1) = 0.5 \)).

Number of Walks:

In this simulation, \( N = 10,000 \) random walks are generated. Each random walk consists of \( T = 1,000 \) time steps, which allows for a large dataset to analyze the properties of the random walk statistically.

Cumulative Position Calculation:

The cumulative position of the walker after each step can be computed using the cumulative sum of the steps taken. This gives a time series of positions for each random walk.

Root Mean Square (RMS) of Positions

The root mean square (RMS) is a statistical measure used to quantify the magnitude of a varying quantity. It provides an average value that takes into account the variability of the data.

For a set of values \( x_1, x_2, \ldots, x_T \), the RMS is calculated as:

\[ R_{\text{rms}} = \sqrt{\frac{1}{T} \sum_{i=1}^{T} x_i^2} \]

Theoretical Principles & Computational Physics Guide

1D Random Walk Simulation: Statistical Physics & Stochastic Modeling

Dr. Alorika Chatterjee & Dr. Anirban Shaw Science & Physics Learners Python 3 / NumPy / SciPy

1. Core Principles & Theoretical Framework

Stochastic Processes: Simulates random physical phenomena including Brownian diffusion, radioactive decay, and thermal fluctuations.
Ensemble Averages: Computes macroscopic thermodynamic observables as statistical ensemble averages over microscopic configurations.
Monte Carlo Convergence: Statistical error scales inversely with the square root of trial count: $\sigma \propto 1/\sqrt{N}$.

2. Mathematical Formulation & Algorithmic Pipeline

Random walk diffusive spreading and Monte Carlo error scaling:

$$ \langle x(t) \rangle = 0, \quad \langle x^2(t) \rangle = 2 D t, \quad \text{Statistical Uncertainty: } \sigma_N = \frac{\sigma}{\sqrt{N}} $$

3. Numerical Mechanics & Implementation Logic

  • Random Number Seeding: Initialize pseudo-random generators with fixed seeds to ensure reproducible simulation results.
  • Ensemble Sampling: Execute $M$ independent trials of $N$ steps each to build accurate probability distributions.
  • Histogramming: Bin particle final positions to verify convergence toward Gaussian/Poisson distributions.

4. Relevant Computational Practice Exercises

Exercise 1
Simulate $M = 1000$ independent random walk trajectories and confirm that root-mean-square displacement scales as $\sqrt{t}$.
Exercise 2
Apply Monte Carlo integration to estimate $\pi$ using hit-or-miss circle sampling and plot error vs trial count $N$.
Exercise 3
Model radioactive nuclear decay for $N_0 = 10^4$ nuclei and compare against the continuous decay law $N(t) = N_0 e^{-\lambda t}$.
Standard Literature & References:
  • F. Reif, "Fundamentals of Statistical and Thermal Physics", Waveland Press (2009).
  • Mark Newman, "Computational Physics", University of Michigan (2013).