B11 · Lesson 5 · Statistics lab
Multiplicities, energy sharing, partition functions and the maximum-entropy principle, computed in Python
Lessons 1 to 4 built thermal physics from counting: multiplicities, entropy as their logarithm, temperature from how entropy changes with energy, and the Boltzmann factor for a system in contact with a reservoir. Every one of those ideas can be checked by brute force on a computer, with numbers too large for a calculator. In this lab you'll count states exactly with log-gamma functions, watch two Einstein solids share energy, build a general partition-function calculator, find a Schottky peak numerically, and check that the Boltzmann distribution really is the one with the most entropy.
- Two Einstein solids with and oscillators share q quanta. The curve is the relative number of ways to give a fraction x of the quanta to A, from Stirling's formula for each solid's multiplicity.
- The peak sits at : energy divides in proportion to size, which is what equal temperatures mean here.
- Multiply all three sliders by ten and the peak narrows by about . Step 2 computes the same distribution exactly.
Predict
Two Einstein solids of 300 and 200 oscillators share 100 quanta. What's the chance that the smaller solid holds more than half of them?
About 4%. The most probable split gives the smaller solid 40 quanta, and the distribution's width is about 5.4 quanta, so 50 or more is nearly two standard deviations out: 3.9% exactly. With systems this small the fluctuations are easy to see; for a mole of oscillators the same question has a probability with an exponent in the trillions.
Name it
Counting with logarithms
Multiplicities overflow floating point almost at once: is about , and a gram of anything is beyond any number a computer can hold. So compute instead, using math.lgamma(n + 1) for , and subtract logarithms before exponentiating. Ratios of multiplicities, which are what probabilities need, come out exactly.
Two systems sharing energy
An Einstein solid of N oscillators holding q quanta has microstates. When two solids share q quanta, the chance of a split is . Its peak is where , equal temperatures. From Stirling's formula the width is about
at the most probable split.
A general partition function
For levels with degeneracies , . Everything else follows: the probabilities , the energy , the entropy , and the heat capacity from the energy's variance, .
Maximum entropy
Among all probability distributions over the states with a given average energy, the Boltzmann distribution has the largest entropy. So any change that keeps and must lower S, by about for a small change . This is another route to the Boltzmann factor, and the one information theory takes.
Worked example
Two Einstein solids, = 300 and = 200, share 100 quanta. Find the most probable split, its probability, the width of the distribution and the chance that B holds half or more.
Show the solution
- Most probable split. Computing all 101 splits exactly, the most probable is = 60, with probability 7.4%, and the mean is also 60.0.
- Width. The standard deviation is 5.36 quanta, and the Stirling estimate gives nearly the same:
- B holds half or more. That means , which has a chance of 3.9%.
- Check the counting. The total number of microstates is and the sum of all splits reproduces it, a check that the counting is right.
Answer the most probable split is = 60 (probability 7.4%), the standard deviation is 5.36 quanta, and B holds half or more 3.9% of the time.
Worked example
A system has levels at 0, 10 and 20 meV, one state each, at 300 K. Find Z, the probabilities, U and S.
Show the solution
- Partition function. kT = 25.85 meV, so
- Probabilities. They are 0.467, 0.317 and 0.216.
- Average energy.
- Entropy.
- Compare with equal weights. With three equally likely states it would be ln 3 = 1.10k; the Boltzmann weighting toward the ground state lowers it a little.
Answer Z = 2.140, the probabilities are 0.467, 0.317 and 0.216, U = 7.48 meV and S = 1.05k.
Worked example
Change the three-level distribution above by ε(1, −2, 1) with ε = 0.01. Does it still have the same energy? What happens to its entropy?
Show the solution
- Still normalized. The change sums to zero, so the probabilities still add to 1.
- Energy change. It's zero, so U stays 7.48 meV:
- New entropy. The new probabilities are 0.477, 0.297 and 0.226, and the entropy falls by .
- Quadratic estimate. It agrees:
- The other sign. ε = −0.01 lowers it by the same amount to first order: the Boltzmann distribution sits at the top of the entropy hill.
Answer the energy stays 7.48 meV, and the entropy falls by .
Check
Step 1. Write ln_multiplicity(N, n) returning with math.lgamma, and gaussian_check(N, s) returning the exact ratio for N spins with n = N/2 + s up.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 2. Write share(NA, NB, q) returning a list of the probabilities that solid A holds = 0, 1, …, q quanta when two Einstein solids share q quanta. Work with logarithms of the multiplicities.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 3. Write thermo(E, g, T) for levels E (meV) with degeneracies g at temperature T (K), returning (Z, U, S, C): the partition function, the energy in meV, and the entropy and heat capacity in units of k.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 4. Write schottky_peak(D) returning the temperature (K) at which a two-level system with splitting D (meV) has its largest heat capacity. Use a golden-section search in T.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 5. Write entropy_drop(E, T, eps) for three equally spaced levels E (meV) at T: perturb the Boltzmann probabilities by eps × (1, −2, 1), which keeps both their sum and the energy fixed, and return S(Boltzmann) − S(perturbed) in units of k.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Two Einstein solids with 100 and 200 oscillators share 500 quanta.
(a)
How many quanta does A most probably hold?
(b)
About how wide is the distribution (one standard deviation)?
Check
A system has levels at 0, 10 and 2 × 10 meV, one state each, at 100 K.
(a)
What's its partition function?
(b)
What's its average energy?
Write units the way you normally would: 1.5 meV, 1500 µeV and 0.0015 eV are the same answer.
Check
A sample holds 1 mol of two-level systems. What's the largest heat capacity they can have, at the Schottky peak?
Write units the way you normally would: 1.5 J/K, 1500 mJ/K and 0.0015 kJ/K are the same answer.
Check
By how much does N ln N − N fall short of ln N! for N = 1000, using the next term of Stirling's series?
Explain why
Why does the most probable split of energy between two large systems become, in practice, the only one you ever see?
The number of ways to make each split is a product of two huge multiplicities, and its logarithm is a sum of two entropies. Near the peak that logarithm falls off quadratically, so the distribution is a Gaussian whose width grows only as the square root of the system size, while the range of possible splits grows in proportion to the size. For 500 oscillators the width is several percent of the total, and fluctuations are easy to see; for particles the relative width is about , so every measurement finds the most probable split. That's why thermodynamic quantities like temperature and energy look perfectly definite for everyday objects.
Practice
Keep practicing
6 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.