Minimizing Energy Under Constant Potential
Introduction
One of the most elegant problems in electrostatics is this: given a conductor held at a fixed potential, what charge distribution on its surface minimizes the electrostatic energy?
The answer, grounded in variational principles, is that the physical equilibrium distribution is exactly the energy-minimizing one — nature solves an optimization problem every time charges settle on a conductor.
In this post, we’ll walk through the mathematics, set up a concrete numerical example (a 2D conducting ring and a 3D conducting sphere), and solve everything in Python.
Mathematical Framework
Energy of a Charge Distribution
The electrostatic energy of a surface charge distribution $\sigma(\mathbf{r})$ is:
$$W = \frac{1}{2} \iint \iint \frac{\sigma(\mathbf{r}), \sigma(\mathbf{r}’)}{4\pi\varepsilon_0 |\mathbf{r} - \mathbf{r}’|} , dS, dS’$$
The Constraint
The conductor surface is held at a fixed potential $V_0$. The potential at any surface point must equal $V_0$:
$$\phi(\mathbf{r}) = \frac{1}{4\pi\varepsilon_0} \int \frac{\sigma(\mathbf{r}’)}{|\mathbf{r} - \mathbf{r}’|} , dS’ = V_0 \quad \forall, \mathbf{r} \in S$$
Variational Condition
Using a Lagrange multiplier $\lambda$ for the total charge $Q = \int \sigma, dS$, minimizing:
$$\delta\left[ W - \lambda \int \sigma, dS \right] = 0$$
yields the integral equation:
$$\frac{1}{4\pi\varepsilon_0} \int \frac{\sigma(\mathbf{r}’)}{|\mathbf{r} - \mathbf{r}’|} , dS’ = \lambda$$
This is precisely the constant-potential condition. The Lagrange multiplier is identified as $\lambda = V_0$, confirming that the equilibrium charge distribution is the energy minimizer.
Discretized Form
Dividing the surface into $N$ elements with charges $q_i$, the energy is:
$$W = \frac{1}{2} \mathbf{q}^T \mathbf{P} \mathbf{q}$$
where $P_{ij} = \dfrac{1}{4\pi\varepsilon_0 r_{ij}}$ is the Maxwell elastance matrix. The potential condition becomes:
$$\mathbf{P} \mathbf{q} = V_0 \mathbf{1}$$
Solving this linear system gives the optimal charge distribution.
Concrete Examples
We solve two cases:
- 2D ring conductor: $N$ point charges arranged on a circle of radius $R$
- 3D sphere conductor: charges distributed on a spherical surface
For the 3D sphere, the analytical answer is known — $\sigma = \text{const}$ — which gives us a perfect verification target.
Python Source Code
1 | """ |
Code Walkthrough
① Physical Constants and Problem Setup
1 | EPS0 = 8.854187817e-12 |
Everything is in SI units. $K_E \approx 8.99 \times 10^9 , \text{N·m}^2/\text{C}^2$ is the Coulomb constant. We hold the conductor at $V_0 = 1,\text{V}$ and set the radius to $R = 1,\text{m}$.
② Maxwell Elastance Matrix — 2D Ring
The function build_elastance_2d constructs the $N \times N$ matrix $\mathbf{P}$ that encodes Coulomb interactions between all pairs of surface elements:
$$P_{ij} = \frac{K_E}{|\mathbf{r}_i - \mathbf{r}j|} \quad (i \neq j), \qquad P{ii} = \frac{K_E}{a_\text{self}}, \quad a_\text{self} = \sqrt{\frac{\pi R^2}{N}}$$
cdist(pos, pos) from SciPy computes all pairwise distances in one vectorized call — much faster than a double loop. The diagonal (self-energy) is regularized by modeling each element as a small disc of radius $a_\text{self}$.
③ Solving the Linear System
1 | q = np.linalg.solve(P, V0 * np.ones(N)) |
This is the entire optimization in two lines. Solving $\mathbf{P}\mathbf{q} = V_0\mathbf{1}$ gives the charge vector that simultaneously satisfies the constant-potential constraint and minimizes energy. The total energy then simplifies beautifully:
$$W = \frac{1}{2}\mathbf{q}^T \mathbf{P} \mathbf{q} = \frac{1}{2} V_0 \sum_i q_i = \frac{1}{2} V_0 Q$$
④ 3D Sphere via Fibonacci Lattice
1 | phi = np.pi * (3.0 - np.sqrt(5.0)) # golden angle ≈ 2.399 rad |
The golden-angle Fibonacci lattice places $N$ points on the sphere with near-uniform spacing, avoiding any clustering at poles. This is critical: a poorly distributed point set would produce an ill-conditioned elastance matrix. For the 3D case, lstsq is used instead of solve for extra numerical stability when $N$ is large.
⑤ Perturbation Test — Proving the Minimum
1 | dq -= dq.mean() # enforce Σδq = 0 (conserve total charge) |
We apply 300 random perturbations while keeping the total charge fixed. If $\mathbf{q}_\text{opt}$ is truly the minimum, then $W_\text{new} \geq W_\text{opt}$ for all perturbations. The energy functional is strictly convex ($\mathbf{P}$ is positive definite), so this is guaranteed mathematically — and confirmed numerically.
⑥ Potential Map (2D)
1 | for i in range(len(q)): |
The potential is evaluated at every point of a $300 \times 300$ grid by superposing the contributions of all $N$ point charges. The np.maximum guard prevents division by zero at source locations. This gives the full 2D potential landscape for visualization.
Execution Results
============================================================
Charge Distribution Optimisation on Conductors
============================================================
[2D] Solving ring conductor (N = 80) ...
Total charge Q = 7.428046e-11 C
Energy W = 3.714023e-11 J
Potential min/max = 1.0000 / 1.0000 (target 1.0)
[3D] Solving sphere conductor (N = 400) ...
Total charge Q = 1.147016e-10 C
Energy W = 5.735082e-11 J
Potential min/max = 1.0000 / 1.0000 (target 1.0)
[2D] Running perturbation test ...
W_opt = 3.714023e-11 | all perturbed >= W_opt : True
[2D] Computing potential map ...
All computation complete. Generating plots ...

============================================================ SUMMARY ============================================================ 2D Ring (N=80) Total charge Q = 7.428046e-11 C Energy W = 3.714023e-11 J Charge std/mean = 0.000000 (0 = uniform) Potential std = 2.23e-16 V 3D Sphere (N=400) Total charge Q = 1.147016e-10 C Energy W = 5.735082e-11 J Charge std/mean = 0.013028 (0 = uniform) Potential std = 8.23e-16 V Perturbation test (2D): 300/300 perturbed states satisfy W_perturbed >= W_opt → energy minimum confirmed
Graph Explanation
The 9-panel figure captures the complete physics of the problem.
Row 1 — 2D Ring
Panel 1 (Ring charge scatter): Each dot on the ring is colored by its charge value $q_i$. For a geometrically symmetric ring, all elements receive exactly the same charge, so the colormap is monochromatic. This confirms uniform charge density $\sigma = \text{const}$ for the 2D ring.
Panel 2 (Charge vs angle): Plots $q_i$ against the azimuthal angle $\theta$. The flat line (numerical values lie exactly on the mean) demonstrates that the solver recovers the analytical result — a ring conductor has uniform charge distribution — with residuals at machine-precision level ($\approx 10^{-16}$ V).
Panel 3 (Potential map): Filled contour plot of $\phi(x, y)$. Inside the ring the potential is constant at $V_0 = 1,\text{V}$. Outside it falls off as $\sim 1/r$, confirming Coulomb’s law. The white circle (conductor boundary) is the equipotential surface $\phi = V_0$.
Row 2 — Verification
Panel 4 (Perturbation histogram): The blue histogram shows the energies of 300 randomly perturbed charge distributions (with fixed total charge). The red vertical line marks $W_\text{opt}$. Every single perturbed state has higher energy — the minimum is confirmed visually and statistically.
Panel 5 (3D sphere scatter): The $N = 400$ Fibonacci-lattice points on the sphere, colored by $q_i$. The near-uniform color confirms that $\sigma \approx \text{const}$ on the sphere, matching the exact analytical solution. Slight color variation reflects finite-$N$ discretization error (std/mean $\approx 0.013$).
Panel 6 (Charge vs polar angle): Each dot is one surface element. The numerical values cluster tightly around both the numerical mean (red dashed) and the analytical uniform value (green dotted), which nearly coincide. The uniform spread across all $\theta \in [0°, 180°]$ confirms there is no polar anisotropy.
Row 3 — 3D Potential
Panel 7 (3D potential surface): The potential $\phi(x, z)$ on the exterior XZ half-plane is rendered as a 3D surface colored by coolwarm. The surface is highest near the conductor ($r \approx R$) and flattens toward zero at large distances, exactly as expected from $\phi \propto 1/r$.
Panel 8 (Radial profile): The critical verification plot. The numerical $\phi(r)$ along the $z$-axis (blue solid line) is compared against the analytical $K_E Q / r$ (red dashed). The two curves overlap almost exactly for $r > R$, confirming that the solved charge distribution produces the correct external potential. The green dash-dot line marks $V_0 = 1,\text{V}$ at the conductor surface.
Panel 9 (Elastance matrix heatmap): The $40 \times 40$ sub-block of $\mathbf{P}$ in $\log_{10}$ scale. The bright diagonal corresponds to large self-energy terms $P_{ii}$. Off-diagonal elements decay rapidly with element separation, forming a Toeplitz-like banded structure — the mathematical signature of Coulomb’s $1/r$ decay for uniformly spaced points on a ring.
Key Takeaways
The numerical results confirm three fundamental principles:
1. The linear system is the exact optimality condition. Solving $\mathbf{P}\mathbf{q} = V_0\mathbf{1}$ yields the variational minimum directly — no iterative optimization is needed. The Lagrange multiplier of the energy minimization problem is simply the conductor potential $V_0$.
2. Symmetry dictates uniformity. For both the 2D ring and 3D sphere, the solver recovers uniform charge density to machine precision (2D) or within discretization error (3D, std/mean $\approx 0.013$). This is the well-known result from electrostatics — symmetric conductors carry uniform surface charge.
3. Strict convexity guarantees a unique global minimum. The elastance matrix $\mathbf{P}$ is symmetric positive definite, so the energy functional $W = \frac{1}{2}\mathbf{q}^T\mathbf{P}\mathbf{q}$ is strictly convex. The 300-trial perturbation test confirmed this: every single perturbed distribution had strictly higher energy.
The variational formulation reveals something profound — nature is always solving an optimization problem. Every time free charges redistribute on a conductor surface, they are finding the unique configuration that minimizes total electrostatic energy subject to the equipotential constraint. The Maxwell elastance matrix makes this optimization explicit and computationally tractable.