The Ideal Gas Law: Simulated

In school, we learn that PV = nRT. It's kind of cool: we get a function for pressure as being proportional to number of moles, n, multiplied by temperature T, and divided by volume V. Explicitly, P = c \cdot \tfrac{nT}{V}, where c happens to be the constant 8.314 \tfrac{\text{J}}{\text{K} \cdot \text{mol}} in the real world, which we call R. This equation is justified by imagining the force exerted by a particle on the walls of an enclosing chamber, as I'll show in this article.

Let's start with an example. Suppose we had a single particle weighing 1 \text{kg} (humor me) in a 1 \text{m} \times 1 \text{m} \times 1 \text{m} box, moving 1 \tfrac{\text{m}}{\text{s}} straight up, we could easily calculate the force it exerts on the outer wall. Assuming elastic collisions, the particle has a change in impulse with the wall of 2 \tfrac{\text{m}}{\text{s}} \cdot \text{kg} every second.

We'll have to use our imagination here for a second, and make the assumption that it's safe to take the average of this change in impulse over time - instead of thinking of a change in impulse with the wall of 2 \tfrac{\text{m}}{\text{s}} \cdot \text{kg} that happens once a second, we'll think of a continuous force of 2 \tfrac{\text{kg-m}}{\text{s}^2}. Indeed, as the number of particles increases, the force against the walls will will approach this constant hammering of pressure, as opposed to the occasional collision with the wall we're starting with. So, we'll take the assumed to be continuous force generated by our single massive particle and divide by the area of the box, 6 \text{m}^2, to see that we have pressure P = \tfrac{2 \text{kg}}{ 6\text{m}\text{s}^2} = \tfrac{1}{3} \text{Pa} (note that Pa is short for Pascals, where 1 \text{Pa} = 1 \tfrac{\text{N}}{\text{m}}). And if we had two particles, we would have two-thirds of a pascal of pressure - it's fairly easy to see that assuming particles have no interaction, the force exerted on the wall is directly proportional to the number of particles! Verify for yourself below:

It does get a little more interesting when we consider particles moving at different speeds. If our particle were moving at 2 \tfrac{\text{m}}{\text{s}}, we would actually observe a pressure of 8 \text{Pa}, since each collision would impart an impulse of 4 \tfrac{\text{kg-m}}{\text{s}}, and these collisions would occur twice as frequently. More generally, we find that pressure is proportional to velocity squared. Interestingly, temperature is also defined to be proportional to particle velocity squared, giving us a direct explanation for why pressure scales with temperature.

However, things start to break down when we attempt to understand why pressure is inversely proportional to volume. Suppose our particle is traveling straight upward. If we shrink the volume by reducing the width of our container, the ideal gas law suggests that pressure should approach infinity—but in our simulation, it doesn't. Clearly, something is missing. The key is that real particles do not travel in perfectly straight lines; they move in entirely random directions. This means they also have horizontal motion. To better illustrate this, let’s examine the system in two dimensions, as that’s how our simulation is built. In 2D, pressure is measured as force per unit length rather than Pascals, and volume is replaced with area. Specifically, our pressure is now expressed in \tfrac{\text{N}}{\text{m}} rather than Pascals. Experiment with the effect of random motion on the simulation below:

Assuming a particle starts with a speed v and \theta as the angle that the particle's path makes with the horizontal, we can still fairly easily compute the expected collisions per second. The horizontal speed of the particle is v \cdot \cos{\theta}, and with w and h for width and height, \tfrac{v \cdot \cos{\theta}}{w} is the number of collisions-per-second against vertical walls. Likewise, \tfrac{v \cdot \sin{\theta}}{h} is the number of collisisons-per-second on the horizontal walls. Note that collisions against vertical walls now have 2v \cdot \cos{\theta} \text{Ns} worth of impulse, and likewise collisions on horizontal walls have 2v \cdot \sin{\theta} \text{Ns} worth of impulse. In total, our expected impulse per second (better thought of as time-averaged force on the container) will be

\tfrac{v \cdot \cos{\theta}}{w} \text{s}^{-1} \cdot (2v \cdot \cos{\theta}) \text{Ns} + \tfrac{v \cdot \sin{\theta}}{h} \text{s}^{-1} 2v \cdot \sin{\theta} \text{Ns} = 2v^2 \left( \tfrac{\cos^2{\theta}}{w} + \tfrac{\sin^2{\theta}}{h} \right) \text{N}

Yay! We have a huge equation... Dividing the area over which our force is exerted to get our 2D version of pressure, we have P = v^2 \left( \tfrac{\cos^2{\theta}}{w(w + h)} + \tfrac{\sin^2{\theta}}{h(w + h)} \right) \text{N/m}. Although it's briefly troubling that we don't have a nice wh in the denominator, we can resolve it by recalling that we don't care about a single particle - we care about what particles will do on expectation. With our expected values for \theta spread evenly across all angles, we can skip a bit of calculus to conclude that \cos^2{\theta} is on average 1/2, and likewise for \sin^2{\theta}. If we go ahead and plug those expected values in, everything cancels nicely to reveal

P = \tfrac{v^2}{2wh} \ \text{N/m}.

Hurrah, we finally have the inverse-area relationship we've been after. Check out the sim below to see for yourself.

Now that we've finally shown the inverse-area relationship, we can combine our proportionality rules into a single equation: P = c \cdot \tfrac{nT}{A}. Seems pretty familiar... Play around with the simulation and see if you can figure out what c is for this simulation.