The Biot–Savart Law
A current sensor sits from a PCB trace; a compass on the bench is from a coil; an MRI-style coil pair must hold its field uniform to a fraction of a percent. Each question asks the same thing: given a current path of any shape, what is the magnetic field at a point? The school rule (Field of a Straight Wire) covers one infinitely long wire. The Biot–Savart law covers every shape, because it adds up the contribution of each small piece of the path. It is the magnetic counterpart of Coulomb's law (Coulomb's Law and the Electric Field), and in code it is a ten-line function.
The law
A current element at a source point produces at the field point a contribution
where points from the element to the field point. is the magnetic field intensity in ; in free space the flux density is in tesla (Ampère's Circuital Law: H and B explains why there are two fields). Three features are worth seeing in the formula:
- Inverse square, like Coulomb, but the direction is a cross product (The Cross Product): is perpendicular to both the current and the line to the point, so field lines circle the current (right-hand rule).
- An element contributes nothing along its own line ().
- Only closed circuits are physical for steady currents (); a straight segment's field is a building block that only makes sense summed around a loop.
For distributed currents replace by (surface current) or (volume current).
Three results to remember
Finite straight segment. At perpendicular distance from the line of a segment, with the ends seen at angles and measured from the perpendicular foot (signed),
For an infinitely long wire , , so .
Circular loop on its axis. A loop of radius at height below the point:
Far away () this is with the magnetic dipole moment , the same fall-off as an electric dipole (Electric Dipoles and Electrostatic Energy).
Off the axis the loop's field needs complete elliptic integrals and , which SciPy provides; the code below checks a numerical sum against them.
Worked example: a square loop
Given: a square loop of side carrying , in air.
Find: and at the centre, and compare with a circular loop of radius (the inscribed circle).
Solve: each side is at from the centre, with its ends at . The four sides add (all point the same way by the right-hand rule):
Check: the square's wire is against the circle's , yet its centre field is 10 % smaller: the square's corners are farther away and the field falls as . Both are about a quarter of the Earth's field ( to ), which is why a compass near a loop barely moves.
In Python: a numerical Biot–Savart solver
The function cuts any closed path into straight segments and sums at each segment's midpoint, vectorised with NumPy. It reproduces the square loop, converges to the exact elliptic-integral field of a circular loop at an off-axis point, and then shows why a Helmholtz pair (two coaxial loops one radius apart) is the standard way to make a uniform field.
import numpy as np
from scipy.special import ellipk, ellipe
MU0 = 4e-7 * np.pi
def biot_savart(path, I, P):
"""B (T) at point P from a closed polyline path (N x 3, m) carrying I (A)."""
a, b = path[:-1], path[1:]
dl, R = b - a, P - 0.5 * (a + b)
Rn = np.linalg.norm(R, axis=1)[:, None]
return MU0 * I / (4 * np.pi) * np.sum(np.cross(dl, R) / Rn**3, axis=0)
def loop_path(a, n):
t = np.linspace(0, 2 * np.pi, n + 1)
return np.column_stack([a * np.cos(t), a * np.sin(t), np.zeros_like(t)])
def loop_exact(a, I, rho, z):
"""Exact (B_rho, B_z) of a circular loop of radius a in the plane z = 0."""
q = (a + rho)**2 + z**2
m = 4 * a * rho / q
K, E = ellipk(m), ellipe(m)
d = (a - rho)**2 + z**2
Bz = MU0 * I / (2 * np.pi * np.sqrt(q)) * (K + (a*a - rho*rho - z*z) / d * E)
Br = MU0 * I * z / (2 * np.pi * rho * np.sqrt(q)) * (-K + (a*a + rho*rho + z*z) / d * E)
return Br, Bz
# square loop, side 0.1 m, 1 A, 100 segments per side
c = np.array([[0.05, 0.05, 0], [-0.05, 0.05, 0], [-0.05, -0.05, 0], [0.05, -0.05, 0], [0.05, 0.05, 0]])
square = np.vstack([np.linspace(c[i], c[i + 1], 101)[:-1] for i in range(4)] + [c[:1]])
B = biot_savart(square, 1.0, np.zeros(3))
print(f"square loop centre: Bz = {B[2]*1e6:.3f} uT, hand 2*sqrt(2)*mu0*I/(pi*L) = "
f"{2*np.sqrt(2)*MU0/(np.pi*0.1)*1e6:.3f} uT")
a, I, P = 0.05, 1.0, np.array([0.03, 0.0, 0.02]) # loop radius 5 cm; point rho = 3 cm, z = 2 cm
for n in (12, 48, 400):
B = biot_savart(loop_path(a, n), I, P)
print(f"loop, {n:3d} segments: Brho = {B[0]*1e6:.4f} uT, Bz = {B[2]*1e6:.4f} uT")
Br, Bz = loop_exact(a, I, 0.03, 0.02)
print(f"loop, exact: Brho = {Br*1e6:.4f} uT, Bz = {Bz*1e6:.4f} uT")
print("Helmholtz pair (loops at z = -a/2 and +a/2), field on the axis:")
z = np.linspace(-0.5 * a, 0.5 * a, 5)
Bpair = [loop_exact(a, I, 1e-12, zi - a/2)[1] + loop_exact(a, I, 1e-12, zi + a/2)[1] for zi in z]
for zi, b in zip(z, Bpair):
print(f" z = {zi*1e3:6.1f} mm: Bz = {b*1e6:.3f} uT ({(b / Bpair[2] - 1)*100:+.3f} %)")square loop centre: Bz = 11.314 uT, hand 2*sqrt(2)*mu0*I/(pi*L) = 11.314 uT
loop, 12 segments: Brho = 5.0335 uT, Bz = 10.3522 uT
loop, 48 segments: Brho = 4.5782 uT, Bz = 10.1535 uT
loop, 400 segments: Brho = 4.5486 uT, Bz = 10.1388 uT
loop, exact: Brho = 4.5482 uT, Bz = 10.1386 uT
Helmholtz pair (loops at z = -a/2 and +a/2), field on the axis:
z = -25.0 mm: Bz = 17.009 uT (-5.418 %)
z = -12.5 mm: Bz = 17.908 uT (-0.420 %)
z = 0.0 mm: Bz = 17.984 uT (+0.000 %)
z = 12.5 mm: Bz = 17.908 uT (-0.420 %)
z = 25.0 mm: Bz = 17.009 uT (-5.418 %)
The midpoint sum converges roughly as : 12 segments are 2 % off in , 400 segments agree with the exact field to 4 digits. In the Helmholtz pair the first three derivatives of vanish at the centre, so the field stays within over the middle half of the gap; the centre value is per ampere-turn.
Guided lab: map the field of a coil
Hand calculation. A flat coil of turns, mean radius , at : ; on the axis at it falls by to .
Simulation. Use biot_savart with 50 turns as one loop of , or as a short helix, and print every along the axis.
What you would measure. Wind the coil on a cardboard former with enamelled wire of about (its resistance is about ). Drive it from a bench supply in constant-current mode at (voltage limit ). Measure with a ratiometric linear Hall sensor on a supply (typical sensitivities are about to per , so expect roughly to of change at the centre; Position, Light and Hall Sensors) or with a phone's magnetometer. Subtract the reading with the current off (the Earth's field and the bench steel), or reverse the current and take half the difference. Expect agreement within 5 to 10 %: the sensor's own calibration, its position ( near the coil changes by several percent) and the winding's real radius dominate. Plot measured against computed .
Hazards and safe setup. Low voltage, current-limited. The coil warms slowly at ; check it by touch after a few minutes. If you switch the current with a switch rather than the supply's output button, put a diode across the coil (cathode to the positive end) to absorb the inductive kick.
Pitfalls
- Wrong direction of . It points from the source element to the field point; reversing it flips the field.
- Evaluating on the wire. The thin-wire formula diverges at ; inside a real conductor use the volume form or Ampère's law.
- Too few segments near the point. A field point close to the wire needs segments shorter than the distance to it.
- Forgetting the background. The Earth's field ( to ) is the size of a loop's field; always subtract a zero-current reading.
Practice
- A straight wire long carries . Find at from its midpoint and compare with the infinite-wire value.
- What current in a single circular loop of radius gives at its centre?
- A loop's on-axis field is at the centre. What is it at ?
Answer
- , so (); infinite wire: , only 0.5 % more.
- .
- , so .
Test yourself
In , the vector points…
- from the field point to the current element
- from the current element to the field point
- along the current
- radially out of the wire's axis only
The field at the centre of a circular loop of radius carrying is…
Far from a small current loop along its axis, the field falls off as…
A Helmholtz pair spaces two identical coaxial loops by…
- one radius
- one diameter
- half a radius
- two diameters