Virial Theorem in Statistical Mechanics

Why does a box of gas push on its walls? Where does the deviation of a real gas from the ideal gas law come from — and how does a galaxy cluster weigh far more than the stars you can see? A single classical identity, over a century and a half old, answers all three. The virial theorem, first written down by Clausius in 1870, ties the average kinetic energy of a bounded system to the virial of the forces acting on it: ⟨T⟩=−12⟨∑iri⋅Fi⟩\langle T\rangle=-\tfrac12\langle\sum_i\mathbf r_i\cdot\mathbf F_i\rangle. It is the coordinate branch of the generalized equipartition theorem, and it is the fastest bridge from microscopic forces to macroscopic pressure. The decisive move for thermodynamics is to split the total force on each particle into two parts: the inward push of the container walls and the mutual forces between particles. The wall part, averaged over the boundary, is exactly −3PV-3PV — pressure times volume, the mechanical fingerprint of the gas pressing on its container. The interaction part carries every deviation from ideal-gas behaviour. Because equipartition already fixes the kinetic side at ⟨T⟩=32NkBT\langle T\rangle=\tfrac32 Nk_BT, the entire physics of a real gas is compressed into one object: the interaction virial ⟨∑i<jrij⋅Fij⟩\langle\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle. This turns the virial theorem into a pressure equation, PV=NkBT+13⟨∑i<jrij⋅Fij⟩PV=Nk_BT+\tfrac13\langle\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle, that reaches from dilute gases to dense liquids to self-gravitating stars. For a power-law potential U∝rkU\propto r^k it collapses to 2⟨T⟩=k⟨U⟩2\langle T\rangle=k\langle U\rangle: harmonic (k=2k=2) gives ⟨T⟩=⟨U⟩\langle T\rangle=\langle U\rangle, gravity (k=−1k=-1) gives 2⟨T⟩=−⟨U⟩2\langle T\rangle=-\langle U\rangle — the astrophysical relation that first revealed dark matter. And it is the exact estimator by which every molecular-dynamics simulation computes pressure. One kinematic identity, and the pressure of matter falls out.

Key takeaways
  • The virial theorem relates the averaged kinetic energy of a bounded classical system to the virial of the forces: ⟨T⟩=−12⟨∑iri⋅Fi⟩\langle T\rangle=-\tfrac12\langle\sum_i\mathbf r_i\cdot\mathbf F_i\rangle, equivalently ⟨∑iri⋅Fi⟩=−3NkBT\langle\sum_i\mathbf r_i\cdot\mathbf F_i\rangle=-3Nk_BT.
  • It is the coordinate-diagonal branch of the generalized equipartition theorem — applying ⟨qk ∂H/∂qk⟩=kBT\langle q_k\,\partial H/\partial q_k\rangle=k_BT to positions and summing over particles.
  • Splitting the force into a wall part (→−3PV\to-3PV by the divergence theorem) and an interaction part gives the exact pressure equation PV=NkBT+13⟨∑i<jrij⋅Fij⟩PV=Nk_BT+\tfrac13\langle\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle.
  • For non-interacting particles only the wall term survives and PV=NkBTPV=Nk_BT is recovered exactly; the interaction virial is the sole correction to ideality.
  • For a power-law potential U∝rkU\propto r^k, 2⟨T⟩=k⟨U⟩2\langle T\rangle=k\langle U\rangle: harmonic ⟨T⟩=⟨U⟩\langle T\rangle=\langle U\rangle, gravity 2⟨T⟩=−⟨U⟩2\langle T\rangle=-\langle U\rangle — the latter giving negative heat capacity and the virial mass of clusters.
  • It is the exact pressure estimator in molecular dynamics and the source of the first evidence for dark matter (Zwicky 1933).
  • Key idea: the average of ∑iri⋅Fi\sum_i\mathbf r_i\cdot\mathbf F_i equals −2⟨T⟩=−3NkBT-2\langle T\rangle=-3Nk_BT; separating wall forces from interaction forces turns this kinematic identity into the exact pressure equation PV=NkBT+13⟨∑i<jrij⋅Fij⟩PV=Nk_BT+\tfrac13\langle\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle.
The core insight

The ensemble average of ∑iri⋅Fi\sum_i\mathbf r_i\cdot\mathbf F_i equals −2⟨T⟩=−3NkBT-2\langle T\rangle=-3Nk_BT; separating wall forces (which give −3PV-3PV) from interaction forces converts this kinematic identity into the exact pressure equation PV=NkBT+13⟨∑i<jrij⋅Fij⟩PV=Nk_BT+\tfrac13\langle\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle.

Where this lives today

The virial theorem is a daily instrument in two very different laboratories. In molecular-dynamics and Monte-Carlo simulations, the instantaneous virial is the standard pressure estimator: P=NkBT/V+13V⟨∑i<jrij⋅Fij⟩P=Nk_BT/V+\tfrac1{3V}\langle\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle, computed from the same pairwise forces already needed to integrate the equations of motion, with the minimum-image convention for periodic boundaries. It is how every equation of state extracted from simulation — for water, proteins, planetary interiors — is measured, sidestepping any need to differentiate a free energy. In astrophysics the gravitational form is foundational: the virial mass of a cluster from its velocity dispersion remains a primary mass estimator, the negative heat capacity underlies the gravothermal core collapse of globular clusters, and the same relation constrains the temperature of the hot gas in galaxy clusters seen in X-rays. From a nanoscale simulation box to a cluster of a thousand galaxies, one 1870 identity ties motion to force to pressure.

The physical picture

Picture the quantity G=∑ipi⋅riG=\sum_i\mathbf p_i\cdot\mathbf r_i — a measure of how far and how fast the particles are streaming outward. In a system confined forever inside a box, GG can wobble but cannot grow or shrink without bound, so its time average of change is zero. That single constraint locks the outward flux (kinetic energy) to the net inward accounting of forces (the virial). The wall is doing real bookkeeping work: each particle bouncing off the container feels an inward force at its boundary position, and summing F⋅r\mathbf F\cdot\mathbf r over the whole surface gives exactly −3PV-3PV. The pressure appears not by assumption but as the wall virial per spatial dimension. The interaction forces then shift the pressure up or down. Attractive forces point particles toward each other, so Fij\mathbf F_{ij} is anti-aligned with the separation rij\mathbf r_{ij}: the interaction virial is negative and PVPV drops below the ideal value — cohesion holding the gas together. Short-range repulsion does the opposite, raising the pressure through excluded volume. The homogeneity of the force law is the cleanest fingerprint: a power-law U∝rkU\propto r^k has r⋅∇U=kU\mathbf r\cdot\nabla U=kU, so the theorem returns 2⟨T⟩=k⟨U⟩2\langle T\rangle=k\langle U\rangle, and the single number kk dictates how energy splits between motion and interaction.

Figure
Two forces in a box. Attractive pull (blue) points inward along the separation, so r·F < 0 and pressure drops below ideal; repulsive push (red) points outward, r·F > 0 and pressure rises. The wall inward force gives −3PV.
attractive: r·F is negative pressure below ideal repulsive: r·F is positive pressure above ideal

The second figure is the punchline: for a self-gravitating system the virial theorem forces a negative heat capacity. With 2⟨T⟩=−⟨U⟩2\langle T\rangle=-\langle U\rangle, the total energy is E=⟨T⟩+⟨U⟩=−⟨T⟩=−32NkBTE=\langle T\rangle+\langle U\rangle=-\langle T\rangle=-\tfrac32 Nk_BT. Remove energy and the system gets hotter — the gravothermal catastrophe that drives star formation and cluster evolution. On the same plot, the ideal-gas pressure sits on the ordinary equipartition line, but the virial mass of a cluster (M∼⟨v2⟩R/GM\sim\langle v^2\rangle R/G) lands an order of magnitude above the luminous mass, the outlier that announced dark matter.

Figure
Punchline: the self-gravitating virial. 2⟨T⟩ = −⟨U⟩ forces E = −⟨T⟩ = −(3/2)NkT, so removing energy raises T — negative heat capacity. The measured virial mass (star) sits far above the luminous mass line.
temperature T → energy 0 ⟨T⟩ = (3/2)NkT E = −⟨T⟩ (dE/dT negative) negative heat capacity virial mass ⟨v²⟩R/G ≫ luminous

The core equations

The starting point is a purely kinematic identity: the time derivative of G=∑ipi⋅riG=\sum_i\mathbf p_i\cdot\mathbf r_i, expanded by the product rule and Newton's law p˙i=Fi\dot{\mathbf p}_i=\mathbf F_i.

ddt∑ipi⋅ri=∑iFi⋅ri+2T(1)\frac{d}{dt}\sum_i\mathbf p_i\cdot\mathbf r_i=\sum_i\mathbf F_i\cdot\mathbf r_i+2T \qquad (1)

where: pi,ri\mathbf p_i,\mathbf r_i — momentum and position of particle ii; Fi=p˙i\mathbf F_i=\dot{\mathbf p}_i — the total force on it; T=∑ipi2/2mT=\sum_i p_i^2/2m — the total kinetic energy. Reading it: the second term is ∑ipi⋅r˙i=∑ipi2/m=2T\sum_i\mathbf p_i\cdot\dot{\mathbf r}_i=\sum_i p_i^2/m=2T, and the first is the virial of the forces. Averaging equation (1) over a bounded trajectory or the equilibrium ensemble sends the left side to zero, giving the virial theorem itself.

⟨T⟩=−12⟨∑iri⋅Fi⟩(2)\langle T\rangle=-\tfrac12\Big\langle\sum_i\mathbf r_i\cdot\mathbf F_i\Big\rangle \qquad (2)

where: ⟨⋅⟩\langle\cdot\rangle — the long-time or ensemble average; the right side is −12-\tfrac12 the virial V=∑iri⋅Fi\mathcal V=\sum_i\mathbf r_i\cdot\mathbf F_i. Reading it: because the system is confined, GG stays bounded, so its average rate of change vanishes and the kinetic and virial sides must balance. The kinetic side is fixed once and for all by equipartition, and the virial itself follows by combining equations (2) and (3).

⟨T⟩=32NkBT ⇒ ⟨∑iri⋅Fi⟩=−3NkBT(3)\langle T\rangle=\tfrac32 Nk_BT\ \Rightarrow\ \Big\langle\sum_i\mathbf r_i\cdot\mathbf F_i\Big\rangle=-3Nk_BT \qquad (3)

where: NN — particle number; kBk_B — Boltzmann's constant. Reading it: each of the 3N3N position coordinates contributes −kBT-k_BT to the virial (this is the coordinate branch of generalized equipartition, ⟨qk ∂H/∂qk⟩=kBT\langle q_k\,\partial H/\partial q_k\rangle=k_BT with ∂H/∂qk=−Fk\partial H/\partial q_k=-F_k). Splitting the total force into wall and interaction parts, and evaluating the wall part by the divergence theorem, converts equation (3) into the exact pressure equation.

PV=NkBT+13⟨∑i<jrij⋅Fij⟩(4)PV=Nk_BT+\frac13\Big\langle\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij}\Big\rangle \qquad (4)

where: rij=ri−rj\mathbf r_{ij}=\mathbf r_i-\mathbf r_j — the separation of a pair; Fij\mathbf F_{ij} — the force on ii from jj; the wall part contributed −3PV-3PV via ∮Sr⋅dA=∫V∇⋅r dV=3V\oint_S\mathbf r\cdot d\mathbf A=\int_V\nabla\cdot\mathbf r\,dV=3V. Reading it: for non-interacting particles the last term vanishes and PV=NkBTPV=Nk_BT; the interaction virial is the entire correction to ideal-gas behaviour. For a central power-law force the interaction virial collapses to the average potential energy through Euler's homogeneity relation.

r⋅∇U=kU ⇒ 2⟨T⟩=k⟨U⟩(U∝rk)(5)\mathbf r\cdot\nabla U=kU\ \Rightarrow\ 2\langle T\rangle=k\langle U\rangle\qquad(U\propto r^k) \qquad (5)

where: kk — the degree of the potential. Reading it: harmonic (k=2k=2) gives ⟨T⟩=⟨U⟩\langle T\rangle=\langle U\rangle (the Dulong-Petit split); gravity or Coulomb (k=−1k=-1) gives 2⟨T⟩=−⟨U⟩2\langle T\rangle=-\langle U\rangle, the astrophysical virial that yields negative heat capacity and cluster masses.

Derivation AThe virial theorem and the pressure equation of state

The goal is to derive the exact pressure equation PV=NkBT+13⟨∑i<jrij⋅Fij⟩PV=Nk_BT+\tfrac13\langle\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle from the Clausius virial, showing that the wall forces produce −3PV-3PV and the interaction forces produce the sole correction to ideality. The strategy is to average the Clausius identity (which kills the total-derivative left side), split the force into wall and pairwise parts, evaluate the wall virial with the divergence theorem, and collapse the internal double sum with Newton's third law.

Step 1. Average equation (1). For a bounded system G=∑ipi⋅riG=\sum_i\mathbf p_i\cdot\mathbf r_i stays finite, so dG/dt‾=lim⁡τ→∞[G(τ)−G(0)]/τ=0\overline{dG/dt}=\lim_{\tau\to\infty}[G(\tau)-G(0)]/\tau=0. Hence ⟨∑iFi⋅ri⟩+2⟨T⟩=0\langle\sum_i\mathbf F_i\cdot\mathbf r_i\rangle+2\langle T\rangle=0, and with ⟨T⟩=32NkBT\langle T\rangle=\tfrac32 Nk_BT this is ⟨∑iri⋅Fi⟩=−3NkBT\langle\sum_i\mathbf r_i\cdot\mathbf F_i\rangle=-3Nk_BT.

Step 2. Split the force: Fi=Fiwall+∑j≠iFij\mathbf F_i=\mathbf F_i^{\text{wall}}+\sum_{j\ne i}\mathbf F_{ij}, the container plus the pairwise interactions.

Step 3. Wall virial by the divergence theorem. The wall exerts inward pressure −P dA-P\,d\mathbf A on the surface element at r\mathbf r, so ⟨∑iFiwall⋅ri⟩=−P∮Sr⋅dA=−P∫V∇⋅r dV=−3PV\langle\sum_i\mathbf F_i^{\text{wall}}\cdot\mathbf r_i\rangle=-P\oint_S\mathbf r\cdot d\mathbf A=-P\int_V\nabla\cdot\mathbf r\,dV=-3PV, using ∇⋅r=3\nabla\cdot\mathbf r=3 in three dimensions. Why the factor is 3, not 1 or 2. The prefactor is the spatial dimension d=∇⋅rd=\nabla\cdot\mathbf r. In dd dimensions the wall virial is −dPV-dPV and the correction carries a 1d\tfrac1d; the familiar 13\tfrac13 is the three-dimensional case, not a double-counting artefact.

Step 4. Internal virial by Newton's third law. Using Fji=−Fij\mathbf F_{ji}=-\mathbf F_{ij}, the double sum collapses to a pair sum: ∑i∑j≠iFij⋅ri=∑i<jFij⋅(ri−rj)=∑i<jFij⋅rij\sum_i\sum_{j\ne i}\mathbf F_{ij}\cdot\mathbf r_i=\sum_{i<j}\mathbf F_{ij}\cdot(\mathbf r_i-\mathbf r_j)=\sum_{i<j}\mathbf F_{ij}\cdot\mathbf r_{ij}. Assembling: −3PV+⟨∑i<jrij⋅Fij⟩=−3NkBT-3PV+\langle\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle=-3Nk_BT, which rearranges to equation (4). Verified: the divergence-theorem factor ∇⋅r=3\nabla\cdot\mathbf r=3, the ideal-gas limit (⟨∑rij⋅Fij⟩=0⇒PV=NkBT\langle\sum\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle=0\Rightarrow PV=Nk_BT), and the sign of the repulsive/attractive interaction virial are confirmed symbolically in verify_aq-sm-virial-theorem-statistical-mechanics.py.

Go deeper · Derivation B · 1 minThe power-law virial and the self-gravitating catastrophe
Derivation BThe power-law virial and the self-gravitating catastrophe

The goal is to reduce the interaction virial to 2⟨T⟩=k⟨U⟩2\langle T\rangle=k\langle U\rangle for a central power-law potential U∝rkU\propto r^k, and to draw out the astrophysical consequence: a self-gravitating system has negative heat capacity. The strategy is Euler's homogeneity relation r⋅∇U=kU\mathbf r\cdot\nabla U=kU, followed by combining 2⟨T⟩=−⟨∑r⋅F⟩=k⟨U⟩2\langle T\rangle=-\langle\sum\mathbf r\cdot\mathbf F\rangle=k\langle U\rangle with the total-energy definition.

Step 1. For U∝rkU\propto r^k, Euler's theorem gives r⋅∇U=kU\mathbf r\cdot\nabla U=kU, so r⋅F=−r⋅∇U=−kU\mathbf r\cdot\mathbf F=-\mathbf r\cdot\nabla U=-kU. The virial of the interaction is −k⟨U⟩-k\langle U\rangle.

Step 2. Insert into the virial theorem 2⟨T⟩=−⟨∑r⋅F⟩2\langle T\rangle=-\langle\sum\mathbf r\cdot\mathbf F\rangle: this gives 2⟨T⟩=k⟨U⟩2\langle T\rangle=k\langle U\rangle. Harmonic (k=2k=2): ⟨T⟩=⟨U⟩\langle T\rangle=\langle U\rangle (energy splits evenly, Dulong-Petit). Gravity/Coulomb (k=−1k=-1): 2⟨T⟩=−⟨U⟩2\langle T\rangle=-\langle U\rangle.

Step 3. Total energy for the gravitational case. With ⟨U⟩=−2⟨T⟩\langle U\rangle=-2\langle T\rangle, the total is E=⟨T⟩+⟨U⟩=⟨T⟩−2⟨T⟩=−⟨T⟩=−32NkBTE=\langle T\rangle+\langle U\rangle=\langle T\rangle-2\langle T\rangle=-\langle T\rangle=-\tfrac32 Nk_BT. Why the heat capacity is negative. Since E=−32NkBTE=-\tfrac32 Nk_BT, we have dE/dT<0dE/dT<0: extracting energy from a virialized self-gravitating system raises its temperature. This gravothermal instability drives the contraction and heating of star-forming clouds and the core collapse of globular clusters — a signature that has no counterpart in a normal gas.

Step 4. Cluster mass estimate. Writing ⟨T⟩=12M⟨v2⟩\langle T\rangle=\tfrac12 M\langle v^2\rangle and ⟨U⟩∼−GM2/R\langle U\rangle\sim-GM^2/R, the relation 2⟨T⟩=−⟨U⟩2\langle T\rangle=-\langle U\rangle gives the virial mass M∼⟨v2⟩R/GM\sim\langle v^2\rangle R/G. Measured velocity dispersion and size fix the total mass — historically the first evidence for dark matter, when the virial mass overshot the luminous mass by an order of magnitude. Verified: the Euler relation r dU/dr=kUr\,dU/dr=kU, the harmonic (k=2k=2) and gravitational (k=−1k=-1) virial splits, the negative heat capacity E=−32NkBTE=-\tfrac32 Nk_BT (so dE/dT<0dE/dT<0), and the order-of-magnitude cluster virial mass ⟨v2⟩R/G∼1014 M⊙\langle v^2\rangle R/G\sim10^{14}\,M_\odot are confirmed in the verify script.

Limiting cases

The virial theorem specializes cleanly to each interaction law; every row is a distinct physical regime.

CaseResultMeaning
Ideal gasPV=NkBTPV=Nk_BTInteraction virial vanishes; only the wall term survives.
Power-law U∝rkU\propto r^k2⟨T⟩=k⟨U⟩2\langle T\rangle=k\langle U\rangleHarmonic ⟨T⟩=⟨U⟩\langle T\rangle=\langle U\rangle; gravity 2⟨T⟩=−⟨U⟩2\langle T\rangle=-\langle U\rangle.
Self-gravitating systemE=−⟨T⟩=−32NkBTE=-\langle T\rangle=-\tfrac32 Nk_BTNegative heat capacity; gravothermal collapse; virial mass.
Dilute repulsive gasPV>NkBTPV>Nk_BTPositive interaction virial (excluded volume).
Dilute attractive gasPV<NkBTPV<Nk_BTNegative interaction virial (cohesion).

Worked examples

Example 1 — The virial mass of a galaxy cluster (enumerate, apply, boundary number). A galaxy cluster in equilibrium has a measured velocity dispersion ⟨v2⟩1/2≈1000 km/s\langle v^2\rangle^{1/2}\approx1000\,\mathrm{km/s} and a radius R≈1 Mpc=3.09×1022 mR\approx1\,\mathrm{Mpc}=3.09\times10^{22}\,\mathrm m. Estimate its total mass.

Step 1. Enumerate. The cluster is self-gravitating, so the virial theorem is 2⟨T⟩+⟨U⟩=02\langle T\rangle+\langle U\rangle=0, i.e. 2⟨T⟩=−⟨U⟩2\langle T\rangle=-\langle U\rangle. Write ⟨T⟩=12M⟨v2⟩\langle T\rangle=\tfrac12 M\langle v^2\rangle and ⟨U⟩∼−GM2/R\langle U\rangle\sim-GM^2/R.

Step 2. Apply. Substituting, M⟨v2⟩=GM2/RM\langle v^2\rangle=GM^2/R, so M∼⟨v2⟩R/GM\sim\langle v^2\rangle R/G. Every factor is measured or known.

Step 3. Boundary number. With ⟨v2⟩=(106)2=1012 m2/s2\langle v^2\rangle=(10^6)^2=10^{12}\,\mathrm{m^2/s^2}, R=3.09×1022 mR=3.09\times10^{22}\,\mathrm m, G=6.674×10−11G=6.674\times10^{-11}: M≈(1012)(3.09×1022)/(6.674×10−11)=4.6×1044 kg≈2.3×1014 M⊙M\approx(10^{12})(3.09\times10^{22})/(6.674\times10^{-11})=4.6\times10^{44}\,\mathrm{kg}\approx\mathbf{2.3\times10^{14}\,M_\odot}. The luminous mass in stars is roughly ten times smaller — the gap Zwicky (1933) attributed to unseen "dark matter," using exactly this virial argument.

Example 2 — Interaction correction to the pressure of a dilute gas. A dilute gas of N=6.0×1023N=6.0\times10^{23} molecules in V=0.0224 m3V=0.0224\,\mathrm m^3 at T=273 KT=273\,\mathrm K has a measured pressure 2%2\% below the ideal value. Find the interaction virial.

Step 1. The ideal pressure is Pid=NkBT/VP_{\text{id}}=Nk_BT/V; the ideal PV=NkBT=(6.0×1023)(1.381×10−23)(273)=2263 JPV=Nk_BT=(6.0\times10^{23})(1.381\times10^{-23})(273)=2263\,\mathrm J.

Step 2. The pressure equation is PV=NkBT+13⟨∑rij⋅Fij⟩PV=Nk_BT+\tfrac13\langle\sum\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle. A 2%2\% deficit means PV=0.98×2263=2218 JPV=0.98\times2263=2218\,\mathrm J, so 13⟨∑rij⋅Fij⟩=2218−2263=−45 J\tfrac13\langle\sum\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle=2218-2263=-45\,\mathrm J.

Step 3. Boundary number. The interaction virial is ⟨∑rij⋅Fij⟩=−135 J\langle\sum\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle=\mathbf{-135\,J}, negative — the forces are net attractive, as expected for a gas below its Boyle temperature. The sign of the pressure deviation reads off the sign of the interaction virial directly, no partition function required.

Origins · 1 minvirial theorem and how this was discovered
VT
virial theorem
classical mechanics · Clausius 1870 · the virial and its statistical form

The virial theorem was introduced by Rudolf Clausius in 1870, who coined the word "virial" from the Latin vis (force) for the quantity ∑iFi⋅ri\sum_i\mathbf F_i\cdot\mathbf r_i. Building on earlier scaling ideas of Rankine and the kinetic theory of Clausius and Maxwell, it was the tool that let nineteenth-century physicists connect the mean kinetic energy of molecules to the forces holding matter together. Boltzmann and Maxwell recognized it as a companion to equipartition; in the modern view it is the coordinate branch of the generalized equipartition theorem. Its reach far exceeds gases: applied to gravity it gives the astrophysical virial relation used by Zwicky in 1933 to infer dark matter, and it remains the exact pressure estimator in molecular-dynamics simulations.

History
1870
— Clausius introduces the virial theorem and coins the term "virial" for the force sum.
1873
— van der Waals gives an equation of state whose corrections match the virial split.
1901
— Kamerlingh Onnes coins "virial expansion" for the density series of the pressure.
1933
— Zwicky applies the virial theorem to the Coma cluster and infers unseen "dark matter".
1957
— Alder and Wainwright use the virial estimator to compute pressure in the first molecular-dynamics simulations.

Going further

References. Pathria & Beale, Statistical Mechanics, 3rd ed., Ch. 3 (virial theorem) and Ch. 10 (virial expansion) · Kardar, Statistical Physics of Particles, Ch. 4–5 · Reif, Fundamentals of Statistical and Thermal Physics, §7.6–7.7 · Landau & Lifshitz, Statistical Physics Part 1, §33–34, and Mechanics §10 · Binney & Tremaine, Galactic Dynamics, §4.3 (astrophysical virial).

Provenance. The Clausius identity, the −3PV-3PV wall virial via the divergence theorem, the pressure equation PV=NkBT+13⟨∑rij⋅Fij⟩PV=Nk_BT+\tfrac13\langle\sum\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle, and the power-law relation 2⟨T⟩=k⟨U⟩2\langle T\rangle=k\langle U\rangle are standard (Pathria §3.7 & Ch. 10, Landau–Lifshitz §33–34). A verifier should confirm: (i) the coordinate-diagonal ⟨q ∂H/∂q⟩=kBT\langle q\,\partial H/\partial q\rangle=k_BT; (ii) ∇⋅r=3\nabla\cdot\mathbf r=3 giving the −3PV-3PV wall term; (iii) the ideal-gas limit PV=NkBTPV=Nk_BT; (iv) r dU/dr=kUr\,dU/dr=kU and the harmonic/gravitational splits; (v) the negative heat capacity E=−32NkBTE=-\tfrac32 Nk_BT and the cluster virial mass ⟨v2⟩R/G∼1014 M⊙\langle v^2\rangle R/G\sim10^{14}\,M_\odot. All checks are in verify_aq-sm-virial-theorem-statistical-mechanics.py. The second virial coefficient B2(T)B_2(T) and the van der Waals identification are developed in the Virial Equation of State article. Constants: kB=1.380649×10−23 J/Kk_B=1.380649\times10^{-23}\,\mathrm{J/K}, G=6.674×10−11 m3 kg−1 s−2G=6.674\times10^{-11}\,\mathrm{m^3\,kg^{-1}\,s^{-2}}.

Builds on: Equipartition Theorem · Generalized Equipartition Theorem · Classical Ideal Gas · Maxwell-Boltzmann Velocity Distribution Leads to: Virial Equation of State · Sackur-Tetrode Equation

How is the virial theorem related to the generalized equipartition theorem?

It is the coordinate branch of it. The generalized equipartition theorem states ⟨xi ∂H/∂xj⟩=δijkBT\langle x_i\,\partial H/\partial x_j\rangle=\delta_{ij}k_BT for any confining Hamiltonian. Take the diagonal case with a position coordinate: ⟨qk ∂H/∂qk⟩=kBT\langle q_k\,\partial H/\partial q_k\rangle=k_BT, and since ∂H/∂qk=−Fk\partial H/\partial q_k=-F_k, this is ⟨qkFk⟩=−kBT\langle q_k F_k\rangle=-k_BT. Summing over all 3N3N coordinates gives ⟨∑iri⋅Fi⟩=−3NkBT\langle\sum_i\mathbf r_i\cdot\mathbf F_i\rangle=-3Nk_BT — exactly the virial theorem. The momentum branch of the same identity gives kinetic equipartition. So the virial theorem and equipartition are two faces of one phase-space identity, distinguished only by whether you probe positions or momenta.

Why must the system be bounded for the theorem to hold?

Because the derivation rests on the average rate of change of G=∑ipi⋅riG=\sum_i\mathbf p_i\cdot\mathbf r_i being zero. That average is lim⁡τ→∞[G(τ)−G(0)]/τ\lim_{\tau\to\infty}[G(\tau)-G(0)]/\tau, which vanishes only if GG stays finite — that is, if positions and momenta both remain bounded for all time. For a confined gas, the walls provide the boundedness (and their virial is the pressure term). For an unconfined, escaping system GG grows and the identity fails, which is why you cannot simply drop the wall forces from a gas: they are precisely what keep the system bounded and what encode the pressure.

Where does the factor of ⅓ in the pressure equation come from?

From the three spatial dimensions. The wall virial is ⟨∑iFiwall⋅ri⟩=−P∮Sr⋅dA=−P∫V(∇⋅r) dV\langle\sum_i\mathbf F_i^{\text{wall}}\cdot\mathbf r_i\rangle=-P\oint_S\mathbf r\cdot d\mathbf A=-P\int_V(\nabla\cdot\mathbf r)\,dV, and ∇⋅r=∂x/∂x+∂y/∂y+∂z/∂z=3\nabla\cdot\mathbf r=\partial x/\partial x+\partial y/\partial y+\partial z/\partial z=3, so the surface integral gives 3V3V and the wall virial is −3PV-3PV. Balancing against −3NkBT-3Nk_BT and moving the 33 across yields the 13\tfrac13 multiplying the interaction virial. In dd dimensions the same computation gives ∇⋅r=d\nabla\cdot\mathbf r=d, a wall virial −dPV-dPV, and a 1d\tfrac1d prefactor — so the 13\tfrac13 is the dimension count, not a double-counting correction.

Does an attractive or a repulsive interaction raise the pressure?

Repulsion raises it, attraction lowers it. The interaction virial is ⟨∑i<jrij⋅Fij⟩\langle\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle. For a repulsive force, Fij\mathbf F_{ij} pushes the pair apart, aligned with the separation rij\mathbf r_{ij}, so the dot product is positive: PVPV rises above NkBTNk_BT (this is the excluded-volume effect). For an attractive force, Fij\mathbf F_{ij} pulls the pair together, anti-aligned with rij\mathbf r_{ij}, so the dot product is negative and PVPV falls below the ideal value — the cohesion that shows up as the −a/V2-a/V^2 term in van der Waals. The measured sign of the pressure deviation is a direct readout of the net interaction virial.

How does the virial theorem give a self-gravitating system negative heat capacity?

For gravity, the potential is U∝r−1U\propto r^{-1} (k=−1k=-1), so 2⟨T⟩=−⟨U⟩2\langle T\rangle=-\langle U\rangle. The total energy is then E=⟨T⟩+⟨U⟩=⟨T⟩−2⟨T⟩=−⟨T⟩=−32NkBTE=\langle T\rangle+\langle U\rangle=\langle T\rangle-2\langle T\rangle=-\langle T\rangle=-\tfrac32 Nk_BT. Because EE decreases as TT increases, the heat capacity dE/dT=−32NkBdE/dT=-\tfrac32 Nk_B is negative: remove energy and the system gets hotter. Physically, a contracting self-gravitating cloud converts gravitational potential energy into kinetic energy faster than it radiates, so it heats up as it shrinks. This gravothermal instability drives star formation and the core collapse of star clusters, and it is a strictly gravitational (long-range) phenomenon with no analogue in an ordinary gas.

Can I use the virial theorem to measure pressure in a simulation?

Yes — it is the standard method. In a molecular-dynamics or Monte-Carlo simulation you already compute the pairwise forces Fij\mathbf F_{ij} to advance the dynamics, so the virial ∑i<jrij⋅Fij\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij} costs almost nothing extra. The pressure is P=NkBT/V+13V⟨∑i<jrij⋅Fij⟩P=Nk_BT/V+\tfrac1{3V}\langle\sum_{i<j}\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle, with TT taken from the average kinetic energy. This gives the equation of state directly from trajectories without differentiating a free energy. The one subtlety is periodic boundary conditions: you must use the minimum-image separation for rij\mathbf r_{ij}, or the virial (and hence the pressure) comes out wrong.

Does the interaction virial give the full equation of state?

It gives the exact pressure, but turning it into a usable equation of state requires expanding the interaction virial in density — which is the job of the virial equation of state. At low density the leading correction is the second virial coefficient B2(T)B_2(T), obtained by evaluating the pair virial with the Boltzmann-factor pair correlation; higher orders bring B3(T)B_3(T) and beyond. The virial theorem provides the exact starting identity PV=NkBT+13⟨∑rij⋅Fij⟩PV=Nk_BT+\tfrac13\langle\sum\mathbf r_{ij}\cdot\mathbf F_{ij}\rangle; the systematic density expansion of that interaction term, and the connection to the pair potential through B2B_2, is developed in the companion Virial Equation of State article.

Before this

Where this leads