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}$$
TTemperature (Kelvin)
ETotal kinetic energy (Joules)
NNumber of particles
k_BBoltzmann'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:
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}$$
nNumber of available microstates (based on chamber area)
kTotal particles in chamber
bBlue 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_BBoltzmann's constant
TTemperature 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:
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: