B115 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 NA and NB 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 NANA+NB: 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 10. 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?

Name it

Counting with logarithms

Multiplicities overflow floating point almost at once: (1000500) is about 10299, and a gram of anything is beyond any number a computer can hold. So compute ln⁡g instead, using math.lgamma(n + 1) for ln⁡n!, 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 Ω(N,q)=(q+N−1q) microstates. When two solids share q quanta, the chance of a split is ΩA(qA)ΩB(q−qA)ΩA+B(q). Its peak is where ∂ln⁡ΩA∂qA=∂ln⁡ΩB∂qB, equal temperatures. From Stirling's formula the width is about

σ2=[NAqA(qA+NA)+NBqB(qB+NB)]−1

at the most probable split.

A general partition function

For levels Ei with degeneracies gi, Z=∑igie−Ei/kT. Everything else follows: the probabilities pi=gie−Ei/kT/Z, the energy U=∑piEi, the entropy S=−k∑ipiln⁡pigi, and the heat capacity from the energy's variance, C=⟨E2⟩−⟨E⟩2kT2.

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 ∑pi=1 and ∑piEi=U must lower S, by about ε22∑di2pi for a small change εdi. This is another route to the Boltzmann factor, and the one information theory takes.

Worked example

Two Einstein solids, NA = 300 and NB = 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
  1. Most probable split. Computing all 101 splits exactly, the most probable is qA = 60, with probability 7.4%, and the mean is also 60.0.
  2. Width. The standard deviation is 5.36 quanta, and the Stirling estimate gives nearly the same: σ≈[30060×360+20040×240]−1/2=5.37
  3. B holds half or more. That means qA≤50, which has a chance of 3.9%.
  4. Check the counting. The total number of microstates is (599100)=9.26×10115 and the sum of all splits reproduces it, a check that the counting is right.

Answer the most probable split is qA = 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
  1. Partition function. kT = 25.85 meV, so Z=1+e−0.387+e−0.774=2.140
  2. Probabilities. They are 0.467, 0.317 and 0.216.
  3. Average energy. U=10×0.317+20×0.216=7.48meV
  4. Entropy. S=−k∑piln⁡pi=1.05k
  5. 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
  1. Still normalized. The change sums to zero, so the probabilities still add to 1.
  2. Energy change. It's zero, so U stays 7.48 meV: 0×1+10×(−2)+20×1=0
  3. New entropy. The new probabilities are 0.477, 0.297 and 0.226, and the entropy falls by 9.8×10−4k.
  4. Quadratic estimate. It agrees: ΔS≈ε22(10.467+40.317+10.216)=9.7×10−4
  5. 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 9.8×10−4k.

Check

Step 1. Write ln_multiplicity(N, n) returning ln⁡(Nn) with math.lgamma, and gaussian_check(N, s) returning the exact ratio g(N,s)/g(N,0) 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 qA = 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?

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.