B5 · Lesson 14 · Magnetic field lab
Biot–Savart in code, uniform-field coils, solenoids, orbits and a Hall measurement
Every magnetic field in this unit came from a symmetric shape: an infinite wire, a circular loop, an ideal solenoid. Real coils are square, short, or bent around a sensor, and the Biot–Savart law handles them all if you add up enough small pieces of current. In this lab you'll write that sum, check it against the shapes you know, design a Helmholtz pair for a uniform field, build a finite solenoid out of loops, track a charge through a field with a method that keeps its speed exact, and pull a carrier density out of noisy Hall data.
- Two coaxial coils of radius R carry equal currents. The curve is the field along their shared axis, relative to its value at the midpoint, as you move along the axis.
- Set the spacing to R: the curve is flattest there, the Helmholtz condition, where the field's second derivative at the center vanishes.
- Closer coils give a dip at the center, wider ones a hump. The readout gives the field 0.1R from the center, relative to the center.
Predict
A Helmholtz pair of 100-turn coils, each 10 cm in radius, carries 1 A. What is the field at the center, compared with one coil alone at its own center?
About 1.43 times. Each coil sits half a radius from the center, where its field has fallen to of its own center value, and two of them give 1.43. That's 899 µT here, against 628 µT for one coil at its center. The pair trades some strength for uniformity.
Name it
Biot–Savart in pieces
A short piece of wire carrying I contributes at a point a displacement r away. Split any path into many short pieces, put each piece's current at its midpoint, and add the contributions. Check the sum on shapes with known answers: a circle's center (), its axis, and a square's center ().
Helmholtz coils
Two coaxial coils of radius R spaced R apart give a field at the center of , uniform to about 1 part in 10 000 within 0.1R of the center. Calibration coils for magnetometers and setups that cancel the Earth's field use them.
Finite solenoids
A solenoid is a stack of loops. On its axis, a solenoid of length L and radius R with n turns per meter gives
which approaches at the center only when .
Tracking a charge
The magnetic force does no work, so a good numerical method should keep the speed constant. The Boris method splits each step into a half push by any electric field, an exact-length rotation by the magnetic field, and another half push: it conserves the speed to rounding error in a pure magnetic field, however many steps it takes.
Fitting Hall data
The Hall voltage is , plus an offset when the voltage probes aren't perfectly opposite each other. Fitting a line to against I removes the offset as the intercept and gives n from the slope.
Worked example
Find the field of a 10 cm length of wire carrying 1 A, 1 cm from its middle, and compare it with an infinite wire.
Show the solution
- Field of a straight segment. Adding Biot–Savart pieces along the segment gives
- Put in the numbers. With r = 1 cm and a half-length of 5 cm:
- Infinite wire.
- Compare. A wire ten times longer than the distance to it already acts as infinite to within 2%. The far parts of a wire contribute little, since their pieces are both distant and nearly lined up with the point.
Answer the 10 cm wire makes 19.6 µT, against 20.0 µT for an infinite wire.
Worked example
How uniform is the field of a Helmholtz pair, and how much worse is it with the coils 20% too far apart?
Show the solution
- At the Helmholtz spacing. With the coils R apart, the axial field 0.1R from the center is uniform to 1.1 parts in 10 000.
- At 1.2R. With the coils 20% too far apart, the same ratio is 30 times less uniform, with a dip at the center.
- Why the Helmholtz spacing is so flat. It makes the field's second derivative vanish at the center, so its first error is fourth order in distance.
- What misplacement costs. A few millimeters of misplacement in a 10 cm coil spoils that quickly.
Answer at the Helmholtz spacing the field 0.1R from the center is within 1.1 parts in 10 000 of the center value; with the coils 20% too far apart it is 30 times less uniform.
Worked example
A Hall bar 0.2 mm thick in a 0.5 T field reads 31.7, 62.9, 94.1, 125.3 and 156.5 mV at 1 to 5 mA. What is its carrier density?
Show the solution
- Fit a line. The points lie on a line of slope 31.2 V/A, with an intercept of 0.5 mV, the probes' offset.
- Solve for the density. The slope is , so , where
- Carrier density.
- Why fit a line. Dividing a single reading by its current would have included the offset: at 1 mA it would give 31.7 V/A and n about 1.6% low.
- Another way. Reversing the field and averaging is the other common way to cancel the offset.
Answer the carrier density is m⁻³.
Check
Step 1. Write biot_savart(path, I, pts, n): path is a list of 3D points joined by straight segments carrying current I, pts an M × 3 array of field points. Split each segment into n pieces at their midpoints and return the M × 3 array of fields, with μ₀ = 4π × 10⁻⁷.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 2. Write coil_axis(R, I, z) for one turn's axial field, and helmholtz_variation(R, s, span) that puts two coils at , samples their total axial field at 2001 points from −span to span, and returns (max − min) divided by the center value.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 3. Write solenoid_sum(n, I, L, R, z, m) that builds a solenoid of length L, radius R and n turns per meter from m equally spaced loops (each carrying the current of turns) and returns the axial field at z. Compare with the exact formula in solenoid_exact. coil_axis is included.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 4. Write boris(q, m, v0, B, dt, steps) that moves a charge in a uniform magnetic field by the Boris rotation, returning the array of positions and the final velocity. Each step: , , , , then .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 5. Write hall_density(I, VH, B, t) that fits by least squares to measured arrays (amperes and volts) and returns the carrier density in m⁻³.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A Helmholtz pair has 50 turns per coil, radius 5 cm, and carries 2 A.
(a)
What field does it make at its center?
Write units the way you normally would: 1.5 µT, 1500 nT and 0.0015 mT are the same answer.
(b)
How far apart should the coils be for the most uniform field?
Check
An electron moves at 1 × 10⁶ m/s square to a 1 mT field. What is the radius of the circle a correct simulation should trace?
Write units the way you normally would: 1.5 mm, 1500 µm and 0.0015 m are the same answer.
Explain why
Why is it important that a simulation of a charge in a magnetic field keep the speed exactly constant?
A magnetic force is always perpendicular to the velocity, so it does no work: in the real motion the speed never changes and the charge circles at a fixed radius forever. A numerical method that doesn't respect this makes a small error in the speed every step, and those errors don't cancel; plain Euler, for instance, always makes the speed slightly larger, so a simulated electron spirals outward and a simulated plasma heats up from nothing. Over the millions of steps of a beam or plasma simulation, that becomes a large, unphysical effect. The Boris method rotates the velocity by an exact-length rotation each step, so the speed is preserved to rounding error no matter how long the run is.
Practice
Keep practicing
4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.