← Back to Simulation

Maxwell's Demon Physics

Mathematical foundation of the thermodynamic simulation

1. Kinetic Energy

Definition

The kinetic energy of a particle is the energy it possesses due to its motion. In classical mechanics:

$$E = \frac{1}{2}mv^2$$

For our simulation with N particles:

$$E_{total} = \sum_{i=1}^{N} \frac{1}{2}m_i v_i^2$$
E Kinetic energy (Joules)
m Mass of particle (kg)
v Velocity magnitude (m/s)
N Total number of particles

Note: Energy is conserved in elastic collisions between particles. In the simulation, we convert pixel-based velocities to m/s using: $v_{m/s} = v_{pixels/frame} \times 0.01$

2. Temperature from Equipartition Theorem

Equipartition Theorem

For a system in thermal equilibrium, the average kinetic energy is distributed equally among all quadratic degrees of freedom. For 2D motion (x and y components), there are 3 degrees of freedom:

$$E = \frac{3}{2}Nk_BT$$

Solving for temperature:

$$T = \frac{2E}{3Nk_B}$$
T Temperature (Kelvin)
E Total kinetic energy (Joules)
N Number of particles
k_B Boltzmann's constant = 1.380649 × 10⁻²³ J/K
Chamber-specific temperatures: Each chamber's temperature is calculated using only the particles and energy in that chamber, allowing us to observe temperature gradients.

3. Combinatorial Entropy

The Multiplicity Function

Entropy quantifies the number of microstates (microscopic configurations) corresponding to a macroscopic state. The total entropy has two components:

Spatial Entropy

Distribution of particles across available positions within a chamber:

$$S_{spatial} = n\ln\left(\frac{n}{n-k}\right) + k\ln\left(\frac{n-k}{k-b}\right) + b\ln\left(\frac{k-b}{b}\right)$$

Combinatorial Entropy (Color Distinguishability)

The entropy from distinguishing between blue and red particles. Using Stirling's approximation:

$$S_{color} = \ln\left(\frac{k!}{b!(k-b)!}\right) \approx k\ln(k) - k - b\ln(b) + b - (k-b)\ln(k-b) + (k-b)$$

Total System Entropy

Sum of entropy from both chambers:

$$S_{total} = S_{left} + S_{right}$$
n Number of available microstates (based on chamber area)
k Total particles in chamber
b Blue particles in chamber
Maximum entropy: Occurs when colors are equally mixed (b ≈ k/2), creating the characteristic sharp peak in the multiplicity curve.

4. Landauer's Principle & Information Cost

The Physical Cost of Measurement

Landauer's Principle states that erasing one bit of information has a minimum thermodynamic cost. In the context of Maxwell's Demon:

$$\Delta S_{min} = k_B T \ln(2)$$

In our simulation: Every time a particle hits the door area, the demon must measure its properties (blue or red, moving left or right). This measurement costs entropy:

$$\Delta S_{demon} = k_B T \ln(2) \approx 0.693 \text{ entropy units per measurement}$$
k_B Boltzmann's constant
T Temperature of the system
ln(2) Natural log of 2 ≈ 0.693
Key observation: The demon's entropy budget increases by 0.693 units each time a particle approaches the door. This represents the physical cost of gathering information about the particle.

5. Szilard Engine - Managing the Budget

Budget Constraint

The demon starts with a limited entropy budget (500 units in our simulation). As measurements accumulate, the entropy cost grows:

$$S_{demon, total} = \sum_{i=1}^{n} k_B T \ln(2)$$

When the demon's accumulated entropy reaches 500, the demon can no longer operate (second law of thermodynamics becomes enforceable).

Key insight: The demon cannot violate the second law because the cost of measurement (entropy increase) exactly offsets any entropy decrease in the system.

6. Perfect Demon Mode

Theoretical Ideal

In Perfect Demon mode, particles are instantly sorted according to their type, achieving maximum entropy reduction:

$$S_{sorted} = 0 \text{ (minimum entropy)}$$

However, this mode still tracks the entropy cost as if measurements were being made, demonstrating why such perfect sorting is thermodynamically impossible in reality.

Educational use: Compare the perfect demon's entropy cost against the actual demon's performance to see how constraints of the second law manifest.

7. Collision Physics

Elastic Collisions

All particle collisions are perfectly elastic, conserving both momentum and kinetic energy:

$$\vec{p}_{before} = \vec{p}_{after}$$ $$E_{before} = E_{after}$$

Collision Detection

Particles collide when the distance between centers is less than the sum of their radii:

$$d = |\vec{r}_1 - \vec{r}_2| < r_1 + r_2$$

Wall and Door Handling

Particles bounce elastically off chamber walls. When the door is open, particles can pass through if they're in the correct door region. The door detection uses position tracking to prevent tunneling:

$$\text{Door open} \iff y \in [doorTop, doorBottom] \text{ AND } door_{state} = OPEN$$

8. The Second Law of Thermodynamics

Entropy Always Increases (Or Stays Constant)

For an isolated system, total entropy never decreases:

$$\Delta S_{universe} = \Delta S_{system} + \Delta S_{surroundings} \geq 0$$

Why Maxwell's Demon Fails

In our simulation:

  1. System entropy decreases: Particles get sorted, reducing entropy
  2. Demon entropy increases: Every measurement at the door costs kT ln(2) in entropy (Landauer's Principle)
  3. Total entropy stays constant: The increase in demon entropy equals the decrease in system entropy
$$\Delta S_{total} = \Delta S_{system} + \Delta S_{demon} = 0 \text{ (or positive)}$$
Takeaway: The demon doesn't violate the second law—it highlights its fundamental nature. Information has thermodynamic cost.