The electric field points in the direction of decreasing potential, but that sentence becomes dependable only when the program fixes its coordinates, units, and derivative stencil. In electrostatics, field and potential are two views of the same model: one returns a vector in volts per metre (or newtons per coulomb); the other returns a scalar in volts. Implementing both independently gives a valuable consistency check.
Think like a programmer
Expose potential as a pure scalar function and derive a second field estimate through a named central-difference helper. Compare it with the analytic or solver field at probes that are safely away from singularities and boundaries. Keep the finite-difference step, probe coordinates, units, and residual norm in the test result. Never differentiate pixels, color values, or post-projection display coordinates.
Model checklist
Inputs
Potential function V in volts, independent electric-field function E in V/m, probe points in metres, central-difference step h, domain boundaries, source mask, and residual tolerance.
State
Four neighbouring potential samples per probe, numerical gradient, negative-gradient field estimate, reference field, and per-probe residual.
Rule
Use centred differences for ∂V/∂x and ∂V/∂y, negate the gradient, then compare with the independent field result.
Output
Field estimate, component residual, vector-norm residual, step-refinement history, and rejected-probe reason.
Check
A linear potential is recovered exactly up to rounding; halving h reduces truncation error before roundoff dominates; field and negative gradient agree away from singularities; constant shifts of V leave E unchanged.
\[\mathbf E=-\nabla V\]
For a central-difference step h, the computational rule in two dimensions is:
The sign is a physical and API contract. If V(x,y) = 3x − 2y volts for coordinates measured in metres, the expected field is [-3, 2] V/m everywhere. That linear fixture should be an exact regression test before testing a nonlinear point-charge potential. It catches a missing minus sign, a swapped x/y sample, and an accidental forward difference with no visual ambiguity.
Step size is not a slider to maximize. A large h blurs curvature and samples across boundaries or masked sources. An extremely small h subtracts nearly equal floating-point values and exposes roundoff. Run a short refinement table—perhaps h, h/2, and h/4—at the same physical probe. Accept the region where the residual improves as expected, and flag a plateau or growth rather than silently choosing the smallest value.
Potential is defined up to an additive constant. Adding C to every potential sample leaves both finite differences unchanged, so a field comparison must not fail just because one implementation chose ground at a different place. Conversely, matching scalar values at one point does not prove matching fields: compare component or norm residuals across a domain.
Try this experiment
Prediction: Moving a positive test charge in the field direction lowers potential; adding a constant to potential leaves the numerical field unchanged.
Implement the linear fixture V = 3x − 2y and check the vector [-3, 2] for three probes. Use h = 0.1, 0.01, and 0.001 m and record the residual. Then add 10 V to V. Finally repeat away from a point charge, excluding samples that touch its singular location.
Where this model breaks
Finite differences amplify roundoff at very small steps and blur features at large ones. Boundaries can make centred samples unavailable; use a stated one-sided stencil or reject those probes. Point-source potentials are undefined at their source, and static E = −∇V is not by itself a complete description of time-varying electromagnetic fields or material response.
Summary
Use the negative-gradient relationship as an automated cross-check between scalar and vector implementations. Validate first on a linear analytic fixture, then log step refinement, boundaries, singularity policy, and residuals for every more realistic comparison.
Glossary
Gradient: vector of spatial scalar derivatives.
Finite difference: derivative approximation from nearby samples.
Residual: mismatch between two expected equivalents.
Central difference: symmetric derivative estimate from samples on both sides of a probe.
Gauge/reference offset: arbitrary additive constant in a potential representation.
Self-check
What sign connects field and gradient?
Which linear potential makes a clean x/y and sign regression fixture?
Why can the smallest finite-difference step be worse?
What happens to the field if every potential value gains the same constant?
Treat the lesson as a small function before treating it as a fact to memorize. Give every value a unit, keep only the state needed for the next step, and make the output easy to inspect.
Quantities you set or measure, with units and useful bounds.
State
Values the program must retain to reproduce the next result.
Rule
The relationship or update that turns inputs and state into a result.
Check
A known limit, unit check, invariant, or measured result that can expose a bad model.
Implement the idea as a model
For Field–Potential Relationship, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Electric Potential and Capacitance, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.
Guided experiment
Prediction: changing one declared input while holding the others fixed should change only the outputs that the model connects to that input. Choose one input, predict the direction of change, then check a limiting case such as zero, a symmetric arrangement, or a familiar low-speed or small-change approximation.
Where this model breaks
This lesson is a teaching model, not a complete simulator. Before using it outside the stated question, check which interactions, scales, uncertainties, boundary conditions, and measurement limits it leaves out.
Summary
Treat Field–Potential Relationship as a contract: named inputs and units enter a rule, the rule produces an observable result, and a known limit or invariant checks whether the implementation deserves trust.
Glossary
Input: a measured value or chosen parameter supplied to a model.
State: the smallest set of values needed to continue or reproduce a model.
Validation: comparing an output with a known result, limit, invariant, or measurement.
Self-check
Which values are inputs, and which values must remain state?
What observable result would tell you the model is behaving as expected?
Which assumption would you test first before applying the model to a real system?
Model review: turn Field–Potential Relationship into a test
Cross-check field and potential functions with a finite-difference negative-gradient residual.
Name the inputs and units that the electric potential and capacitance model needs.
Separate the state you must keep from values you can calculate when needed.
Write one rule that maps the current state and inputs to an observable result.
Choose a limiting case, unit check, invariant, or known result before trusting an output.
State one assumption you would change before using this simplified model for a real decision.