Particles in a Box

A gas is many small things bouncing around. From that one picture, three quantities fall out: temperature, pressure, entropy. Each gets its own demo.

Temperature

Temperature is the average kinetic energy of the particles. Below, every particle starts with the same speed but a random direction. They collide elastically — energy and momentum conserved on every hit — and within a few seconds the speeds spread out into a curve. That curve is the Maxwell–Boltzmann distribution: the equilibrium signature of a gas at a single temperature. The faster a particle, the redder; the slower, the bluer. Heat the gas (give every velocity a kick) or cool it (shrink them) and watch the distribution slide.

In two dimensions and natural units (mass = 1, kBk_B = 1), the average kinetic energy is the temperature: 12v2=T\langle \tfrac12 v^2 \rangle = T. So the readout under the histogram is both at once.

speed → T = 1 ⟨KE⟩ = 0

The point is the universality: regardless of how you initialise the speeds, collisions drag the population toward this same shape. T is the one number that survives.

Pressure

Pressure is the rate at which particles deliver momentum to the walls, per unit length of wall. Each elastic bounce off a wall transfers 2mv2m|v_\perp| of momentum; sum that over a rolling time window and divide by the perimeter and the window size, and you have P.

The slider shrinks the box. The temperature stays the same (no energy goes in or out — the moving wall is only a clamp here, not a piston), but the wall area shrinks while the same number of bounces happen more often per unit length. So P rises. The combination PV/N should sit near T — that’s the 2D ideal-gas law, PV=NkBTPV = Nk_BT, written in the same natural units.

P ≈ 0.0V = 0T ≈ 0PV/N ≈ 0

Drag the slider. Watch P climb as V falls, while T and PV/N stay near constant.

Entropy

Entropy is a count of how many ways the particles can arrange themselves consistent with what you can observe macroscopically. The cheapest version: divide the box into a grid of cells, count occupants per cell, and compute the Shannon entropy H=ipilnpiH = -\sum_i p_i \ln p_i where pip_i is the fraction of particles in cell i. Maximum entropy is lnM\ln M where M is the total number of cells: every cell equally populated, no information about which one any particle is in.

The classical demonstration is free expansion. Start every particle confined to the left half of the box (a partition runs down the middle). Press remove partition. The gas spreads out to fill the whole box, and H climbs from ln(M/2)\ln(M/2) to lnM\ln M. The curve is monotonic on average and saturates: this is the second law in one picture.

H_max = log(32) = 3.47H(t) → H = 0.00 H/H_max = 0.00

Reset and run it again. You will never see the gas un-mix — re-collect itself in the left half — even though every collision in the simulation is time-reversible. The arrow of time here is purely statistical: the macrostate “all in left half” corresponds to vastly fewer microstates than “spread out evenly,” and a random walk through microstate space almost certainly leaves the rare ones for the common ones.

Putting it together

  • Temperature is the average kinetic energy per particle. It is the one number conserved when particles collide with each other.
  • Pressure is the average momentum delivered to the walls per unit length per unit time. Compress the box at fixed T and P must rise.
  • Entropy is the log of how many microstates are consistent with the macrostate. It rises in any spontaneous process and saturates at equilibrium.

These three are all the same gas, watched through three different magnifying glasses.