Task 1 of 5
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.
α from
D, dt and dx, and return one explicit step of
field.ALPHA = D * dt / (dx * dx) in JavaScript — it reaches the kernel as a constantα times the Laplacianα = 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.
lap and c are already in scope, so the body is one line:
return c + this.constants.alpha * lap;This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.