Electromagnetism
Four equations, one unification, and the realization that light is a ripple in the same field that holds a magnet to your fridge. After reading you will see why motors spin, why antennas work, and why every piece of electronics on Earth rests on Maxwell's 1865 math.
1. Why electromagnetism is the engineering workhorse
Classical mechanics handles things you can push and pull directly. Electromagnetism handles the forces that reach across empty space — the pull of a magnet, the shock from a doorknob on a dry winter day, the spark of a lightning bolt. For two centuries before 1820 these were thought to be separate phenomena. Then Hans Christian Ørsted noticed that a current-carrying wire deflected a compass needle, and within half a century electricity and magnetism had been fused into a single theory that also explained light. It is one of the cleanest unifications in the history of physics.
The practical payoff is enormous. Every generator, motor, transformer, and power line is an application of Faraday's law. Every antenna, radio, and fiber-optic cable is an application of Maxwell's wave equation. Every transistor and memory cell in every chip depends on how electrons move in electric and magnetic fields inside crystalline lattices. The computer you are reading this on is an electromagnetism problem from the power supply outward.
Charges create electric fields. Moving charges create magnetic fields. Changing electric fields create magnetic fields, and changing magnetic fields create electric fields. Put those four ideas together and you get Maxwell's equations, whose solutions include waves that propagate at a speed you can compute from two constants in the lab. That speed turns out to be the speed of light. That is not a coincidence — light is an electromagnetic wave.
Three reasons to care if you are not a physicist:
- Hardware. If you design, debug, or just want to understand any electrical device, you need a working command of fields, circuits, and Ohm's law.
- Communications. Wi-Fi, 5G, radar, optical fiber, satellite links — all are engineered solutions to Maxwell's equations with specific boundary conditions.
- Chemistry and materials. Chemical bonds are electrostatic. Semiconductors, superconductors, and batteries are all electromagnetism inside matter.
2. Vocabulary cheat sheet
The symbols you will see repeatedly. Defined more carefully below.
| Symbol | Read as | Means |
|---|---|---|
| $q$, $Q$ | "q" or "Q" | Electric charge. SI unit: coulomb (C). Comes in integer multiples of $e = 1.6\times 10^{-19}$ C. |
| $\mathbf{E}$ | "E (bold)" | Electric field — force per unit test charge. Units: V/m or N/C. |
| $\mathbf{B}$ | "B (bold)" | Magnetic field. Units: tesla (T). The name is from Nikola Tesla; 1 T is a huge magnet. |
| $V$, $\varphi$ | "V" or "phi" | Electric potential — potential energy per unit charge. Unit: volt. |
| $I$ | "I" | Electric current. Charge per unit time. Unit: ampere (A), $1\,\text{A} = 1\,\text{C/s}$. |
| $\epsilon_0$ | "epsilon nought" | Permittivity of free space, $\approx 8.85 \times 10^{-12}\,\text{F/m}$. Measures how easily electric fields form in vacuum. |
| $\mu_0$ | "mu nought" | Permeability of free space, $4\pi\times 10^{-7}\,\text{T}\cdot\text{m/A}$. Measures how easily magnetic fields form in vacuum. |
| $c$ | "c" | Speed of light in vacuum, $c = 1/\sqrt{\mu_0 \epsilon_0} \approx 3\times 10^8\,\text{m/s}$. |
| $\Phi_B$ | "phi-B" | Magnetic flux through a surface. Unit: weber (Wb). |
| $\nabla\cdot$, $\nabla\times$ | "div" and "curl" | Vector calculus operators — divergence and curl — that measure how fields spread out and circulate. |
One warning about units: this page uses SI (Système International), which is what engineers and most modern textbooks use. Older physics textbooks, especially Jackson, use Gaussian units where Coulomb's law has no $4\pi\epsilon_0$ and factors of $c$ appear in Maxwell's equations instead. The physics is the same; the constants are shuffled around. If you see a formula that looks slightly wrong, check the units.
3. Electric field and Coulomb's law
Two charges at rest attract or repel each other with a force that falls off as the square of the distance between them. Like charges repel, unlike charges attract. Charles-Augustin de Coulomb measured this law with a torsion balance in 1785. In modern notation:
Coulomb's law
- $\mathbf{F}_{12}$
- Force on charge 1 due to charge 2. A vector. By Newton's third law, the force on charge 2 due to charge 1 is equal and opposite.
- $q_1, q_2$
- The two charges, in coulombs. Can be positive or negative.
- $r$
- Distance between them, in meters.
- $\hat{\mathbf{r}}$
- Unit vector pointing from charge 2 to charge 1. Tells you the direction; the magnitude is encoded in the scalar part.
- $1/(4\pi\epsilon_0)$
- Coulomb's constant, $k_e \approx 8.99 \times 10^9\,\text{N}\cdot\text{m}^2/\text{C}^2$. The $4\pi$ is there so that Gauss's law below looks clean; it is a bookkeeping choice.
Sign convention. If $q_1 q_2 > 0$ (same signs), the force is along $+\hat{\mathbf{r}}$, pushing them apart. If $q_1 q_2 < 0$ (opposite signs), the force is along $-\hat{\mathbf{r}}$, pulling them together. Coulomb's law looks exactly like Newton's inverse-square law for gravity, with charge replacing mass. The difference is that charges come in two flavors and can cancel, while mass only attracts.
Rather than talk about forces between pairs of charges, it is usually cleaner to introduce the electric field $\mathbf{E}$, defined as the force per unit positive test charge:
Electric field from point charges
- $\mathbf{E}(\mathbf{r})$
- The electric field vector at the field point $\mathbf{r}$. Tells you the force a unit positive charge would feel if placed there.
- $q_i$
- The $i$-th source charge.
- $\mathbf{r}_i$
- Position of the $i$-th source charge.
- $|\mathbf{r} - \mathbf{r}_i|$
- Distance from the $i$-th source charge to the field point.
- $\hat{\mathbf{r}}_i$
- Unit vector from the $i$-th source charge to the field point.
- $\sum_i$
- Sum over all source charges — this is the principle of superposition: fields from multiple charges simply add vectorially.
Why fields, not forces. The field is a property of the region of space, independent of whether there is a test charge there to feel it. You can compute $\mathbf{E}$ once, then ask about the force on any charge just by multiplying: $\mathbf{F} = q\mathbf{E}$. It also sets up the mental picture you'll need for Maxwell's equations and for the idea that fields carry energy and momentum of their own, independent of any particles.
4. Gauss's law — symmetry makes the integrals trivial
Summing Coulomb's law over a complicated charge distribution is painful. Gauss's law is a shortcut that works whenever the problem has enough symmetry. It relates the total electric flux through a closed surface to the charge enclosed:
Gauss's law (integral form)
- $\oint$
- A closed-surface integral — integrate over the entire boundary of some 3D region.
- $\mathbf{E}\cdot d\mathbf{A}$
- The electric field dotted with an outward-pointing area element. Measures how much field is piercing through that patch of surface.
- $\partial\mathcal V$
- The boundary of the volume $\mathcal V$ — the Gaussian surface. You are free to choose any closed surface; symmetry tells you which choice makes the integral trivial.
- $Q_\text{enc}$
- The total charge enclosed inside that surface. Charges outside the surface contribute nothing to the total flux, though they contribute plenty to the local field.
- $\epsilon_0$
- Permittivity of free space — the same constant from Coulomb's law.
The trick. Gauss's law is always true, but it is only useful when the symmetry of the problem lets you pull $\mathbf{E}$ out of the integral. For a spherical charge distribution, a concentric spherical Gaussian surface gives $|\mathbf{E}| \cdot 4\pi r^2 = Q/\epsilon_0$, so $|\mathbf{E}| = Q/(4\pi\epsilon_0 r^2)$ — you just recovered Coulomb's law in one line. For an infinite line of charge, a coaxial cylinder gives $|\mathbf{E}| \propto 1/r$. For an infinite sheet, a pillbox gives $|\mathbf{E}| = \sigma/(2\epsilon_0)$, independent of distance. Three problems, three symmetry choices, three trivial integrals.
Worked example: uniformly charged sphere
A solid sphere of radius $R$ carries total charge $Q$ spread uniformly through its volume. Find the field inside and outside.
Outside ($r > R$): draw a concentric spherical surface of radius $r$. By symmetry, $\mathbf{E}$ points radially outward and has the same magnitude everywhere on the surface. Flux is $|\mathbf{E}|\cdot 4\pi r^2$, and enclosed charge is $Q$. So:
Field outside a uniform sphere
- $Q$
- Total enclosed charge.
- $4\pi r^2$
- Surface area of the Gaussian sphere.
- $r$
- Distance from the sphere's center to the field point.
The shell theorem. This looks exactly like the field of a point charge $Q$ at the sphere's center. Outside any spherically symmetric distribution, the field is identical to a point charge at the center. Newton proved the same thing for gravity. It is a happy consequence of the inverse-square law and spherical symmetry.
Inside ($r < R$): the same Gaussian surface, but now it only encloses a fraction of the charge. The fraction is the ratio of volumes, $r^3/R^3$. So:
Field inside a uniform sphere
- $Qr^3/R^3$
- The enclosed charge inside a Gaussian sphere of radius $r$ — total charge times the volume fraction.
- $r$
- Same as before, but now $r < R$.
Linear inside, inverse-square outside. Inside, the field grows linearly with $r$ — it is zero at the center (by symmetry) and rises to $Q/(4\pi\epsilon_0 R^2)$ at the surface. Outside, it falls off as $1/r^2$. The two pieces match at $r = R$, so the field is continuous even though its functional form changes. Plot it and you see a triangle rising to a peak then decaying.
5. Electric potential and capacitance
For static electric fields (no time dependence), the work done moving a charge from one point to another depends only on the endpoints, not the path. This lets you define a scalar potential $V$ from which the field is derivable:
Electric potential
- $V(\mathbf{r})$
- Electric potential at point $\mathbf{r}$, in volts. Potential energy per unit charge.
- $-\nabla V$
- Negative gradient of $V$. Same relation as force from potential energy in mechanics — electric field "points downhill" on the potential landscape.
- $1/|\mathbf{r}-\mathbf{r}_i|$
- Notice the single inverse power, not inverse-square. Integrating $E \sim 1/r^2$ gives $V \sim 1/r$.
Why scalar fields are nice. Adding potentials from many charges is a simple scalar sum — no vector components to juggle. You compute $V$ from a point-charge distribution by adding, then take the gradient to get $\mathbf{E}$. Much easier than vector superposition of fields, especially for complicated geometries. The potential is also what voltmeters measure: a voltage reading is a difference in electric potential between two probe points.
A capacitor is two conductors that store opposite charges $+Q$ and $-Q$ separated by a gap. The relationship $Q = C V$ defines the capacitance $C$, measured in farads. For a parallel-plate capacitor with plate area $A$ and separation $d$:
Parallel-plate capacitor
- $C$
- Capacitance. How much charge you can store per volt of potential difference.
- $A$
- Plate area.
- $d$
- Plate separation.
- $U$
- Energy stored in the capacitor — equivalent to the energy stored in the electric field between the plates.
Where the energy goes. Filling a capacitor takes work because you have to push like charges together against their own repulsion. That work is stored in the electric field in the gap. The energy density of an electric field is $u_E = \tfrac{1}{2}\epsilon_0 |\mathbf{E}|^2$, so electric fields themselves carry energy — not just the particles in them. This is the first hint that fields are physical objects, not mathematical conveniences.
6. Current, resistance, and DC circuits
When charges move through a conductor, the flow is called electric current. For steady flow, Ohm's law relates the voltage drop $V$ across a resistor to the current $I$ through it:
Ohm's law and power
- $V$
- Voltage drop (potential difference) across the resistor, in volts.
- $I$
- Current through the resistor, in amperes. One ampere is one coulomb per second.
- $R$
- Resistance, in ohms. Depends on the material, geometry, and temperature.
- $P$
- Power dissipated — the rate at which electrical energy is turned into heat. Units: watts.
The water analogy. Voltage is pressure, current is flow rate, and resistance is pipe narrowness. More pressure pushes more water through a pipe of fixed narrowness. A thin pipe resists more. The power $I^2 R$ dissipated is like the heat you'd generate forcing water through a small hole — the resistor's job description is "convert electrical work into heat." This is what every electric heater and incandescent bulb does deliberately, and what every CPU does by accident.
For circuits, you combine Ohm's law with Kirchhoff's laws: at any node, current in equals current out (conservation of charge); around any loop, the voltage drops sum to zero (conservation of energy). Resistors in series add: $R_\text{tot} = R_1 + R_2$. Resistors in parallel combine via reciprocals: $1/R_\text{tot} = 1/R_1 + 1/R_2$. With these three rules you can analyze any DC resistor network, though for large networks you'd turn to linear algebra — every DC circuit is a sparse linear system in the node voltages.
7. Magnetic field and the Lorentz force
Moving charges create magnetic fields and feel forces from them. The Lorentz force law gives the total force on a charge $q$ moving with velocity $\mathbf{v}$ in fields $\mathbf{E}$ and $\mathbf{B}$:
Lorentz force
- $q$
- The charge feeling the force.
- $\mathbf{E}$
- Local electric field.
- $\mathbf{v}\times\mathbf{B}$
- Cross product of the particle's velocity with the local magnetic field. Perpendicular to both $\mathbf{v}$ and $\mathbf{B}$.
- $\mathbf{B}$
- Local magnetic field.
Three things the Lorentz law tells you. First, a stationary charge feels no magnetic force — magnetic fields only act on moving charges. Second, the magnetic force is always perpendicular to the velocity, so it changes the direction of motion but not the speed — magnetic fields do no work on point charges. Third, charges moving in a uniform magnetic field travel in circles (or helixes if they have a velocity component along the field). This is the principle behind cyclotrons, mass spectrometers, and the funnels that guide electron beams in old CRT televisions.
For a charged particle moving perpendicular to a uniform magnetic field, the circular-motion condition $qvB = mv^2/r$ gives the cyclotron radius and frequency:
Cyclotron motion
- $r$
- Radius of the circular orbit. Proportional to speed, inversely proportional to field strength. Fast particles orbit larger circles.
- $\omega_c$
- Angular frequency of the circular motion, independent of the particle's speed. This speed-independence is what made the cyclotron work.
- $m, q$
- Mass and charge of the particle.
Why mass spectrometers work. For two particles with the same charge but different masses sent through the same field at the same speed, the heavier one traces a bigger circle. Fire a beam of ionized atoms into a magnetic field and each isotope lands at a different place on the detector plate. This is how isotope abundances are measured and how trace chemicals are identified by their characteristic mass spectra.
Ampère's law is the magnetic analog of Gauss's law: the line integral of $\mathbf{B}$ around a closed loop equals $\mu_0$ times the enclosed current.
Ampère's law (static form)
- $\oint_C$
- Integral around a closed loop $C$ — an Amperian loop, chosen for symmetry.
- $\mathbf{B}\cdot d\boldsymbol{\ell}$
- Magnetic field dotted with an infinitesimal directed segment of the loop.
- $\mu_0$
- Permeability of free space, $4\pi\times 10^{-7}\,\text{T}\cdot\text{m/A}$.
- $I_\text{enc}$
- Current piercing any surface bounded by the loop.
Same trick as Gauss. For a long straight wire, draw a circular loop around it: $|\mathbf{B}|\cdot 2\pi r = \mu_0 I$, so $|\mathbf{B}| = \mu_0 I / (2\pi r)$. For a solenoid, draw a rectangle with one side inside and one outside: $|\mathbf{B}| = \mu_0 n I$ inside, 0 outside. Two problems, two symmetry choices, two trivial integrals. Maxwell later added a correction term (the displacement current) to make Ampère's law work when fields change in time — that correction is what makes electromagnetic waves possible.
8. Faraday's law and induction
In 1831, Michael Faraday discovered that a changing magnetic flux through a loop induces an electric field around the loop. This is the principle behind every electric generator and transformer ever built. In equation form:
Faraday's law
- $\Phi_B$
- Magnetic flux through surface $S$ — integrate $\mathbf{B}\cdot d\mathbf{A}$ over the surface.
- $d\Phi_B/dt$
- Rate of change of that flux with time.
- $\oint \mathbf{E}\cdot d\boldsymbol{\ell}$
- Electromotive force (EMF) around a closed loop — the line integral of the induced electric field.
- The minus sign
- Lenz's law: the induced current flows in whichever direction opposes the change in flux. If the flux through a loop is increasing, the induced current tries to create a flux that cancels the increase.
Why generators work. Spin a coil of wire inside a fixed magnet (or a fixed magnet inside a stationary coil). The flux through the coil varies sinusoidally, so the induced EMF is sinusoidal, and alternating current flows in the wire. This is every power plant's output stage. The energy comes from whatever is doing the spinning — steam from nuclear or coal, water from a dam, wind from a turbine. The physics is identical. A transformer uses the same principle with two coils sharing flux through an iron core: the primary's varying current creates varying flux which induces an EMF in the secondary. Voltage ratios match turn ratios.
Faraday's discovery is what unified electricity and magnetism into a single subject. Before 1831 you could still pretend they were separate phenomena that just happened to interact; after 1831 it was clear they were inseparable. The electric field and the magnetic field are two aspects of one object: the electromagnetic field.
9. Interactive: field from a small charge array
Below is a snapshot of the electric field produced by up to three point charges. Drag the charge-strength sliders to change each charge (positive or negative). The small arrows show the field direction and relative magnitude at a grid of sample points.
Electric field vectors from up to three point charges. Arrow length is proportional to field magnitude (capped for readability). Positive charges render cyan, negative pink, dipole neutral.
Things to try:
- Equal and opposite charges. Set $q_1 = +2$, $q_2 = -2$, $q_3 = 0$ for a classic dipole. You will see field lines emerging from the positive charge, curving through space, and terminating at the negative.
- Equal same-sign charges. Set $q_1 = q_2 = +2$. The field between them cancels near the midpoint and is purely repulsive outside.
- Three-charge configuration. Add charge 3 and watch how the field rearranges. Notice that superposition means you can almost predict the result by imagining adding the individual fields one at a time.
10. Maxwell's equations
James Clerk Maxwell collected the laws of electricity and magnetism into four equations, added one crucial correction term to Ampère's law (the displacement current), and published the full theory in 1865. In SI units and differential form:
Gauss's laws (for E and B)
- $\nabla\cdot\mathbf{E}$
- Divergence of the electric field — measures how much the field "spreads out" from a point.
- $\rho$
- Electric charge density, in coulombs per cubic meter. Local amount of charge per unit volume.
- $\nabla\cdot\mathbf{B} = 0$
- The magnetic field has no divergence anywhere. In other words, magnetic monopoles do not exist — every magnetic field line that enters a closed region must also leave it. If you cut a bar magnet in half, you get two smaller bar magnets, not an isolated north and south pole.
What divergence means. Think of a fluid. The divergence of its velocity field at a point tells you whether fluid is being created or destroyed there. $\nabla\cdot\mathbf{E} = \rho/\epsilon_0$ says electric field lines are created at positive charges and destroyed at negative charges, with strength proportional to the local charge density. $\nabla\cdot\mathbf{B} = 0$ says magnetic field lines have nowhere to start or end — they always form closed loops.
Faraday's and Ampère-Maxwell laws
- $\nabla\times\mathbf{E}$
- Curl of the electric field — measures how much the field circulates around a point.
- $-\partial\mathbf{B}/\partial t$
- Negative time derivative of the magnetic field. A changing $\mathbf{B}$ drives a curling $\mathbf{E}$. This is Faraday's law in differential form.
- $\mathbf{J}$
- Electric current density, in amperes per square meter.
- $\mu_0 \mathbf{J}$
- Ampère's original source term: currents produce curling magnetic fields.
- $\mu_0 \epsilon_0\,\partial\mathbf{E}/\partial t$
- Maxwell's displacement current — a changing electric field also produces a curling magnetic field, even in empty space with no actual current. Without this term, the equations would be mathematically inconsistent and electromagnetic waves would not exist.
What Maxwell noticed. Ampère's original law said only real currents produced magnetic fields. Maxwell realized that if you apply this to a capacitor being charged — current flows into the plates but not through the gap — you get a contradiction at the capacitor gap. His fix: the changing electric field between the plates acts like a current for the purpose of magnetic generation. Add this term and the four equations together become self-consistent and predict that ripples in the field propagate as transverse waves at speed $1/\sqrt{\mu_0\epsilon_0}$. Maxwell computed this number and got $3\times 10^8$ m/s, matching measurements of the speed of light. "We can scarcely avoid the inference," he wrote, "that light consists in the transverse undulations of the same medium which is the cause of electric and magnetic phenomena." Unification.
11. Electromagnetic waves
In a region with no charges or currents ($\rho = 0$, $\mathbf{J} = \mathbf{0}$), Maxwell's equations reduce to coupled curl equations for $\mathbf{E}$ and $\mathbf{B}$. Take the curl of one and substitute the other and you get separate wave equations for each field:
Electromagnetic wave equation
- $\nabla^2$
- The Laplacian — sum of second partial derivatives, $\partial^2/\partial x^2 + \partial^2/\partial y^2 + \partial^2/\partial z^2$.
- $\partial^2/\partial t^2$
- Second partial derivative with respect to time.
- $c$
- The speed of light in vacuum, $2.998 \times 10^8$ m/s. Comes out of the equations as $1/\sqrt{\mu_0\epsilon_0}$, with no reference to light.
Why this is a wave equation. The standard form $\nabla^2 f = (1/c^2) \partial^2 f/\partial t^2$ describes any quantity that propagates as a wave at speed $c$. Plane-wave solutions like $\mathbf{E} = \mathbf{E}_0 \cos(kx - \omega t)$ with $\omega/k = c$ satisfy it immediately. The $\mathbf{E}$ and $\mathbf{B}$ fields are perpendicular to each other and to the direction of propagation, with amplitudes related by $|\mathbf{B}| = |\mathbf{E}|/c$. They oscillate in step, shedding energy as they go.
Different frequencies of electromagnetic wave get different names: radio, microwave, infrared, visible, ultraviolet, X-ray, gamma ray. It is one continuous spectrum, differing only in wavelength. Human eyes evolved to detect the narrow band where the Sun emits most of its power and Earth's atmosphere is transparent — roughly 400–700 nm. Everything we call "light" and everything we call "radio" is the same phenomenon: ripples in the electromagnetic field, propagating at the speed $c$.
12. Electromagnetism in code
Here is the most basic simulation of EM fields — computing the electric field of a small collection of point charges on a grid and rendering it as a vector field. This is the same calculation the interactive figure above does, but laid out for reading.
import numpy as np
# ---------- Electric field of a set of point charges ----------
def efield(charges, positions, X, Y):
# charges : array of scalars (coulombs or arbitrary units)
# positions: array of shape (N, 2) with (x_i, y_i)
# X, Y : meshgrid of field-point coordinates
# Returns Ex, Ey arrays with same shape as X.
Ex = np.zeros_like(X)
Ey = np.zeros_like(Y)
k = 1.0 # 1 / (4 pi eps0), set to 1 for illustration
for q, (qx, qy) in zip(charges, positions):
dx = X - qx
dy = Y - qy
r2 = dx * dx + dy * dy + 1e-6 # soften at the charge itself
r3 = r2 ** 1.5
Ex += k * q * dx / r3
Ey += k * q * dy / r3
return Ex, Ey
# Dipole on a 40x40 grid
gx = np.linspace(-3, 3, 40)
gy = np.linspace(-2, 2, 40)
X, Y = np.meshgrid(gx, gy)
Ex, Ey = efield(charges=[1, -1], positions=[(-1, 0), (1, 0)], X=X, Y=Y)
mag = np.sqrt(Ex ** 2 + Ey ** 2)
print(f"max |E| = {mag.max():.3f}, min = {mag.min():.3f}")
# ---------- Gauss's law check (in 2D, integrate over a disk) ----------
# For a single point charge q at the origin, integrate E dot n dA
# over a circle of radius R. Should equal 2 pi q (the 2D analog).
q = 1.0
R = 1.5
Nang = 400
th = np.linspace(0, 2 * np.pi, Nang, endpoint=False)
dtheta = 2 * np.pi / Nang
xs = R * np.cos(th)
ys = R * np.sin(th)
Ex_c, Ey_c = efield([q], [(0, 0)], xs, ys)
# Outward normal = (cos th, sin th); line element = R dtheta.
flux = np.sum((Ex_c * np.cos(th) + Ey_c * np.sin(th)) * R * dtheta)
print(f"enclosed flux = {flux:.4f}, 2 pi q = {2 * np.pi * q:.4f}")
import math
# Same dipole field without NumPy.
def efield_at(charges, positions, x, y):
Ex = Ey = 0.0
for q, (qx, qy) in zip(charges, positions):
dx = x - qx
dy = y - qy
r2 = dx * dx + dy * dy + 1e-6
r3 = r2 ** 1.5
Ex += q * dx / r3
Ey += q * dy / r3
return Ex, Ey
charges = [1, -1]
positions = [(-1, 0), (1, 0)]
Ex, Ey = efield_at(charges, positions, x=0, y=1)
print(f"Field at (0, 1): Ex={Ex:.3f}, Ey={Ey:.3f}")
# Rough Gauss flux around a unit circle centered at a single charge
def gauss_flux(q, R, N=400):
total = 0.0
for i in range(N):
th = 2 * math.pi * i / N
x, y = R * math.cos(th), R * math.sin(th)
Ex, Ey = efield_at([q], [(0, 0)], x, y)
total += (Ex * math.cos(th) + Ey * math.sin(th)) * R * (2 * math.pi / N)
return total
print(f"flux = {gauss_flux(1, 1.5):.4f} (expected {2 * math.pi:.4f})")
A couple of notes:
- Softening at the source. The $r^{-2}$ divergence at a point charge would give infinities on a grid that happens to land near a charge. The small additive $10^{-6}$ in $r^2$ is a standard numerical trick that keeps the answer finite at the cost of a tiny bias near the source. Real plasma simulations and N-body gravity codes use similar regularizations.
- Numerical Gauss check. The second block shows that the numerical flux around a loop really does match the analytical expectation. This is a quick sanity test you can always run when you are not sure your field code is correct.
13. Cheat sheet and see also
Coulomb's law
$\mathbf{F} = \dfrac{k_e q_1 q_2}{r^2}\hat{\mathbf{r}}$
Electric field
$\mathbf{E} = \mathbf{F}/q$
Gauss's law
$\oint\mathbf{E}\cdot d\mathbf{A} = Q_\text{enc}/\epsilon_0$
Potential
$\mathbf{E} = -\nabla V$
Ohm's law
$V = IR$
Lorentz force
$\mathbf{F} = q(\mathbf{E} + \mathbf{v}\times\mathbf{B})$
Ampère's law
$\oint\mathbf{B}\cdot d\boldsymbol{\ell} = \mu_0 I_\text{enc}$
Faraday's law
$\text{EMF} = -d\Phi_B/dt$
Maxwell's equations
Four coupled field laws
Speed of light
$c = 1/\sqrt{\mu_0 \epsilon_0}$
See also
Physics: Classical Mechanics
The Lorentz force acts on charged particles; to know how they move you combine it with Newton's second law. Lagrangians for charged particles pick up a velocity-dependent potential $q\mathbf{v}\cdot\mathbf{A}$.
Physics: Special Relativity
Maxwell's equations were already Lorentz-invariant, which is how Einstein got pushed toward relativity. $\mathbf{E}$ and $\mathbf{B}$ transform into each other under boosts; they are really one object, the electromagnetic field tensor.
Physics: Quantum Mechanics
Atomic spectra, photons, and the photoelectric effect all force you to quantize the electromagnetic field. Do that cleanly and you get quantum electrodynamics (QED), the most precisely tested theory in physics.
Math: Calculus
Divergence, curl, gradient, and the Laplacian — the vector calculus that Maxwell wrote his equations in — is a chapter of multivariable calculus.
Math: Linear Algebra
Circuits are linear systems; field theory uses tensors; Fourier analysis of waves is linear algebra in disguise.
AI: Foundation Models
Training runs on hardware that is one giant electromagnetism problem — power delivery, signal integrity, and heat extraction. Data center design is Maxwell's equations plus thermodynamics.
Further reading
- Richard Feynman, Robert Leighton, Matthew Sands — The Feynman Lectures on Physics, Vol. 2 (1964). Feynman's take on electromagnetism; conceptually the clearest undergraduate text written in English, and free at feynmanlectures.caltech.edu.
- David Griffiths — Introduction to Electrodynamics (4th ed., 2012). The standard undergraduate textbook. Excellent problem sets; readable voice.
- John David Jackson — Classical Electrodynamics (3rd ed., 1999). The graduate-level bible. Uses SI in the 3rd edition; the 2nd edition used Gaussian. Dense but comprehensive.
- James Clerk Maxwell — A Treatise on Electricity and Magnetism (1873). Two-volume original in (mostly) quaternion notation. Of historical and philosophical interest; do not try to learn from it.
- Wikipedia — Maxwell's equations. Good modern summary with history, units, and reformulations.
- MIT OCW — Electricity and Magnetism (8.02). Walter Lewin's famous demonstrations are on YouTube and still the best video introduction for engineers.