A939 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A9 · Lesson 39 · Lab: flux, divergence and curl

Checking Gauss, Stokes and Biot–Savart numerically

The divergence and Stokes theorems connect what happens inside a region to what crosses or circles its boundary. In this lab you'll test them numerically: derivatives of a field on a grid, the flux of a point charge through spheres that do and don't contain it, the flux out of a cube computed both ways, the magnetic field of a current loop summed segment by segment, and the circulation of a wire's field around loops that do and don't enclose it.

  • The field is that of a line source at the origin, (x,y)x2+y2, a two-dimensional point charge.
  • Its flux through any closed curve is 2π if the curve encloses the source and zero if it doesn't. The readout applies that to a circle of radius R centered at distance d from the source.
  • Slide d past R: the flux drops from 2π to zero at once, however close the curve still is.

Predict

A point charge sits just outside a closed sphere. What is the net electric flux through the sphere?

Name it

Derivatives on a grid

np.gradient(F, h, axis=k) estimates ∂F∂xk by central differences in the interior. Divergence and curl come from combining them:

div = np.gradient(Fx, h, axis=0) + np.gradient(Fy, h, axis=1)
curl_z = np.gradient(Fy, h, axis=0) - np.gradient(Fx, h, axis=1)

(with arrays indexed [i, j] for xi, yj).

Flux through a sphere

On a grid of (θ,φ) angles, the outward normal is 𝐧^=(sin⁡θcos⁡φ,sin⁡θsin⁡φ,cos⁡θ) and dA=a2sin⁡θdθdφ. Sum 𝐅⋅𝐧^dA over the cells.

Biot–Savart

A current loop's field is the sum over short segments d𝐥:

𝐁=μ0I4π∑d𝐥×𝐫|𝐫|3

with 𝐫 from each segment to the field point. On the axis of a circular loop of radius R, the exact result is Bz=μ0IR22(R2+z2)3/2.

Worked example

Check the divergence theorem for 𝐅=(x2y,yz,zx) on the unit cube.

Show the solution
  1. Divergence. ∇⋅𝐅=2xy+z+x
  2. Integrate it over the cube. 2⋅12⋅12+12+12=1.5
  3. Flux through the far faces. At x=1, Fx=y, giving 12; at y=1, Fy=z, giving 12; at z=1, Fz=x, giving 12.
  4. Flux through the near faces. The three faces through the origin have zero normal component.
  5. Compare. The total flux is 1.5, matching.

Answer both sides give 1.5.

Worked example

Find the field on the axis of a 5 cm loop carrying 1 A, 3 cm from its center.

Show the solution
  1. On-axis field of a loop. Bz=μ0IR22(R2+z2)3/2=4π×10−7×0.00252(0.0034)3/2=7.92µT
  2. Check numerically. Summing Biot–Savart over 2000 segments of the loop gives the same to thirteen digits: on the axis the sum is a symmetric average, and it converges very fast.

Answer the field is 7.92 µT along the axis.

Check

A loop of radius 2 cm carries 1 A. What is the field on its axis, 3 cm from the center?

Write units the way you normally would: 1.5 µT, 1500 nT and 0.0015 mT are the same answer.

Check

An 8 nC charge sits at the center of a cube. What is the flux through one face?

Write units the way you normally would: 1.5 V·m, 1500 mV·m and 0.0015 kV·m are the same answer.

Check

On a 101 × 101 grid over [0,1]2, compute the divergence and the curl's z component of 𝐅=(x2,xy) with np.gradient. Set err_div and err_curl to the largest differences from the exact 3x and y at interior points.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write flux(c, a, n=400) returning the flux of 𝐫|𝐫|3 (a point charge at the origin) through a sphere of radius a centered at c, with a midpoint grid of n × 2n angles. Set f1, f2, f3 for spheres of radius 1 centered at (0,0,0), (0.3,0,0) and (2,0,0).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Check the divergence theorem for 𝐅=(x2y,yz,zx) on the unit cube: compute the volume integral of ∇⋅𝐅 with a 100³ midpoint grid and the outward flux through the six faces with 100² midpoint grids. Set vol and surf.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Sum Biot–Savart over 2000 segments of a loop of radius 5 cm carrying 1 A to get Bz at 3 cm along the axis. Set Bz and formula.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

A long wire along z carries 2 A, with 𝐁=μ0I2π(−y,x)x2+y2. Compute the circulation of 𝐁 around the square with corners (±1,±1) (enclosing the wire) and around the square from (2,2) to (3,3) (not enclosing it), 4000 midpoint segments per side. Set c1 and c2.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

A field's flux through a closed surface is zero. Does that mean the field is zero inside?

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.