Member-only story

An Ideal Gas Is Just a Bunch of Balls. Here’s How to Model it in Python

Rhett Allain
10 min readDec 11, 2023

--

Screenshot from Web VPython

The Ideal Gas Law. It’s covered in pretty much every middle school physical science class. It gives a relationship between pressure (P), temperature (T), volume (V) and amount of a gas (n). There are actually two versions of this model. Here’s the way chemists like to write it.

In SI units, R has a value of 8.314 J/K*mol. Physicists like to write it as:

The difference is that N is the number of particles in the gas and k is the Boltzman constant (1.38 x 10^-23 J/K).

Chemists like to think of a gas as a continuous fluid and physicists want to think of it as a bunch of discrete particles. Of course, in most situations it’s easier to think of the gas as just one thing — but it’s fun to treat it as a bunch of particles. So that’s what we are going to do.

Don’t worry, I’m going to go over ALL the details of how to do this in python (Web VPython actually).

A Single Particle in a Sphere

The general plan is to put a bunch of balls inside of a container and let them bounce around. That means that we need some type of container so that the gas-balls interact with a wall when they collide. I’m going to use a spherical container since it only has one wall to deal with (where a cube would…

--

--

Rhett Allain
Rhett Allain

Written by Rhett Allain

Physics faculty, science blogger of all things geek. Technical Consultant for CBS MacGyver and MythBusters. WIRED blogger.

No responses yet