Understanding Helmholtz Free Energy in Thermal Equilibrium
The principle of free energy minimization is fundamental in statistical mechanics and thermodynamics. At thermal equilibrium, a system naturally evolves to minimize its Helmholtz free energy, which is defined as:
$$F = U - TS$$
where $F$ is the Helmholtz free energy, $U$ is the internal energy, $T$ is the temperature, and $S$ is the entropy.
Problem Setup: Two-State Spin System
Let’s consider a concrete example: a system of $N$ magnetic spins that can be either up (+1) or down (-1). Each spin has:
- Energy when aligned with external field: $-\epsilon$
- Energy when anti-aligned: $+\epsilon$
The system reaches equilibrium by minimizing the Helmholtz free energy. We’ll compute:
- The internal energy $U$
- The entropy $S$
- The Helmholtz free energy $F$
- The equilibrium magnetization as a function of temperature
The number of spins in the up state $n_{up}$ determines:
$$U = -\epsilon n_{up} + \epsilon n_{down} = \epsilon(N - 2n_{up})$$
$$S = k_B \ln\Omega = k_B \ln\binom{N}{n_{up}}$$
Python Implementation
1 | import numpy as np |
Code Explanation
Core Functions
1. calculate_internal_energy(n_up, N, epsilon)
This function computes the total internal energy of the spin system. Each up-spin contributes $-\epsilon$ and each down-spin contributes $+\epsilon$:
$$U = -\epsilon \cdot n_{up} + \epsilon \cdot (N - n_{up}) = \epsilon(N - 2n_{up})$$
2. calculate_entropy(n_up, N, k_B)
The entropy is calculated using Stirling’s approximation for the combinatorial factor:
$$S = k_B \ln \binom{N}{n_{up}} \approx k_B[N\ln N - n_{up}\ln n_{up} - (N-n_{up})\ln(N-n_{up})]$$
This approximation is excellent for large $N$ and avoids numerical overflow issues with factorials.
3. calculate_free_energy(n_up, N, T, epsilon, k_B)
This is the key function that combines internal energy and entropy:
$$F(n_{up}, T) = U(n_{up}) - T \cdot S(n_{up})$$
Main Analysis Loop
The code iterates over different temperatures and, for each temperature, scans all possible values of $n_{up}$ to find which configuration minimizes the free energy. This is the equilibrium state at that temperature.
Visualization Strategy
2D Plots:
- Free energy curves at different temperatures show how the minimum shifts
- Magnetization vs temperature reveals the phase transition behavior
- Energy decomposition illustrates the competition between $U$ and $TS$
- Minimum free energy tracks the system’s equilibrium stability
- Entropy and internal energy show how these quantities evolve with temperature
3D Plots:
- The surface plot shows free energy as a function of both configuration ($n_{up}$) and temperature
- The red/white line traces the equilibrium path where the system naturally settles
- Two viewing angles provide different perspectives on the energy landscape
Results and Physical Interpretation
Execution Results:


======================================================================
FREE ENERGY MINIMIZATION ANALYSIS
======================================================================
System Parameters:
Number of spins (N): 100
Energy per spin (ε): 1.0
Boltzmann constant (k_B): 1.0
----------------------------------------------------------------------
Equilibrium Results at Selected Temperatures:
----------------------------------------------------------------------
T n_up m U/ε S/k_B F/k_B
----------------------------------------------------------------------
0.50 98 0.9600 -96.00 9.80 -100.90
1.00 88 0.7600 -76.00 36.69 -112.69
2.00 73 0.4600 -46.00 58.33 -162.65
3.00 66 0.3200 -32.00 64.10 -224.31
5.00 60 0.2000 -20.00 67.30 -356.51
======================================================================
PHYSICAL INTERPRETATION
======================================================================
1. Low Temperature (T → 0):
- System favors minimum energy (all spins aligned)
- Magnetization approaches maximum: m → 1.0
- Entropy contribution negligible: TS → 0
- Free energy ≈ Internal energy
2. High Temperature (T → ∞):
- System favors maximum entropy (random spins)
- Magnetization approaches zero: m → 0
- Entropy dominates: TS >> U
- Equal probability for all configurations
3. Intermediate Temperature:
- Competition between energy and entropy
- System finds optimal balance
- Free energy minimum determines equilibrium
======================================================================
Key Observations
Low Temperature Regime (T < 1):
At low temperatures, the internal energy term dominates. The system minimizes $F \approx U$ by aligning all spins with the field, giving maximum magnetization $m \approx 1$. The entropy is small because there are few accessible states.
High Temperature Regime (T > 3):
At high temperatures, the entropy term $-TS$ dominates. The system maximizes entropy by distributing spins randomly, leading to $m \approx 0$. The free energy becomes $F \approx -TS$, and the system explores all possible configurations equally.
Intermediate Regime (1 < T < 3):
This is where the physics becomes interesting. The system balances energy and entropy, showing a smooth transition from ordered (magnetized) to disordered (random) states. This is characteristic of a second-order phase transition in the thermodynamic limit.
The 3D free energy landscape beautifully illustrates how the global minimum shifts from high $n_{up}$ (low T) to $n_{up} \approx N/2$ (high T), demonstrating the fundamental principle that thermal equilibrium corresponds to free energy minimization.
This principle is universal and applies to chemical reactions, protein folding, crystal formation, and countless other phenomena in nature.