Benjamin Crowell · Simple Nature Ch. 7 · CC BY-SA 3.0
Moving charges create magnetic fields. Magnetic forces are always perpendicular to velocity, so they change direction without changing speed. Ampere's law relates the field around a wire to the current through it.
The magnetic field
Electric charges at rest create electric fields. Electric charges in motion also create magnetic fields. The magnetic field B is a vector field measured in teslas (T). Unlike electric field lines that start and end on charges, magnetic field lines always form closed loops.
Scheme
; Magnetic field of a long straight wire; B = mu_0 * I / (2 * pi * r); mu_0 = 4*pi*1e-7 T*m/A (permeability of free space)
(define pi 3.14159265)
(define mu0 (* 4 pi 1e-7))
(define (B-wire I r)
(/ (* mu0 I) (* 2 pi r)))
; 10 A current, field at various distances
(display "B at 1 cm: ")
(display (B-wire 100.01))
(display " T") (newline)
(display "B at 5 cm: ")
(display (B-wire 100.05))
(display " T") (newline)
(display "B at 10 cm: ")
(display (B-wire 100.10))
(display " T") (newline)
; Field falls off as 1/r
(display "Ratio B(1cm)/B(10cm): ")
(display (/ (B-wire 100.01) (B-wire 100.10)))
Python
importmath
mu0 = 4 * math.pi * 1e-7def B_wire(I, r):
return mu0 * I / (2 * math.pi * r)
for r in [0.01, 0.05, 0.10]:
print(f"B at {r*100:.0f} cm: {B_wire(10, r):.6e} T")
print(f"Ratio B(1cm)/B(10cm): {B_wire(10, 0.01)/B_wire(10, 0.10):.1f}")
The Lorentz force
A charge q moving with velocity v through a magnetic field B feels a force F = qv x B. The cross product means the force is perpendicular to both the velocity and the field. A positive charge moving right in a field pointing into the page curves upward. This perpendicularity means magnetic forces do no work: they steer, but never speed up or slow down.
Scheme
; Lorentz force: F = q * v * B * sin(theta); For a charge moving perpendicular to B (theta = 90 deg):; F = qvB, and the charge moves in a circle.; Radius of circular motion: r = mv / (qB)
(define (lorentz-force q v B theta)
(* q v B (sin theta)))
(define (cyclotron-radius m v q B)
(/ (* m v) (* q B)))
; Proton in Earth's magnetic field (~50 microT)
(define q-proton 1.6e-19) ; C
(define m-proton 1.67e-27) ; kg
(define v-proton 1e6) ; m/s (1000 km/s)
(define B-earth 50e-6) ; T
(define F (lorentz-force q-proton v-proton B-earth (/ 3.141592)))
(display "Force on proton: ")
(display F) (display " N") (newline)
(define r (cyclotron-radius m-proton v-proton q-proton B-earth))
(display "Cyclotron radius: ")
(display r) (display " m") (newline)
(display "That's about ")
(display (/ r 1000))
(display " km")
Python
importmathdef lorentz_force(q, v, B, theta):
return q * v * B * math.sin(theta)
def cyclotron_radius(m, v, q, B):
return m * v / (q * B)
q = 1.6e-19# proton charge (C)
m = 1.67e-27# proton mass (kg)
v = 1e6# speed (m/s)
B = 50e-6# Earth's field (T)
F = lorentz_force(q, v, B, math.pi/2)
r = cyclotron_radius(m, v, q, B)
print(f"Force: {F:.2e} N")
print(f"Cyclotron radius: {r:.1f} m ({r/1000:.1f} km)")
Ampere's law
Ampere's law says the line integral of B around any closed loop equals mu_0 times the current passing through the loop. In symbols: the integral of B dot dl around a closed path = mu_0 * I_enclosed. This is the magnetic analog of Gauss's law. It's most useful when symmetry lets you pull B out of the integral.
Scheme
; Ampere's law: integral of B . dl = mu0 * I_enclosed; For a circular Amperian loop around a wire:; B * 2*pi*r = mu0 * I; B = mu0*I / (2*pi*r) -- same result as before!
(define pi 3.14159265)
(define mu0 (* 4 pi 1e-7))
; Verify: line integral of B around a circle of radius r
(define (ampere-check I r)
(let ((B (/ (* mu0 I) (* 2 pi r))))
(* B 2 pi r)))
; Should equal mu0 * I regardless of r
(define I 5.0)
(display "mu0 * I = ") (display (* mu0 I)) (newline)
(display "Loop integral (r=0.01): ") (display (ampere-check I 0.01)) (newline)
(display "Loop integral (r=0.10): ") (display (ampere-check I 0.10)) (newline)
(display "Loop integral (r=1.00): ") (display (ampere-check I 1.00)) (newline)
(display "All equal: Ampere's law confirmed.")
Solenoids
A solenoid is a coil of wire. Inside a long solenoid the field is uniform and parallel to the axis: B = mu_0 * n * I, where n is the number of turns per meter. Outside, the field is nearly zero. Solenoids are how we make controllable, uniform magnetic fields.
Scheme
; Solenoid: B = mu0 * n * I; n = N/L (turns per meter)
(define pi 3.14159265)
(define mu0 (* 4 pi 1e-7))
(define (B-solenoid n I)
(* mu0 n I))
; 500 turns over 0.2 m, carrying 3 A
(define N 500)
(define L 0.2)
(define n (/ N L))
(define I 3.0)
(display "Turns per meter: ") (display n) (newline)
(display "B inside solenoid: ")
(display (B-solenoid n I))
(display " T") (newline)
; Compare to Earth's field
(display "Times stronger than Earth's field: ")
(display (/ (B-solenoid n I) 50e-6))
Magnetic flux
Magnetic flux through a surface is the integral of B dot dA. For a uniform field through a flat loop: Phi = B * A * cos(theta). Flux is measured in webers (Wb = T * m^2). Gauss's law for magnetism says the total flux through any closed surface is zero. There are no magnetic monopoles: every field line that enters a surface also exits.
Scheme
; Magnetic flux: Phi = B * A * cos(theta); Gauss's law for magnetism: total flux through closed surface = 0
(define pi 3.14159265)
(define (magnetic-flux B A theta)
(* B A (cos theta)))
; Circular loop of radius 5 cm in a 0.1 T field
(define r 0.05)
(define A (* pi r r))
(define B 0.1)
; Flux at various angles
(display "Flux at 0 deg (face-on): ")
(display (magnetic-flux B A 0))
(display " Wb") (newline)
(display "Flux at 45 deg: ")
(display (magnetic-flux B A (/ pi 4)))
(display " Wb") (newline)
(display "Flux at 90 deg (edge-on): ")
(display (magnetic-flux B A (/ pi 2)))
(display " Wb") (newline)
; At 90 degrees, no field lines pass through
(display "Edge-on flux is zero: ")
(display (< (abs (magnetic-flux B A (/ pi 2))) 1e-15))
Neighbors
Cross-references
Calculus Ch.14 — line integrals: the math behind Ampere's law
All formulas assume SI units. The cross product in the Lorentz force is computed as a scalar magnitude here (q*v*B*sin theta) since our Scheme REPL lacks vector operations. Crowell develops the vector form in detail. The solenoid formula assumes an ideal infinite solenoid; real solenoids have fringe fields at the ends.