# Physics with Calculus/Electromagnetism/Field Energy

A single test particle's potential energy, ${\displaystyle U_{\mathrm {E} }^{\text{single}}}$, can be calculated from a line integral of the work, ${\displaystyle q_{n}{\vec {E}}\cdot \mathrm {d} {\vec {\ell }}}$. We integrate from a point at infinity, and assume a collection of ${\displaystyle N}$ particles of charge ${\displaystyle Q_{n}}$, are already situated at the points ${\displaystyle {\vec {r}}_{i}}$. This potential energy (in Joules) is:

${\displaystyle U_{\mathrm {E} }^{\text{single}}=q\phi ({\vec {r}})={\frac {q}{4\pi \varepsilon _{0}}}\sum _{i=1}^{N}{\frac {Q_{i}}{\left\|{\mathfrak {\vec {r}}}_{i}\right\|}}}$

where ${\displaystyle {\vec {\mathfrak {r}}}_{i}={\vec {r}}-{\vec {r}}_{i},}$ is the distance of each charge ${\displaystyle Q_{i}}$ from the test charge ${\displaystyle q}$, which situated at the point ${\displaystyle {\vec {r}}}$, and ${\displaystyle \phi ({\vec {r}})}$ is the electric potential that would be at ${\displaystyle {\vec {r}}}$ if the test charge were not present. If only two charges are present, the potential energy is ${\displaystyle k_{e}Q_{1}Q_{2}/r}$. The total electric potential energy due a collection of N charges is calculating by assembling these particles one at a time:

${\displaystyle U_{\mathrm {E} }^{\text{total}}={\frac {1}{4\pi \varepsilon _{0}}}\sum _{j=1}^{N}Q_{j}\sum _{i=1}^{j-1}{\frac {Q_{i}}{r_{ij}}}={\frac {1}{2}}\sum _{i=1}^{N}Q_{i}\phi _{i},}$

where the following sum from, j = 1 to N, excludes i = j:

${\displaystyle \phi _{i}={\frac {1}{4\pi \varepsilon _{0}}}\sum _{j=1(j\neq i)}^{N}{\frac {Q_{j}}{4\pi \varepsilon _{0}r_{ij}}}.}$

This electric potential, ${\displaystyle \phi _{i}}$ is what would be measured at ${\displaystyle {\vec {r}}_{i}}$ if the charge ${\displaystyle Q_{i}}$ were missing. This formula obviously excludes the (infinite) energy that would be required to assemble each point charge from a disperse cloud of charge. The sum over charges can be converted into an integral over charge density using the prescription ${\displaystyle \sum (\cdots )\rightarrow \int (\cdots )\rho \mathrm {d} ^{3}r}$:

${\displaystyle U_{\mathrm {E} }^{\text{total}}={\frac {1}{2}}\int \rho ({\vec {r}})\phi ({\vec {r}})\operatorname {d} ^{3}r={\frac {\varepsilon _{0}}{2}}\int \left|{\mathbf {E} }\right|^{2}\operatorname {d} ^{3}r}$,

This second expression for electrostatic energy uses the fact that the electric field is the negative gradient of the electric potential, as well as vector calculus identities in a way that resembles integration by parts. These two integrals for electric field energy seem to indicate two mutually exclusive formulas for electrostatic energy density, namely ${\displaystyle {\frac {1}{2}}\rho \phi }$ and ${\displaystyle {\frac {\varepsilon _{0}}{2}}E^{2}}$; they yield equal values for the total electrostatic energy only if both are integrated over all space.