Physics Library
 An open source physics library
Encyclopedia | Forums | Docs | Random  

[parent] Numerical Electric Field Maps and Independent Checks

(Example)

ES01E10: Numerical Electric Field Maps and Independent Checks

computer calculations are valuable in electrostatics, but they are reliable only when they implement the same geometry and signs as the analytic derivation. This lesson develops a small field evaluator, applies it to a point charge map, reconstructs E from potential with a centered difference, and checks numerical convergence. A runnable Python program is supplied at the article’s top level.

1 1. The basic field evaluator

The field evaluation function implements the vector Coulomb sum at an observation point r:

|------------------------|
|         ∑N          ′  |
|E(r) = k     q -r-−-ri-.|
|        e     i|r − r′i|3 |
-----------i=1-------------
(1)

For an ideal point charge the field is singular at the source location. A singularity mask means deliberately excluding those positions or representing their field as undefined, rather than replacing an infinite value by zero. The code checks that the input arrays have matching lengths and that no evaluation point coincides with a source.

2 2. Worked example 1: a sampled point charge map

Take a positive charge Q at the origin. At (a, 0), (a,a), and (2a, 0), the analytically scaled fields in units of E0 = keQ∕a2 are

E(a,0)-=  (1, 0),  E-(a,a) = (1,√1),   E-(2a,-0) = (1∕4,0).
  E0                E0       2  2       E0
(2)

A correct program must reproduce these values to floating point precision. Figure 1 shows an example map with all arrows at a common scale. When a plotting routine automatically normalizes vectors, the figure displays direction only and must not be used to infer the inverse square magnitude law.

PIC

Figure 1. Sample vector field about a positive point charge, with the singular source excluded. All arrows are scaled consistently within the diagram.

3 3. Worked example 2: use potential as an independent computation

For a point charge at the origin, V (x, 0) = keQ∕x for x > 0. The exact field at x > 0 is Ex = keQ∕x2. A finite difference gradient approximates the derivative using nearby potential values:

           V(x + h ) − V (x − h)
Ex (x ) ≃ − --------------------,     0 < h < x.
                    2h
(3)

For x = 1 m, substitute V = keQ∕x and simplify algebraically:

              (              )
Ex,h = − keQ-   --1--−  --1---
          2h    1 + h   1 − h
         keQ
     = ------2.
       1 − h
(4)

The exact value is Ex = keQ. Thus the relative error is

|--------------------|
|Ex,h − Ex      h2   |
|----------=  -----2.|
----Ex--------1 −-h---
(5)

For h = 0.200, 0.100, and 0.0500 m the relative errors are approximately 4.17%, 1.01%, and 0.251%, respectively. This is a controlled calculation because V is known analytically; it is not a measurement of the accuracy of an arbitrary laboratory voltmeter.

4 4. Worked example 3: measure convergence

A convergence test repeats the calculation as the numerical step is refined. Equation (5) predicts an O(h2) error for sufficiently small h. Halving h should reduce the error by a factor approaching four. The exact ratios at finite h are slightly different because of the denominator 1 − h2.

PIC

Figure 2. Schematic convergence trend when numerical resolution increases. The number of sample points and the step size are inversely related; the actual error must be measured against an independent result.

A single grid result cannot prove convergence. For a general field map, compare successive grid resolutions away from singular sources and verify at least one symmetry or analytic limit. Refinement near a singularity requires special care, because the underlying field diverges there.

5 5. Worked example 4: two charges and cancellation checks

Place two identical charges +q at (−a, 0) and (a, 0). At the midpoint the code should return E(0, 0) = 0 within numerical roundoff, because the two contributions are equal and opposite. At (0,z) with z > 0, it should return the purely vertical result

E (0,z) = ---2keqz---ˆy.
          (a2 + z2)3∕2
(6)

These checks exercise both sign conventions and symmetry. Far from a neutral pair with opposite charges, the direct summation subtracts nearly equal terms and can suffer cancellation error in finite precision. Compare that result with the analytically derived dipole far field, and report the observation distance relative to the source size.

6 6. Running the accompanying program

The bundled file ES01E10_field_checks.py uses Python 3 and NumPy. Running

python ES01E10_field_checks.py

prints the main analytic comparisons and numerical errors, checks two source symmetry with assertions, and saves a CSV of finite difference results. It neither accesses the network nor treats a generated field as experimental data. Read the source and change the charges to experiment with new geometries.

File downloads: ES01E10˙field˙checks.py ES01E10˙finite˙difference.csv

7 7. Exercises

  1. Derive the general centered difference field for V (x) = keQ∕x at any x > h > 0, and calculate its relative error.
  2. Explain why a field evaluator must not return 0 at a point source location.
  3. If a centered difference has an O(h2) truncation error, what error ratio should occur after halving h sufficiently far from singularities?
  4. A symmetric two-charge problem returns a small nonzero Ex of order 10−13 times the magnitude of each contribution. What independent information decides whether this is a physics effect or floating point roundoff?

8 8. Solutions

  1. The finite difference expression simplifies to Ex,h = keQ∕(x2 −h2). Divide by the exact keQ∕x2 to obtain (E x,h − Ex)∕Ex = h2∕(x2 − h2).
  2. The ideal point charge field diverges at the source and is not a finite vector there. Returning zero would falsely suggest a physical cancellation or equilibrium.
  3. The error should approach one quarter of its previous value, for smooth data and sufficiently small h. Measurement noise or rounding can eventually spoil this trend.
  4. Verify the analytic reflection symmetry, compare individual component magnitudes with the residual, change numeric precision or source order, and test the result under coordinate reflection. A residual near machine precision is usually roundoff, not a new physical field.

9 9. Numerical quality checklist

State the sources, coordinate units, and observation grid; mask singularities; preserve the sign of every source charge; use physical vector scales; compare with a known solution and convergence study; and label simulated curves as calculations rather than experimental readings.

References

References

[1]   P. Dourmashkin and collaborators, Electricity and Magnetism, MIT 8.02 course notes, chapters on Coulomb’s law and electric fields.

[2]   D. J. Griffiths, Introduction to Electrodynamics, 4th ed., Cambridge University Press, 2017, electrostatics chapters.

[3]   E. M. Purcell and D. J. Morin, Electricity and Magnetism, 3rd ed., Cambridge University Press, 2013.

[4]   PhysicsLibrary, ES01/EM05 articles and the earlier single example entries for the corresponding ES01E identifiers.


"Numerical Electric Field Maps and Independent Checks" is owned by bloftin.
(view preamble)
View style:
Other names:  ES01E10
Keywords:  electric field computation, Python, vector field maps, Coulomb sum, finite differences, gradient, convergence, vector superposition, numerical verification

This object's parent.

Cross-references: source charge, equilibrium, gradient, diagram, vector field, magnitude, square, units, positive charge, positions, observation point, vector, function, program, charge, computer

This is version 2 of Numerical Electric Field Maps and Independent Checks, born on 2026-11-27, modified 2026-11-27.
Object id is 1607, canonical name is NumericalElectricFieldMapsAndIndependentChecks.
Accessed 133 times total.

Classification:
Physics Classification: 41.20.Cv (Electrostatics; Poisson and Laplace equations, boundary-value)
 03.50.De (Classical electromagnetism, Maxwell equations )
 41.20.-q (Applied classical electromagnetism)
 41.20.Jb (Electromagnetic wave propagation; radiowave propagation )

Pending Errata and Addenda

None.

Discussion

No messages.

Interact