Task 1 of 5

One Explicit Step

The heat equation is the simplest interesting PDE there is: ∂u/∂t = D·∇²u. Every point drifts toward the average of what surrounds it, at a rate set by the diffusivity D. Discretise the right-hand side with the 5-point stencil — left + right + up + down − 4·centre, divided by dx², which Reaction–Diffusion derives in full — take a plain forward-Euler step in time, and the whole solver is one line:

u' = u + α·(left + right + up + down − 4u)
with  α = D·dt/dx²

That single dimensionless number α, the diffusion number, is what this module is about. Collect the terms and the step turns out not to be an addition at all. It is an average:

u' = (1 − 4α)·u
     + α·left + α·right + α·up + α·down

Five weights that add to exactly one. Notice the shape of that centre weight, 1 − 4α — the next task is about what happens when it goes negative.

five weights that add to one — while the middle one is positive
Goal: compute the diffusion number α from D, dt and dx, and return one explicit step of field.

Requirements

Hint 1 — dx is squared

α = D·dt/dx² — the cell spacing appears squared, because a second derivative is a difference of differences. With D = 8, dt = 0.2 and dx = 4 that comes to 0.1.

Hint 2 — the whole return

lap and c are already in scope, so the body is one line:

return c + this.constants.alpha * lap;

Same idea elsewhere

This three-line update is, almost character for character, the innermost loop of every explicit finite-difference solver on every platform: a CUDA kernel with one thread per cell, a WGSL compute shader reading and writing a storage texture, a Metal kernel tiling the grid into threadgroups. What differs between them is memory layout and how the halo is exchanged — never the arithmetic.

All tasks in The Heat Equation & Stability

  1. One Explicit Step
  2. Cross the Line
  3. Sixteen Step Sizes at Once
  4. Solve, Don’t Step
  5. Stable Is Not Accurate

This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.