Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Balls in a Box: Random Walk Simulation

A Monte Carlo simulation of particles undergoing random walks in a bounded 2D domain with elastic wall reflections.

Statistical Concepts

Random Walk (Brownian Motion Analogue)

Each particle moves at a fixed step length in a randomly assigned direction. The direction angle is drawn uniformly from [0, 2*pi). This discrete-time random walk approximates Brownian motion in the continuum limit: the displacement of each particle in each coordinate follows an approximately normal distribution over many steps (Central Limit Theorem).

Reflection at Boundaries

When a particle's position (plus a margin for its radius) exceeds the box limits [-L, L] x [-L, L], the angle is reflected:

  • Horizontal walls: angle -> -angle
  • Vertical walls: angle -> pi - angle

This implements elastic reflection and confines the random walk to a bounded domain.

Diffusion and Equilibrium Distribution

When particles all start from the origin (concentration = 0), we observe the diffusion process: the particle cloud expands outward. Over time, with wall reflections, the spatial distribution approaches a uniform equilibrium across the box -- a consequence of the ergodic theorem for reflected random walks.

Visualizations

Particle Snapshots at Different Time Steps

Starting from the origin, particles diffuse outward and eventually fill the box:

Random walk snapshots at different time steps

Statistical Properties of the Random Walk

Distribution of particle positions (x, y), distance from origin, and mean displacement over time:

Statistical properties of particle positions over time

Animated Simulations

Particles starting from random positions:

Random particles bouncing in a box

Random particles bouncing in a box (alternative)

Particles starting from the same point -- watch the diffusion process:

Particles diffusing from a common origin

First Bounce Sequence

Step-by-step view of 1000 particles at the first wall reflection:

Key Observations

  1. Diffusion rate: The mean distance from the origin grows proportionally to sqrt(t) in the early phase (before wall interactions dominate), consistent with the classical diffusion relation.
  2. Equilibrium: After sufficiently many steps, the spatial distribution becomes approximately uniform within the box, independent of starting configuration.
  3. Geometric patterns at boundaries: When the expanding particle cloud first hits a wall, interesting geometric patterns emerge from the simultaneous reflection of many particles.

Notebooks