# The canonical ensemble at work

Suppose we have a system whose Hamiltonian is:

${\displaystyle {\mathcal {H}}=\sum _{i}{\frac {{\vec {p}}_{i}{}^{2}}{2m}}+\sum _{i}U({\vec {q}}_{i})+{\frac {1}{2}}\sum _{i\neq j}U_{2}({\vec {q}}_{i},{\vec {q}}_{j})}$
(for example, ${\displaystyle U}$ can be the gravitational potential and ${\displaystyle U_{2}}$ an interaction between the particles). Then the canonical probability density is:
${\displaystyle \rho (\mathbb {Q} ,\mathbb {P} )={\frac {1}{Z}}e^{-\beta \sum _{i}{\frac {{\vec {p}}_{i}{}^{2}}{2m}}-\beta \left[\sum _{i}U({\vec {q}}_{i})+{\frac {1}{2}}\sum _{i\neq j}U_{2}({\vec {q}}_{i},{\vec {q}}_{j})\right]}}$
Note that ${\displaystyle \mathbb {Q} }$ and ${\displaystyle \mathbb {P} }$ don't "get mixed up"; therefore, when calculating the partition function ${\displaystyle Z}$ we can separate the kinetic and configurational contributions[1]:
${\displaystyle Z=\int d\Gamma \rho (\mathbb {Q} ,\mathbb {P} )=\prod _{i=1}^{N}\left({\frac {1}{N!h^{3N}}}\int e^{-\beta {\frac {{\vec {p}}_{i}{}^{2}}{2m}}}d{\vec {p}}_{i}\right)\cdot \int e^{-\beta \left[\sum _{i}U({\vec {q}}_{i})+{\frac {1}{2}}\sum _{i\neq j}U_{2}({\vec {q}}_{i},{\vec {q}}_{j})\right]}d\mathbb {Q} }$
Now, since:
${\displaystyle \int e^{-\beta {\frac {{\vec {p}}{}^{2}}{2m}}}d{\vec {p}}=\left({\frac {2\pi m}{\beta }}\right)^{3/2}}$
we have:
${\displaystyle Z={\frac {1}{N!}}\left({\frac {2\pi m}{h^{2}\beta }}\right)^{3N/2}\int e^{-\beta \left[\sum _{i}U({\vec {q}}_{i})+{\frac {1}{2}}\sum _{i\neq j}U_{2}({\vec {q}}_{i},{\vec {q}}_{j})\right]}d\mathbb {Q} }$
In order to simplify this expression, we define the configurational partition function (or configurational sum) as:
${\displaystyle Q_{N}=\int e^{-\beta \left[\sum _{i}U({\vec {q}}_{i})+{\frac {1}{2}}\sum _{i\neq j}U_{2}({\vec {q}}_{i},{\vec {q}}_{j})\right]}d\mathbb {Q} }$
and the thermal wavelength as:
${\displaystyle \Lambda ={\sqrt {\frac {h^{2}}{2\pi k_{B}Tm}}}={\sqrt {\frac {2\pi \hbar ^{2}}{k_{B}Tm}}}}$
so that, in general:
${\displaystyle Z={\frac {1}{N!\Lambda ^{3N}}}Q_{N}}$

If we now consider an ideal gas, namely we set ${\displaystyle U=U_{2}=0}$, then:

${\displaystyle Q_{N}=V^{N}\quad \Rightarrow \quad Z={\frac {1}{N!}}\left({\frac {V}{\Lambda ^{3}}}\right)^{N}}$
And using Stirling's approximation (see the appendix Stirling's approximation) the free energy ${\displaystyle F=-k_{B}T\ln Z}$ of the system turns out to be:
${\displaystyle F=k_{B}TN\left[\ln \left({\frac {N}{V}}\Lambda ^{3}\right)-1\right]}$
Since from thermodynamics we know that ${\displaystyle P=-\partial F/\partial V}$, we get:
${\displaystyle P=-k_{B}TN{\frac {V}{N\Lambda ^{3}}}\left(-{\frac {N}{V^{2}}}\Lambda ^{3}\right)={\frac {k_{B}TN}{V}}\quad \Rightarrow \quad PV=Nk_{B}T}$
We have therefore found the state equation of an ideal gas in the canonical ensemble! We are thus really verifying that the canonical and microcanonical ensembles are equivalent. For example, we can also compute the entropy of this ideal gas, and we get:
${\displaystyle S=-{\frac {\partial F}{\partial T}}=Nk_{B}\left[{\frac {5}{2}}-\ln \left({\frac {N}{V}}\Lambda ^{3}\right)\right]}$
which is exactly what we have found in the microcanonical ensemble.

## Column of gas in a gravitational potential

Just as another example of the power of the canonical ensemble, we now want to see that in a particular case we can obtain the same results that we can determine from simple kinetic considerations. In particular, we want to see how the density of a gas subjected to a uniform gravitational potential varies with the height from the ground.

We begin with the "kinetic" computation. Consider a column of gas subjected to a constant gravitational potential ${\displaystyle mgz}$, where ${\displaystyle z}$ is the height from the ground. The action of gravity will in some way change the density of the particles (we expect that the gas will be more dense near the ground and become thinner and thinner as ${\displaystyle z}$ grows) so let us call ${\displaystyle \rho (z)}$ and ${\displaystyle P(z)}$ the density and the pressure of the gas at height ${\displaystyle z}$. The situation is represented in the following figure:

Column of gas subject to gravity

Let us call ${\displaystyle n(z)\Delta z}$ is the number of particles that are between the heights ${\displaystyle z}$ and ${\displaystyle z+\Delta z}$, where ${\displaystyle n(z)}$ is the particle number density at height ${\displaystyle z}$; these will be subjected to the pressures ${\displaystyle P(z)}$ and ${\displaystyle P(z+\Delta z)}$, and if we call ${\displaystyle \Sigma }$ the cross section of the column then the net force acting on the particles is ${\displaystyle P(z)\Sigma -P(z+\Delta z)\Sigma }$. Since the system is in equilibrium, this force must be balanced by the weight of the gas itself:

${\displaystyle P(z)\Sigma -P(z+\Delta z)\Sigma =\rho (z)\Delta z\Sigma g}$
Therefore, dividing by ${\displaystyle \Sigma }$ and ${\displaystyle \Delta z}$ and taking the limit ${\displaystyle \Delta z\to 0}$:
${\displaystyle {\frac {\partial P}{\partial z}}=-\rho (z)g}$
If we then consider a volume ${\displaystyle V}$ between ${\displaystyle z}$ and ${\displaystyle z+\Delta z}$ we have:
${\displaystyle P(z)V=N(z)k_{B}T\quad \Rightarrow \quad P(z)={\frac {N(z)}{V}}k_{B}T}$
and since ${\displaystyle \rho (z)=N(z)m/V=n(z)m}$, then:
${\displaystyle P(z)={\frac {\rho (z)}{m}}k_{B}T\quad \Rightarrow \quad \rho (z)={\frac {m}{k_{B}T}}P(z)}$
Therefore:
${\displaystyle {\frac {\partial P}{\partial z}}=-g\rho (z)=-{\frac {mg}{k_{B}T}}P(z)\quad \Rightarrow \quad P(z)=P(0)e^{-{\frac {mg}{k_{B}T}}z}}$
or equivalently:
${\displaystyle n(z)=n(0)e^{-{\frac {mg}{k_{B}T}}z}}$
Thus, the density of the gas decreases exponentially with the height.

We now want to show that the tools of the canonical ensemble allow us to obtain the very same result. Let us consider the single-particle canonical partition function[2]:

${\displaystyle Z_{\text{s.p.}}=\int e^{-\beta \left({\frac {{\vec {p}}{}^{2}}{2m}}+mgz\right)}{\frac {d{\vec {p}}d{\vec {q}}}{h^{3}}}}$
Since ${\displaystyle {\vec {q}}=(x,y,z)}$ is such that ${\displaystyle (x,y)\in \Sigma }$ and ${\displaystyle z\in [0,+\infty ]}$, integrating we will have:
${\displaystyle Z_{\text{s.p.}}=\left({\frac {2\pi mk_{B}T}{h^{2}}}\right)^{3/2}{\frac {\Sigma }{\beta mg}}}$
The single-particle probability density of having momentum ${\displaystyle {\vec {p}}}$ and height ${\displaystyle z}$ is:
${\displaystyle \rho _{\text{s.p.}}({\vec {p}},{\vec {q}})={\frac {1}{Z_{\text{s.p.}}}}e^{-\beta \left({\frac {{\vec {p}}{}^{2}}{2m}}+mgz\right)}}$
Therefore we can obtain the spatial probability density integrating over ${\displaystyle {\vec {p}}}$, ${\displaystyle x}$ and ${\displaystyle y}$; in the end we get:
${\displaystyle \rho _{\text{s.p.}}(z)={\frac {mg}{k_{B}T}}e^{-{\frac {mg}{k_{B}T}}z}:=\rho _{\text{s.p.}}(0)e^{-{\frac {mg}{k_{B}T}}z}}$
where we have relabelled the proportionality constant. Now, the particle number density at height ${\displaystyle z}$ will be ${\displaystyle n(z)=N\rho _{\text{s.p.}}(z)}$, so in the end we have:
${\displaystyle n(z)=n(0)e^{-{\frac {mg}{k_{B}T}}z}}$
which is exactly the result previously found .

1. This "separation" was not possible within the microcanonical ensemble and as we will later see (for example in Statistical mechanics of phase transitions) this will simplify the computations when we will consider non ideal systems, namely if the particles actually interact; in fact since any reasonable interaction does not involve the particles' momenta but only their positions only ${\displaystyle Q_{N}}$ (see below) will be affected by the presence of the interaction.
2. We use the single-particle partition function because in the end we want to find the single-particle configurational probability density.