Electromagnetism · Lab

Charges and fields

Place charges, draw conductors and watch the field settle. Try image charges, Gauss's law, a capacitor or a Faraday cage.

Pick a tool above the canvas.

weak strong |E|

Solid lines with arrows: field lines. Thin lines: equipotentials. Red and blue blocks: conductors above and below zero, grey ones grounded. Tinted cells: dielectric.

Charges and fields

Two-dimensional electrostatics in units with ε0 = 1: every charge is a line charge seen end on.

Scene
1.00
1.0
4.0
0.20
0.80
0.06
Walls
Display
Colour
Exact overlay
10
0.040
Simulation
400
Free charge
n/a
V at probe
n/a
|E| at probe
n/a
E direction, degrees
n/a
Induced charge
n/a
C per length
n/a
Ideal, no fringing
n/a
C / ideal
n/a
Max |ΔV| from exact
n/a
Max |E| enclosed
n/a
SOR sweeps
n/a
Last correction
n/a
Sources
  1. W. H. Press, S. A. Teukolsky, W. T. Vetterling and B. P. Flannery, Numerical Recipes, 3rd ed., Cambridge University Press (2007), ch. 17 and 20
  2. D. Young, Iterative methods for solving partial difference equations of elliptic type, Trans. Amer. Math. Soc. 76, 92 (1954)
  3. S. P. Frankel, Convergence rates of iterative treatments of partial differential equations, Math. Tables Aids Comput. 4, 65 (1950)
  4. R. A. James, The solution of Poisson's equation for isolated source distributions, J. Comput. Phys. 25, 71 (1977)
  5. W. E. Lorensen and H. E. Cline, Marching cubes: A high resolution 3D surface construction algorithm, ACM SIGGRAPH Comput. Graph. 21, 163 (1987)
  6. J. R. Nuñez, C. R. Anderton and R. S. Renslow, Optimizing colormaps with consideration for color vision deficiency, PLOS ONE 13, e0199239 (2018)
  7. H. B. Palmer, The Capacitance of a Parallel-Plate Capacitor by the Schwartz-Christoffel Transformation, Trans. AIEE 56, 363 (1937)
  8. M. Faraday, Experimental researches in electricity, eleventh series, Phil. Trans. R. Soc. Lond. 128, 1 (1838)
  9. M. Faraday, On static electrical inductive action, Phil. Mag. 22, 200 (1843)
  10. D. J. Griffiths, Introduction to Electrodynamics, 4th ed., Pearson (2013), ch. 2 to 4
  11. J. D. Jackson, Classical Electrodynamics, 3rd ed., Wiley (1999), ch. 1, 2 and 4
  12. E. M. Purcell and D. J. Morin, Electricity and Magnetism, 3rd ed., Cambridge University Press (2013), ch. 1 to 3 and 10

Experiments

Potential along your line

Pick the Line tool and drag across the canvas. Solid blue: the computed V. Dashed red: the exact image solution, where the scene has one.

Sweeps

Learn Charges, fields and the relaxation method

Charges in a flat world

A point charge q pushes on everything around it with a field that points straight away from it and falls off as the inverse square of the distance. That's Coulomb's law [1, Ch. 2; 3, Ch. 1]. This lab is flat, though, so it needs a flat version of that law. The right one is a line charge: an infinite straight wire carrying charge \lambda per unit length, seen end on. Gauss's law (below) gives its field at once,

\mathbf{E} = \frac{\lambda}{2\pi\varepsilon_0 r}\,\hat{\mathbf{r}}, \qquad V = -\frac{\lambda}{2\pi\varepsilon_0}\ln r + \text{const},

so in the plane the field falls off as 1/r instead of 1/r^2, and the potential grows logarithmically instead of settling to zero at infinity [1, Ch. 2]. Every "charge" you click onto the canvas is such a line, every conductor is a long prism and every capacitance is a capacitance per unit length. The lab works in units with \varepsilon_0 = 1 and measures lengths in units of half the width of the box, so a unit charge has V = -\ln r / 2\pi.

Nothing else about electrostatics changes in two dimensions. Fields still add, conductors are still equipotentials and the same uniqueness theorems hold.

Superposition

The field of several charges is the vector sum of their separate fields, and the potential is the plain sum of their potentials [1, Ch. 2; 2, Ch. 1]:

V(\mathbf{r}) = -\frac{1}{2\pi\varepsilon_0}\sum_i \lambda_i \ln|\mathbf{r} - \mathbf{r}_i| .

With only free charges on the canvas and the walls set to open space, this sum is the answer, worked out exactly at every pixel. There's no grid and nothing to converge, and the readout under the canvas tells you so.

Field lines and equipotentials

A field line is a curve whose tangent is \mathbf{E} everywhere. The lab traces each one by integrating d\mathbf{r}/ds = \mathbf{E}/|\mathbf{E}| with the classical fourth order Runge-Kutta method [8, Ch. 17], in steps of a little over half a grid cell, until the line reaches a charge, enters a conductor or leaves the box.

Lines start on positive charges, evenly spaced in angle, with a number proportional to the charge. In two dimensions that rule pays off. The flux of \mathbf{E} through any closed curve counts the charge inside, and lines are neither created nor destroyed in empty space, so the number of lines crossing a short segment is proportional to the flux through it. So here, crowded lines really do mean a strong field. The flat drawings of three dimensional fields in most textbooks can't promise that [3, Ch. 1]. Negative charges only start their own lines, traced backwards, for the share that did not arrive from somewhere else. Conductors seed lines from their surface in proportion to the induced charge on each face.

An equipotential is a curve of constant V. Since \mathbf{E} = -\nabla V, the field is always perpendicular to the equipotentials, and the lab draws both so you can see the right angles. The contours come from the marching squares algorithm, the two dimensional form of marching cubes [10]: each grid cell is classified by which of its corners lie above the level, and the crossing points on its edges are found by linear interpolation.

Gauss's law

The flux of the electric field out of any closed surface equals the charge enclosed divided by \varepsilon_0 [1, Ch. 2; 2, Ch. 1; 3, Ch. 1]:

\oint \mathbf{E}\cdot d\mathbf{a} = \frac{Q_\text{enc}}{\varepsilon_0} .

In the plane the closed surface becomes a closed curve and Q_\text{enc} a charge per length. The lab uses Gauss's law to measure the charge on a conductor: it adds up the flux of \varepsilon \mathbf{E} through every face of the grid that separates a conductor node from empty space. The tests check it two ways: as a flux integral around circles that do or don't contain each charge, and on a grounded shell that must collect exactly -q when a charge q sits inside.

Faraday put this to the test in 1838. He built a cube twelve feet on a side out of wire, paper and tin foil, charged it from outside and sat a gold-leaf electrometer inside. In his words, "neither during the charge or after the discharge did the electrometer or air within show the least signs of electricity" [4, §1174, quoted from the 1849 reprint]. Five years later his ice-pail experiment showed that a charged ball lowered into a closed metal can induces an equal charge on the outside of the can, whatever its position inside [5].

Conductors and the uniqueness theorem

Inside a conductor in equilibrium the field is zero, so the whole conductor is one equipotential and any charge sits on its surface [1, Ch. 2; 3, Ch. 3]. The lab's conductors are sets of grid nodes held at a fixed potential, either grounded at zero or at the potential V you set.

Why should the field around them have only one answer? The first uniqueness theorem states that the solution of Laplace's equation in a region is fixed by the potential on its boundary. The second states that, around conductors, the field is fixed by the total charge on each conductor, or equally by their potentials [1, Ch. 3; 2, Ch. 1]. Uniqueness is the licence for every method in this lab: if a guess satisfies the equation and the boundary conditions, it's the answer, however you found it.

The method of images

A charge q at height a above an infinite grounded plane induces a negative charge on the plane. Working out that distribution head on looks hard. Here's the trick: a charge -q placed at the mirror point, depth a below the plane, makes the plane an equipotential at zero all by itself. Above the plane the pair satisfies the same equation and the same boundary condition as the real problem, so by uniqueness the field above the plane is exactly that of the pair [1, Ch. 3; 2, Ch. 2; 3, Ch. 3]:

V(x, y) = -\frac{q}{2\pi\varepsilon_0}\ln\frac{\sqrt{x^2 + (y - a)^2}}{\sqrt{x^2 + (y + a)^2}}, \qquad \sigma(x) = -\frac{q\,a}{\pi\left(x^2 + a^2\right)} .

The induced charge integrates to exactly -q, spread over the whole infinite plane.

No box can hold an infinite plane. With open walls, the plane in the lab is two units wide, and the image solution's tails beyond the walls are missing: the plane collects only part of -q and the potential drifts away from the image result. With the walls set to Exact solution, the wall nodes hold the potential the infinite plane would produce, and nothing else. The solver never sees the image charge; it only knows the real charge, the grounded plane and the wall values. Uniqueness then says it must find the image potential everywhere inside, and it does, to about 10^{-5}.

The same trick works for a dielectric. A charge q in vacuum at distance a from a flat dielectric of permittivity \varepsilon_r sees, on its own side, the field of itself plus an image q' = -q(\varepsilon_r - 1)/(\varepsilon_r + 1) at the mirror point. Inside the dielectric the field is that of a single charge 2q/(\varepsilon_r + 1) at the original position [1, Ch. 4; 2, Ch. 4]. Both pieces match at the surface: V and the tangential \mathbf{E} are continuous, and so is the normal component of \mathbf{D} = \varepsilon \mathbf{E}. The textbook derivations use point charges, but they only rely on radially symmetric potentials matching on a plane, so they carry over unchanged to line charges.

Laplace's equation and relaxation

Away from free charges the potential obeys Laplace's equation, \nabla^2 V = 0, and inside a dielectric the more general \nabla\cdot(\varepsilon\nabla V) = -\rho_\text{free} [1, Ch. 3 and 4]. On a square grid of spacing h the Laplacian becomes

\frac{V_{i+1,j} + V_{i-1,j} + V_{i,j+1} + V_{i,j-1} - 4V_{i,j}}{h^2} = 0,

which says that each node holds the average of its four neighbours: the discrete form of the mean value property of harmonic functions [1, Ch. 3]. Repeatedly replacing every node by its neighbours' average is the Jacobi method. It converges, but slowly: an error that varies across the whole box needs a number of sweeps proportional to the square of the number of cells across.

Successive over-relaxation (SOR) speeds this up by overshooting each update,

V_{i,j} \leftarrow V_{i,j} + \omega\left(\bar V_{i,j} - V_{i,j}\right), \qquad 1 < \omega < 2,

with \bar V the neighbour average. Frankel [6] and Young [7] found independently that the best \omega for an N \times N box is close to 2/(1 + \sin(\pi/N)), and that it cuts the work to a number of sweeps proportional to N itself. The lab updates the grid in red-black checkerboard order and uses Chebyshev acceleration, which starts with \omega = 1 and walks it towards the optimum over the first sweeps [8, Ch. 20]. At 128 cells across, a box solves to a correction of 10^{-6} in a few hundred sweeps. The tests check it against the Fourier series for a grounded square with one wall at V_0 [1, Ch. 3]: the error falls fourfold each time the spacing halves, as a second order scheme should, and the sweep count only doubles.

Two details keep the grid accurate. First, free charges never live on the grid. Their exact log potential is computed everywhere, and SOR only solves for the correction \psi that conductors, dielectrics and walls add. Near a charge the potential is as sharp as the formula. Second, the walls. A real lab has no box around it, and a two dimensional potential doesn't even vanish at infinity. With Open space walls, every sixteen sweeps the lab finds the charge induced on conductors and bound to dielectric surfaces (the discrete Laplacian of \psi), and sets each wall node to the free space potential of those charges. This iteration settles together with SOR. It is a variant of James's method for isolated systems, which also sets the boundary from the potential of the screening charge [9]. Each wall update moves only halfway towards the new value, because a conductor close to a wall feeds back on it strongly. Painted conductors keep a quarter of a unit clear of the walls, and if the walls still fail to settle the lab grounds them and says so under the canvas. Grounded box holds the walls at zero instead.

Turn SOR sweeps per frame down to one and press a preset with a conductor. Now you can watch the potential relax outward from the conductors, one sweep per frame.

Capacitance and fringing

Two conductors at potentials V_+ and V_- carry charges \pm Q, and C = Q/(V_+ - V_-) depends only on their shapes and the dielectric between them [1, Ch. 2; 3, Ch. 3]. For two plates of width w a distance d apart, ignoring their edges, the field between them is uniform and

\frac{C}{\text{length}} = \frac{\varepsilon_r \varepsilon_0\, w}{d} .

The real field bulges out around the edges. This fringing field stores extra charge on the outer faces and near the ends, so the true capacitance is always larger than \varepsilon_0 w/d, and the excess matters more as d grows compared with w. Palmer solved the thin-plate problem exactly with a Schwarz-Christoffel conformal map in 1937 [12]; the lab measures it directly instead. For coaxial cylinders of radii a < b there is no fringing, and C = 2\pi\varepsilon_0/\ln(b/a) per length [1, Ch. 2]. The tests use this as a second analytic check: the grid's staircase circles reach it to about 3% at 128 cells and closer on finer grids.

Things to try

  • Dipole. Every line leaving the positive charge lands on the negative one, apart from a few that leave the box and come back. The zero equipotential is the perpendicular bisector.
  • Two like charges. The lines push apart. Move the probe to the midpoint: |E| drops to zero at the neutral point, where two equipotentials cross.
  • Quadrupole. Net charge zero and dipole moment zero, so the field falls off faster than either a single charge or a dipole. The colour fades quickly towards the walls.
  • Charge above a grounded plane. Dashed red contours are the image solution, drawn over the computed ones. Max |\Delta V| should sit near 10^{-5}. Switch the walls to Open space: the plane becomes finite and the agreement degrades, worst far from the charge.
  • Parallel-plate capacitor. Read C per length against the ideal. Then press Sweep the gap below the canvas, and set \varepsilon_r above 1 to fill the gap with dielectric.
  • Faraday cage. A grounded closed box between two charges. Max |E| enclosed falls to about 10^{-4}, set by the solver's tolerance, while the field outside is of order one.
  • Charge inside a shell. The induced charge reads -1.000, and outside the shell the field is zero. Drag the charge around inside: neither changes.
  • Charge facing a dielectric. Field lines refract at the surface and the field inside is weaker. Change \varepsilon_r and watch the dashed two-image solution follow.

Then make your own: choose Blank, paint conductors and dielectrics with the brush and drop charges among them.

Reading the lab's instruments

  • Canvas. Colour is |\mathbf{E}| on a logarithmic scale spanning at most three decades, using the cividis map, which was designed to read the same for viewers with colour vision deficiency and to brighten steadily with value [11]. Solid lines with arrows are field lines; thin lines are equipotentials, spaced by Equipotential spacing in volts. The cross is the probe and the red tick on it points along \mathbf{E}.
  • Free charge. The sum of the charges you placed, per unit length.
  • V at probe, |E| at probe, E direction. Potential and field under the cursor, or wherever the Probe tool last put it. The angle is measured anticlockwise from the +x axis.
  • Induced charge. Total charge on all conductors, from the flux of \varepsilon\mathbf{E} through their surface faces.
  • C per length, Ideal, no fringing, C / ideal. Capacitance per unit length in units of \varepsilon_0, against the ideal \varepsilon_r w/d. Shown when exactly two conductors sit at different potentials with no free charges. The ideal uses the plate width and gap as snapped to the grid.
  • Max |ΔV| from exact. The largest difference between the computed and the exact image potential over all grid nodes, skipping conductors and the three cells around each charge.
  • Max |E| enclosed. The largest field at nodes walled off from the box edge by conductors.
  • SOR sweeps, Last correction. How many red-black sweeps the solver has run, and the largest change made in the last one. The solver stops when that change falls below 10^{-6} of the largest correction.
  • Potential along your line. With the Line tool, drag across the canvas. Solid blue is V along the line; dashed red is the exact solution where the scene has one.
  • Capacitance against plate gap. Twelve capacitors from d = 0.06 to 0.6, each solved from scratch with open walls, as dots over the ideal \varepsilon_r w/d.

References

[1] D. J. Griffiths, Introduction to Electrodynamics, 4th ed. (Pearson, 2013). Ch. 2 "Electrostatics", Ch. 3 "Potentials" and Ch. 4 "Electric Fields in Matter".

[2] J. D. Jackson, Classical Electrodynamics, 3rd ed. (Wiley, 1999). Ch. 1 "Introduction to Electrostatics", Ch. 2 "Boundary-Value Problems in Electrostatics: I" and Ch. 4 "Multipoles, Electrostatics of Macroscopic Media, Dielectrics".

[3] E. M. Purcell and D. J. Morin, Electricity and Magnetism, 3rd ed. (Cambridge University Press, 2013). Ch. 1 to 3 on charges, potential and conductors, Ch. 10 on dielectrics.

[4] M. Faraday, "Experimental researches in electricity, eleventh series," Philosophical Transactions of the Royal Society of London 128, 1-40 (1838). DOI: 10.1098/rstl.1838.0002. Quoted from the reprint in Experimental Researches in Electricity, vol. 1, 2nd ed. (Taylor, 1849), §1173-1174.

[5] M. Faraday, "On static electrical inductive action," Philosophical Magazine 22, 200-204 (1843). DOI: 10.1080/14786444308636351

[6] S. P. Frankel, "Convergence rates of iterative treatments of partial differential equations," Mathematical Tables and Other Aids to Computation 4, 65-75 (1950). DOI: 10.1090/S0025-5718-1950-0046149-3

[7] D. Young, "Iterative methods for solving partial difference equations of elliptic type," Transactions of the American Mathematical Society 76, 92-111 (1954). DOI: 10.1090/S0002-9947-1954-0059635-7

[8] W. H. Press, S. A. Teukolsky, W. T. Vetterling and B. P. Flannery, Numerical Recipes: The Art of Scientific Computing, 3rd ed. (Cambridge University Press, 2007). Ch. 17 "Integration of Ordinary Differential Equations" and Ch. 20 "Partial Differential Equations".

[9] R. A. James, "The solution of Poisson's equation for isolated source distributions," Journal of Computational Physics 25, 71-93 (1977). DOI: 10.1016/0021-9991(77)90013-4

[10] W. E. Lorensen and H. E. Cline, "Marching cubes: A high resolution 3D surface construction algorithm," ACM SIGGRAPH Computer Graphics 21, 163-169 (1987). DOI: 10.1145/37402.37422

[11] J. R. Nuñez, C. R. Anderton and R. S. Renslow, "Optimizing colormaps with consideration for color vision deficiency to enable accurate interpretation of scientific data," PLOS ONE 13, e0199239 (2018). DOI: 10.1371/journal.pone.0199239

[12] H. B. Palmer, "The Capacitance of a Parallel-Plate Capacitor by the Schwartz-Christoffel Transformation," Transactions of the American Institute of Electrical Engineers 56, 363-366 (1937). DOI: 10.1109/T-AIEE.1937.5057547