See also: Course-wide Conventions & Notation
Run the code: Notebook for Section 2.3, in which you can change and rerun the Python cells of this section in your browser.
Overview and Learning Objectives¶
Once microstate probabilities are known, thermodynamic properties follow as ensemble averages. This section derives canonical expressions for internal energy, heat capacity, and pressure in terms of derivatives of . A recurring theme is that fluctuations are not a nuisance—they encode response functions such as . A response function measures how strongly a property of the system changes when a controlled variable changes; is the response of to a change in .
Section 2.1 emphasized that macroscopic properties are expectation values of microscopic properties, with the expectation taken over the microstate probabilities. Section 2.2 derived the canonical probability distribution for a closed system’s microstates. Here, we connect these results by computing ensemble averages that determine macroscopic properties.
Learning objectives:
Compute internal energy both as an ensemble average, , and as a derivative, .
Relate heat capacity to energy fluctuations via .
Compute pressure from the partition function using (when applicable).
Apply these formulas to simple discrete models (e.g., a two-state system).
Core Ideas and Derivations¶
Thermodynamic Equilibrium¶
Recall from Section 1.1 that thermodynamic equilibrium is a state of simultaneous mechanical, thermal, and chemical equilibrium. Below are working definitions of each type of equilibrium:
- Thermal contact
- A state in which two systems can exchange energy.
- Chemical contact
- A state in which two systems can exchange matter.
- Mechanical equilibrium
- A state in which there are no unbalanced forces. Across a movable boundary, the pressure of the system equals that of its surroundings.
- Thermal equilibrium
- A state in which there is no net exchange of energy between systems in thermal contact.
- Chemical equilibrium
- A state in which there is no net exchange of matter between systems in chemical contact.
Internal Energy¶
The internal energy of a macroscopic system at thermodynamic equilibrium is defined as the ensemble average of the microstate energy :
where is the energy of microstate , is the probability of that microstate, and is the total number of microstates.
For the canonical ensemble, using the Boltzmann factor and the partition function , we have
where and
Why can we factor out ?
At fixed , , and (equivalently fixed ), does not depend on the microstate index . Therefore, it is constant with respect to the summation over and can be pulled outside the sum.
Partial Derivative of the Partition Function¶
Taking the partial derivative of with respect to gives
Substituting this result into the expression for yields
Where does the natural log come in?
Using the chain rule,
Example: Two-State System¶
For a two-state system with energies and , the partition function is
Then the internal energy is
which is the ensemble average .
Consistency Check
Using ,
Figure 2.3.1 shows , measured from , as a function of temperature for an energy gap of , together with the heat capacity at constant volume, which the next subsection defines.
Source
import sys
import matplotlib.pyplot as plt
import numpy as np
from scipy.constants import eV, k
sys.path.append("..") # the book folder, which holds figstyle
import figstyle as fs
k_B = k / eV # Boltzmann constant in eV/K
E1, E2 = 0.0, 0.01 # energies of the two states in eV
T = np.linspace(1, 1000, 1000) # K
beta = 1 / (k_B * T) # 1/eV
# Internal energy U = -d(ln Q)/d(beta), which is the average of the two energies weighted by their probabilities
Q = np.exp(-beta * E1) + np.exp(-beta * E2)
U = (E1 * np.exp(-beta * E1) + E2 * np.exp(-beta * E2)) / Q
# Heat capacity in units of k_B: C_V / k_B = x^2 e^(-x) / (1 + e^(-x))^2, with x = (E2 - E1) / (k_B T)
x = (E2 - E1) * beta
C_V = x**2 * np.exp(-x) / (1 + np.exp(-x))**2
def draw(c):
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(fs.WIDTH, 3.0), constrained_layout=True)
half_gap = 1e3 * (E2 - E1) / 2 # meV
ax1.axhline(half_gap, color=c.muted, lw=1.2, ls=(0, (4, 3)))
ax1.text(1000, half_gap + 0.15, "$(E_2 - E_1)/2$", color=c.muted, ha="right", va="bottom")
ax1.plot(T, 1e3 * (U - E1), color=c.ink)
ax1.set(xlabel="Temperature $T$ (K)", ylabel=r"$U_{\mathrm{two\text{-}state}} - E_1$ (meV)", xlim=(0, 1000),
ylim=(0, 6))
fs.panel(ax1, "a", "Internal energy")
ax2.plot(T, C_V, color=c.ink)
ax2.set(xlabel="Temperature $T$ (K)", ylabel=r"$C_V / k_{\mathrm{B}}$", xlim=(0, 1000), ylim=(0, 0.5))
fs.panel(ax2, "b", "Heat capacity")
return fig
fs.show(draw, alt="Two panels against temperature from 0 to 1000 K for a two-state system with an energy gap of 0.01 "
"eV. Panel a: the internal energy measured from the lower energy starts at 0, rises steeply up to "
"about 200 K, and then approaches a dashed line at half the gap, 5 meV, reaching about 4.7 meV at "
"1000 K. Panel b: the heat capacity divided by the Boltzmann constant starts at 0, rises to a "
"maximum of about 0.44 near 50 K, and then decreases toward 0 at high temperature.")Figure 2.3.1:Two-state system with an energy gap () as a function of temperature. (a) Internal energy measured from . The dashed line is its high-temperature limit, . (b) Heat capacity at constant volume in units of .
Heat Capacity at Constant Volume¶
From Section 1.1, heat is energy transferred due to a temperature difference. The heat capacity at constant volume, , measures how much heat is required to change a system’s temperature at fixed and :
Panel (b) of Figure 2.3.1 shows for the two-state system.
Heat Capacity and Energy Fluctuations¶
In the canonical ensemble, the energy of the system is not fixed, because the system exchanges energy with the heat bath (Section 2.2); the internal energy is its average. In statistics, the variance of a random variable is . In statistical mechanics, quantifies fluctuations in the total energy:
where . One can show that
which implies
What does the relationship mean physically?
Consider two systems in contact with heat baths at the same temperature , one with a larger than the other. Use the relationship above to compare their energy fluctuations .
Complete Derivation of the and Relationship
Fluctuations and System Size¶
How large are these fluctuations? For independent particles, both , measured from the lowest energy of the system, and are proportional to the number of particles . The standard deviation is then proportional to , so the width of the energy distribution relative to its mean falls as
Figure 2.3.2 shows this for independent two-state particles with and . Each particle is in state 2 with probability , so the number of particles in state 2 follows the binomial distribution, and
The energy of 10 particles is spread over a wide range around . For one mole of particles, is about 10-12. The energy of a macroscopic system in contact with a heat bath never stops fluctuating, but the fluctuations are far too small to measure, and this is why thermodynamics can speak of the internal energy of the system.
Source
from scipy.constants import N_A
from scipy.stats import binom
epsilon = 0.01 # energy of state 2 in eV; state 1 has the energy 0
T_room = 300 # K
x_room = epsilon / (k_B * T_room)
p2 = np.exp(-x_room) / (1 + np.exp(-x_room)) # probability of state 2
p1 = 1 - p2
sizes = [10, 100, 1000] # numbers of particles in panel (a)
def relative_width(N):
"""sigma_E / U for N independent two-state particles."""
return np.sqrt(p1 / (N * p2))
def draw(c):
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(fs.WIDTH, 3.1), constrained_layout=True,
gridspec_kw={"width_ratios": [1.25, 1]})
colors = [c.blue, c.vermilion, c.green]
# (a) The energy is E = n * epsilon, where n, the number of particles in state 2, is binomial.
for N, color in zip(sizes, colors):
n = np.arange(N + 1)
step = 1e3 * epsilon / N # spacing of the values of E/N in meV
density = binom.pmf(n, N, p2) / step # probability per meV of E/N
edges = (np.arange(N + 2) - 0.5) * step
ax1.stairs(density, edges, color=color, lw=1.6, fill=False)
ax1.stairs(density, edges, color=c.tint(color, 0.8), fill=True, zorder=0)
ax1.axvline(1e3 * epsilon * p2, color=c.muted, lw=1.2, ls=(0, (4, 3)), zorder=1)
ax1.text(1e3 * epsilon * p2 + 0.15, 2.72, "$U/N$", color=c.muted, ha="left", va="top")
ax1.text(7.3, 0.36, "$N = 10$", color=colors[0], ha="left", va="center")
ax1.text(5.35, 0.95, "$N = 100$", color=colors[1], ha="left", va="center")
ax1.text(4.75, 2.2, "$N = 1000$", color=colors[2], ha="left", va="center")
ax1.set(xlabel="Energy per particle $E/N$ (meV)", ylabel="Probability per meV of $E/N$", xlim=(0, 10),
ylim=(0, 2.8))
fs.panel(ax1, "a", "Distribution of the energy")
# (b) sigma_E / U = sqrt(p1 / (N p2)), a straight line of slope -1/2 on logarithmic axes
N_line = np.logspace(0, 24, 200)
ax2.plot(N_line, relative_width(N_line), color=c.ink, lw=1.6)
for N, color in zip(sizes, colors):
ax2.plot(N, relative_width(N), "o", color=color, ms=6.5, zorder=3)
ax2.plot(N_A, relative_width(N_A), "o", mfc=c.ground, mec=c.ink, mew=1.6, ms=6.5, zorder=3)
ax2.annotate("1 mol", (N_A, relative_width(N_A)), xytext=(-9, -4), textcoords="offset points", ha="right",
va="top", color=c.ink)
ax2.text(1e9, 6e-4, r"$\sigma_E/U \propto 1/\sqrt{N}$", color=c.ink, ha="left", va="bottom")
ax2.set(xscale="log", yscale="log", xlabel="Number of particles $N$", ylabel=r"Relative width $\sigma_E/U$",
xlim=(1, 1e25), ylim=(1e-13, 10))
ax2.set_xticks([1, 1e6, 1e12, 1e18, 1e24])
ax2.set_yticks([1, 1e-3, 1e-6, 1e-9, 1e-12])
ax2.minorticks_off()
fs.panel(ax2, "b", "Relative width")
return fig
fs.show(draw, alt="Two panels. Panel a: three distributions of the energy per particle between 0 and 10 meV, all "
"centered on a dashed line at 4.04 meV. For 10 particles the distribution is a low staircase that "
"covers almost the whole range. For 100 particles it is a narrower peak, and for 1000 particles a "
"tall, sharp peak. Panel b: on logarithmic axes, the relative width of the distribution falls "
"along a straight line from about 1.2 at one particle to about 0.38, 0.12, and 0.038 at 10, 100, "
"and 1000 particles, and to about 1.6 times ten to the minus twelve at one mole.")Figure 2.3.2:Energy of independent two-state particles with and at , the conditions of the worked example below. (a) Distribution of the energy per particle, , for three values of . Each distribution has an area of 1, and the dashed line marks . (b) Relative width of the distribution against on logarithmic axes. The filled points are the three systems of panel (a), and the open point is one mole of particles.
The simulation in Figure 2.3.3 follows the same particles in time. In each step, a tenth of the particles exchange energy with the heat bath, so the energy of the system moves around its average . The simulation collects the energies that the system visits and compares them with the binomial distribution.
Figure 2.3.3: independent two-state particles with and in contact with a heat bath. The energy per particle is shown in successive steps around , with a band that reaches one standard deviation to either side. The bars are the energies that the system has visited, and the line is the binomial distribution. The relative width is given as its exact value and as measured from the visited energies.
Three things to try:
Increase the number of particles from 10 to 10,000 in steps, and compare how far the energy strays from in each system.
Each time grows by a factor of 100, note the factor by which changes, and compare it with Eq. (2.3.18).
Change the temperature at a fixed number of particles, and relate the changes of and of to the probabilities and .
Pressure¶
The pressure follows from two results that are derived in later sections:
, where is the Helmholtz free energy (Section 4.3).
, where is pressure (Section 5.1).
Combining these expressions gives
Section 2.5 applies this formula to particles in a cube and recovers the ideal gas law.
Worked Example¶
Two-state internal energy and heat capacity¶
Consider a two-state system with and . Let .
Partition function
Internal energy
Heat capacity at constant volume
Differentiate with respect to (holding and fixed). Using and ,
Numerical illustration
For at , and , so
Result. interpolates between 0 and , while peaks when thermal energy is comparable to .
Concept Checks¶
Why is obtained from a derivative of rather than from directly?
What does it mean physically when is large? When it is small?
In the two-state model, why does both as and as ?
How do fluctuations in energy relate to the system’s ability to exchange heat with a reservoir?
Key Takeaways¶
Thermodynamic properties are ensemble averages computed from microstate probabilities.
In the canonical ensemble, .
Response functions connect to fluctuations: .
Simple discrete models already capture key qualitative behaviors of and .