Maxwell's curl equations, discretised
For a 2D transverse-magnetic wave with field components E_z, H_x and H_y, Maxwell's curl equations reduce to three coupled partial differential equations. The Finite-Difference Time-Domain method (FDTD), introduced by Kane Yee in 1966, replaces every derivative with a finite difference on a grid, and simply steps those equations forward in time — no Fourier transforms, no assumed geometry, just the local update rule applied everywhere at once:
∂H_x/∂t = -(1/μ) * ∂E_z/∂y ∂H_y/∂t = (1/μ) * ∂E_z/∂x ∂E_z/∂t = (1/ε) * (∂H_y/∂x - ∂H_x/∂y)
The Yee grid: why it stays accurate for free
Yee's trick is to place E and H components at offset positions: H_x and H_y sit half a cell away from E_z in space, and are also evaluated half a time step apart from it — a leapfrog in time as well as in space. Every derivative then becomes a simple, symmetric central difference, which is second-order accurate without any extra work:
H_x[i,j]^(n+1/2) = H_x[i,j]^(n-1/2) - (dt/(μ*dy)) * (E_z[i,j+1]^n - E_z[i,j]^n)
E_z[i,j]^(n+1) = E_z[i,j]^n + (dt/ε) * ( (H_y[i,j]-H_y[i-1,j])/dx
- (H_x[i,j]-H_x[i,j-1])/dy )
The Courant stability condition
The time step cannot be chosen freely: information must not be allowed to cross more than one grid cell per step, or the scheme diverges. In two dimensions the Courant–Friedrichs–Lewy bound is:
dt ≤ dx / (c * sqrt(2)) (2D, square grid, c = speed of light in the medium)
Push the time step even slightly past this limit and the simulation does not just lose accuracy — it blows up exponentially within a handful of steps, since the numerical scheme itself becomes unstable, not merely imprecise.
Boundaries: perfect reflectors versus open space
Forcing E_z = 0 along a line of cells models a perfect electric conductor (PEC): a wave hitting it reflects completely, which is exactly how the "paint PEC reflectors" tool builds mirrors and slit walls. A simulation box that is meant to represent open space, however, cannot simply stop at its edge — a hard wall there would reflect every outgoing wave back in as spurious noise. The standard fix is a perfectly matched layer (PML), an artificial absorbing region around the edge whose impedance is engineered to match free space at every angle of incidence, so waves pass into it and are attenuated to nothing rather than bouncing back.
Diffraction and interference for free
Nothing in the update rule above knows about slits, lenses or interference — it only knows the local field values one cell away. Yet paint two narrow gaps in a PEC wall and the double-slit interference fringes appear on their own, because every point along the wavefront genuinely acts as Huygens's secondary source, exactly as the classical wave-front construction predicts. That is the real payoff of solving the field equations directly on a grid rather than hand-coding a diffraction formula: any geometry — a lens, a prism, an antenna — produces its own correct diffraction and interference pattern automatically.
Frequently asked questions
Why simulate Maxwell's equations on a grid instead of solving them exactly?
Exact closed-form solutions to Maxwell's equations only exist for a small number of special geometries. FDTD works for essentially any shape or arrangement of materials because it only ever evaluates the same local update rule cell by cell, letting complex effects like diffraction and interference emerge from the simulation rather than being derived by hand for every new geometry.
Why does refining the grid force a smaller time step?
The Courant stability condition ties the maximum stable time step directly to the grid spacing through the speed of light: dt must stay below roughly dx divided by c times a geometric factor. Halving the cell size for finer spatial detail means the time step has to shrink correspondingly or the simulation becomes numerically unstable.
How does double-slit interference appear without any interference formula being coded in?
Every grid cell simply obeys the same local Maxwell update rule. When a wavefront reaches a wall with two gaps, each gap becomes a new source of outgoing wavefronts purely because the field values there are nonzero, and the interference pattern is just the sum of those two wavefronts overlapping, a global consequence of superposition rather than a special case in the code.
Try it live
Everything above runs in your browser — open EM Wave Simulator and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open EM Wave Simulator simulation