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

B2 · Lesson 13 · Computing fields

Superposition by computer, checked against the formulas

The formulas of lesson 5 cover a handful of symmetric shapes. A real electrode, a PCB trace or an irregular charged part has no formula. But superposition still holds, so a computer can do what the integral does: chop the charge into many small pieces, add up their fields as point charges, and refine until the answer stops changing. Field solvers in electronics design start from exactly this idea. In this lab you'll write one in NumPy and test it against cases where the answer is known.

  • The solid curve is the exact field of a charged rod (half-length a, 2 nC/m) on its perpendicular bisector. The dashed curves are an infinitely long line and a point charge with the rod's total charge.
  • Close to the rod it looks like an infinite line; far away, like a point. In between, neither formula works, and that's where numerical summing earns its keep.
  • Make the rod longer. Where does the changeover move?

Predict

You approximate a charged rod by n equal point charges at the middles of n equal segments. Roughly how does the error behave as n grows?

Name it

Superposition in code

For point charges qj at positions 𝐫j, the field at a point 𝐫 is

𝐄(𝐫)=∑jkqj𝐫−𝐫j|𝐫−𝐫j|3

In NumPy, with sources as an N×3 array and field points as M×3, broadcasting builds all M×N separation vectors at once: d = pts[:, None, :] - src[None, :, :]. Divide by the cube of each distance, weight by the charges, and sum over the sources.

Discretizing continuous charge

Chop a line of charge into n segments of length Δx, each carrying λΔx at its midpoint. As n grows the sum approaches the integral, with error about 1n2. Surfaces work the same way with small patches carrying σΔA.

Testing a field code

  • One point charge must give exactly kq/r2, pointing away.
  • A symmetric shape must reproduce its formula: a rod on its bisector, a ring on its axis.
  • Refine and compare: doubling n should change the answer by about a quarter of the remaining error.
  • Check far-field behavior: any neutral pair of charges must fall off as 1/r3 far away, the dipole law; measuring the exponent on a log-log scale checks the whole calculation at once.

Worked example

A 10 cm rod carries 2 nC/m. What is its field 2 cm out on its bisector, exactly and with 10 point charges?

Show the solution
  1. Exact field. E=2kλayy2+a2=2×8.988×1090.020.0004+0.0025×2×10−9×0.05=1669.0V/m
  2. Ten point charges. With 10 midpoint charges of 0.2 nC each, the sum is 1669.9 V/m, high by 0.055%.
  3. Two hundred point charges. With 200, it's 1669.03 V/m.

Answer the exact field is 1669.0 V/m; 10 point charges give 1669.9 V/m (0.055% high), and 200 give 1669.03 V/m.

Worked example

How can you check numerically that a dipole's field falls as 1/r3?

Show the solution
  1. Two distances. Compute the field at two distances r1 and r2 along the axis.
  2. Slope on a log-log plot. slope=ln⁡(E2/E1)ln⁡(r2/r1)
  3. Far out. For ±1 nC charges 1 mm apart, distances of 2 and 5 cm give −3.001.
  4. Close in. At 2 and 4 mm, it's −3.14: the dipole law holds only far compared with the separation.

Answer find the log-log slope between two distances on the axis; for this dipole it's −3.001 at 2 and 5 cm, very close to −3.

Check

Step 1. Write field(q, src, pts) returning an M×3 array of field vectors at the M points pts, from charges q (length N) at positions src (N×3), using k = 8.988 × 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 rod_field(lam, a, y, n) returning Ey at (0,y,0) from a rod along x from −a to a carrying lam C/m, approximated by n charges at segment midpoints. field 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 3. Write axis_exponent(q, d, r1, r2): for charges +q at (−d/2,0,0) and −q at (d/2,0,0), compute the field strength on the x axis at r1 and r2 and return ln⁡(E2/E1)ln⁡(r2/r1). field 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. A midpoint-rule field sum with 10 pieces is off by 0.06%. The error falls as 1/n2. What error do you expect with 4 times as many pieces, in percent?

Explain why

Why is placing each piece's charge at the middle of its segment so much better than placing it at one end?

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.