A field assigns a value to every position, and a partial differential equation (PDE) relates local changes in that value across space and time. Code cannot store “every position,” so it chooses a grid, an update rule, and boundary behavior. Those choices are part of the physical model, not low-level implementation details.
dx, dt, coefficient units, source arrays, and edge policy parameters. Then write known-value tests before animating the result.A classic scalar example is diffusion,
\[\frac{\partial u}{\partial t}=D\nabla^2u\]where u might be a concentration or temperature-like scalar and D is diffusivity. On a unit-spaced two-dimensional grid, the five-point Laplacian is
An explicit update becomes
\[u^{n+1}_{i,j}=u^n_{i,j}+D\Delta t\nabla_h^2u^n_{i,j}\]const laplacian = east + west + north + south - 4 * center;
const nextValue = center + diffusivity * timeStep * laplacian;
This teaches two important API choices. First, all nextValue computations must read the old grid; mutating cells in place makes update order change the model. Second, for the unit-grid two-dimensional explicit scheme, stability requires approximately D * Δt ≤ 1/4. Rejecting a larger product is more honest than rendering exploding values and calling them a surprising pattern.
Boundary policy changes the question. A fixed-zero boundary acts like a prescribed exterior value; wrapping makes opposite edges neighbors and models a periodic tile. Start with a single central peak: one stable step should lower its center, raise nearby cells, leave the old grid unchanged, and behave differently at edges under the two policies.
Prediction: A stable diffusion step spreads a peak, while a time step beyond the stability bound can create nonphysical oscillation or growth.
Use a 3×3 grid with one central value of 1 and zeros elsewhere. Predict the center and four neighbor values afterDΔt = 0.1, then compare with the update. Next explain why a wrap boundary makes an edge cell interact with the opposite edge.PDE code is local array programming with physical consequences. State the grid and boundaries, derive the finite-difference update, enforce its stability condition, and test old-grid immutability, symmetric fixtures, and refinement before trusting an animated field.
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.
\[\text{observable output} = f(\text{inputs},\,\text{state})\]For Fields as Partial Differential Equations, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Maxwell’s Equations and EM Waves, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.
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.
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.
Treat Fields as Partial Differential Equations 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.
Translate field equations into explicit grid state, boundaries, and stable local update rules.