What is live
The pressure gauge reads the walls, not a formula
Live particle motion, wall hits, pressure, temperature, the histogram
Every particle's position and velocity is advanced on this device many times per frame. When one reaches a
wall it bounces, and the momentum it hands over is added to that wall's tally. The pressure gauge is that
tally, per second, per unit of wall length. Temperature is computed from the particles' kinetic energy.
Nothing is looked up and nothing about the gas law is built in.
Scripted the box, the starting gas and the guided experiment
A 100 × 60 box, 240 particles at a temperature of 300 and a particle radius of 0.35 are chosen teaching
values. The guided experiment is a fixed routine: measure for four seconds of simulated time, double N,
wait a moment, measure again.
Reasoned the ± band under the pressure reading
A gauge on a few hundred particles is noisy: the band is the reading divided by the square root of the
number of wall hits counted, a rough rule of thumb for a random count, not a confidence interval. More
particles, more time, or a smaller box all steady it.
How it works
P = (momentum handed to the walls) ÷ (time × total wall length)
A particle of mass 1 moving at speed v⊥ toward a wall leaves with the same speed the other
way, so the wall receives momentum 2v⊥. Add every such hit over a stretch of time,
divide by that time and by the length of wall, and you have a pressure. Doubling the number of particles
doubles the number of hits per second while leaving each hit the same, so the pressure doubles.
Assumptions and simplifications
- Two dimensions. The box is flat, so "pressure" is force per unit length of wall and "volume"
is area. Every relationship the stages find holds in 3D too; only the constants change.
- Reduced units. Every particle has mass 1 and Boltzmann's constant is 1, so temperature is half the
mean squared speed and the gas law reads P·A = N·T with no constant in it. The default
temperature of 300 is chosen to look like room temperature in kelvin; it is not kelvin.
- Perfectly elastic walls at rest (the piston aside), which hand back exactly the speed they receive.
- A finite, noisy gauge. Real gases have ~1023 particles and a gauge that averages over
all of them; this box has a few hundred, so the reading wanders. The running average smooths about one
second of simulated time.
- The animation runs at 2× simulated time by default, adjustable from the Speed switch, so that
an experiment finishes in a few seconds.
Sources
Boundary: this is an idealized two-dimensional teaching model built to make one
mechanism visible. It does not reproduce any real gas's numbers, and its temperature and pressure scales are
the model's own.
What is live
The same gauge, with temperature as the variable
Live the temperature readout, the histogram and the pressure
The temperature shown is computed every frame from the particles' actual kinetic energy. The guided
experiment rescales every velocity by √2 in one step so the gas is at 600 at once, then measures the
walls. The histogram's bars are the particles now; its curve is the 2D Maxwell distribution for the
measured temperature, drawn for comparison.
Scripted the thermostat
The thermostat nudges every speed a little toward the target each step, like a water bath the box is
sitting in. It changes only the width of the speed distribution. It is a modelling device, not a claim
about any particular apparatus.
How it works
T = ½⟨v²⟩ so vrms = √(2T)
Doubling T multiplies typical speeds by √2. A particle moving √2 times faster hands the wall
√2 times the momentum per hit, and comes back to hit it √2 times as often. The product is 2:
pressure is proportional to temperature at fixed N and A.
Assumptions and simplifications
- Temperature is defined by kinetic energy alone. These particles have no rotation, no vibration, no
internal structure — two degrees of freedom each and nothing else.
- The velocity distribution is Maxwellian at the start and stays so, because the thermostat rescales
uniformly and disc collisions keep it thermalized. Switch collisions off and start all particles at one
speed to see a distribution that is not Maxwellian.
- Every simplification from stage 1 still applies — two dimensions, reduced units, elastic walls,
a noisy finite gauge.
Sources
- OpenStax
Chemistry 2e, §9.5 — average kinetic energy proportional to temperature; the
Maxwell–Boltzmann distribution and how it widens with temperature.
- The 2D speed density drawn on the histogram, f(v) = (v/T)·e−v²/2T,
is the two-dimensional case of that distribution with m = kB = 1; it is computed
in this page's model and checked there to integrate to 1, not quoted from a table.
Boundary: the claim is that pressure tracks temperature for a gas of
structureless particles. Real molecules store energy in rotation and vibration too, which changes heat
capacities but not this proportionality.
What is live
A moving wall, and what it does with the thermostat off
Live the piston, the pressure and the temperature
The piston slides at a fixed 12 units per second toward wherever the slider is set. A particle that bounces
off a wall moving at speed u leaves with its normal speed changed by 2u: a wall moving inward
speeds it up. That is the entire mechanism by which compressing a gas heats it, and this page computes it
for every bounce rather than assuming it.
Scripted the guided experiment holds the thermostat on
The routine measures, slides the piston from width 100 to 50, waits for it to arrive and for the gas to
settle, and measures again — with the thermostat holding T at 300 throughout, so that the only thing that
changed is the room. Switching the thermostat off is left to you, on purpose.
How it works
P·A = constant (fixed N and T)
With the same speeds and half the width, a particle crossing the box reaches the piston and the left wall
twice as often. The top and bottom walls are shorter, so they are hit as often per unit length as before but
there is less of them. Add it up and the total momentum per second per unit of wall doubles. This is
Boyle's law, arrived at by counting.
With the thermostat off, the inward-moving piston hands energy to every particle it meets, so T rises and the
pressure rises by more than the room alone would give. That is adiabatic compression — the reason a bicycle
pump gets warm.
Assumptions and simplifications
- The piston moves at one fixed speed, which is a sizeable fraction of the particles' own speeds.
The compression is therefore not slow and gentle, and with the thermostat off it heats the gas more than
a slow one would. The direction of the effect is right; its size depends on the piston speed.
- The thermostat is idealized — it removes energy at a fixed rate everywhere at once. A real
water bath conducts heat through the walls with a lag.
- Every simplification from stages 1 and 2 still applies.
Sources
- OpenStax
University Physics Volume 2, §2.2 — pressure from wall collisions, from which Boyle's law
follows at fixed temperature.
- The moving-wall reflection rule, v′ = −v + 2u, is an exact consequence of
an elastic bounce seen from the wall's own frame; it is coded in this page's model, not quoted.
Boundary: this stage shows why pressure and area trade off at fixed
temperature, and why compression heats a gas that is not held cold. It reports no real gas's compressibility
and no real pump's temperature rise.
What is live, and what is estimated
The sweeps are measured; the size correction is a first-order estimate
Live every sweep point and every ratio
Each sweep steps one of N, T or A through five values. At every step the gas settles for a moment and the
walls are measured for three seconds of simulated time; the point plotted is that measurement against
N·T / A for the same step. The ratio Z = P·A / (N·T) is measured, not
fitted.
Reasonedfirst-order estimate, overstates the effect at higher packing the "expected drift" for big particles
Two particles of radius r cannot bring their centres closer than 2r, so each pair excludes a
disc of area 4πr²; sharing that between the two gives about 2πr² of lost room
per particle. With N·2πr² of the box unavailable, P ≈ N·T / (A −
N·2πr²), so Z ≈ 1 / (1 − 2η) where η is the fraction of the
box the particles cover. That is the authors' leading-order estimate from the geometry, offered for
direction and rough size. It is not a fitted equation of state.
How it works
Z = P·A ÷ (N·T) — 1 when the law holds
The ideal gas law assumes particles occupy no space and never interact except at the walls. Small particles
with collisions on come close to that: Z sits within a few percent of 1. Grow them and the room they leave
each other shrinks, so the walls are hit more often than the law expects and Z climbs. This is the
correction a real-gas equation such as van der Waals makes with its b term. There is no attraction
between these particles, so the other van der Waals correction, which lowers pressure, does not appear here.
Assumptions and simplifications
- Hard discs, no attraction. Real molecules attract each other weakly at a distance, which pulls Z
below 1 at low temperature. This model has only the repulsive core, so it shows one of the two real-gas
corrections.
- Even the "small" default is not zero. At radius 0.35 the particles cover about 1.5% of the box,
and Z runs a few percent above 1 for that reason. The demo's "the law holds" is "to within a few percent
plus noise", and the gauge shows the number.
- Sweeps are short. Three simulated seconds per point keeps a sweep to about fifteen real seconds,
at the cost of a few percent of scatter on each point.
- Every simplification from stages 1 to 3 still applies.
Sources
- OpenStax
Chemistry 2e, §9.6 Non-Ideal Gas Behavior — the compressibility factor Z, why molecular
volume raises it above 1, and the van der Waals b term this stage's drift corresponds to.
- The excluded-area estimate above is the authors' own derivation from the disc geometry, as labelled; it is
not taken from a source.
Boundary: the claim is that the ideal gas law holds for tiny non-interacting
particles and drifts, in a predictable direction, when they take up room. This page does not measure any
real gas's compressibility, and its size correction is an estimate of direction and magnitude, not a fitted
law.