Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 39 · Partition Functions and Thermodynamics

The Partition Function

Master the partition function Z: how to compute it, how it factorizes for independent systems, and how to extract the average energy, with a reusable Python function.

The partition function Z looks like a mere normalization constant, but it contains all the thermodynamics of a system. Once you can compute Z, every other quantity follows by differentiation. This is the central computational tool of statistical mechanics.

Definition

For a system in thermal equilibrium at temperature T with microstates s of energy E_s:

Text
Z = Σ_s e^(−β E_s),      β = 1/(k_B T)

If energy levels E_j have degeneracies g_j, sum over levels instead: Z = Σ_j g_j e^(−βE_j). For continuous classical systems the sum becomes an integral over phase space (chapter 5).

Z is dimensionless. You can think of it as the effective number of thermally accessible states: at T → 0 only the ground state counts, so Z → g_0, while at high T, Z grows to count many states.

Python A reusable partition-function toolkit

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Average energy from Z

Because ∂/∂β of e^(−βE_s) brings down −E_s:

Text
⟨E⟩ = −∂(ln Z)/∂β = k_B T² ∂(ln Z)/∂T

The second form follows from ∂β = −∂T/(k_B T²). Entropy and free energy come from ln Z as well; the next lesson shows how.

Python Average energy: direct sum against -d lnZ / d beta

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Independent subsystems multiply

If a system consists of two independent parts A and B, every microstate is a pair (s_A, s_B) with energy E_A + E_B:

Text
Z_AB = Σ_(s_A, s_B) e^(−β(E_A + E_B)) = Z_A Z_B

Therefore ln Z adds: ln Z_AB = ln Z_A + ln Z_B, and so do energy, entropy and free energy. For N identical, distinguishable and independent particles (for instance atoms fixed at lattice sites):

Text
Z_N = (Z_1)^N

For N identical, indistinguishable particles that are free to move (a gas), the same product overcounts: swapping identical particles does not make a new microstate. In the dilute classical limit one divides by N!:

Text
Z_N ≈ (Z_1)^N / N!

This 1/N! matters for entropy and was historically linked to the Gibbs paradox. Chapter 5 uses it.

Python Z factorizes for independent systems

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Shifting the zero of energy

Adding a constant E_0 to every energy changes Z to e^(−βE_0) Z and shifts ⟨E⟩ by E_0, but changes no probabilities and no heat capacity. Only energy differences matter physically. A practical consequence: when computing numerically, subtract the lowest energy first to avoid underflow in exp.

The meaning of ln Z

Since Z counts effectively accessible states, ln Z plays the role of an entropy-like quantity. We will see that F = −k_B T ln Z: the free energy is minus k_B T times the logarithm of the number of accessible states. This is the bridge between the microscopic list of energies and thermodynamics.

When a problem asks for thermodynamic properties of a model, a good workflow is: (1) list the states and their energies; (2) compute Z; (3) differentiate ln Z. Steps 1 and 2 hold all the physics.

Python Population and heat capacity of a four-level system

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. A system has two levels, energies 0 and 2 eV with no degeneracy. As T approaches 0, Z approaches:

    At T -> 0 only the ground state contributes: Z -> g_0 = 1.
  2. 2. If A and B are independent systems, Z_AB equals:

    Z multiplies for independent systems, so ln Z adds.
  3. 3. For N identical, indistinguishable, free particles in the dilute classical limit, Z_N is approximately:

    Dividing by N! corrects the overcounting of identical particles.
  4. 4. What happens to the average energy if you add a constant E_0 to every energy level?

    Probabilities are unchanged but every energy shifts by E_0, so the average shifts by E_0. Differences (and heat capacity) are unaffected.

Summary

  • Z = Σ_s e^(−βE_s) (or Σ_j g_j e^(−βE_j)); it counts effectively accessible states.
  • ⟨E⟩ = −∂ln Z/∂β and σ_E² = ∂²ln Z/∂β².
  • Z multiplies for independent systems; Z_N = Z_1^N (distinguishable) or Z_1^N/N! (indistinguishable, dilute).
  • Only energy differences matter; shift the zero for numerical safety.

Next: Helmholtz Free Energy