HomeArticlesHeat Equation

The Heat Equation: Solving PDEs with Finite Differences

Fourier’s law plus energy conservation gives one equation for how heat spreads — here is how a grid of numbers turns it into a moving picture.

mysimulator teamUpdated June 2026≈ 8 min read▶ Open the simulation

A conservation law in disguise

The heat equation describes how temperature spreads through a material once you stop asking about individual molecules and start asking about a continuous field. It follows from two ideas glued together. Fourier’s law says heat flux is proportional to the temperature gradient: heat flows from hot to cold, faster where the gradient is steeper. Energy conservation says the temperature at a point only changes if more heat is flowing in than out. Combine the two and you get a single partial differential equation, with thermal diffusivity α = k/(ρc) bundling conductivity k, density ρ and specific heat c into one number.

∂u/∂t = α ( ∂²u/∂x² + ∂²u/∂y² )    ← 2D heat equation
u(x,y,t)  = temperature field
α = k / (ρ c)  = thermal diffusivity

This is the same equation that governs diffusion of ink in water and the spread of a pollutant in the atmosphere — diffusion and conduction are the same mathematics with different labels on the axes.

Turning derivatives into neighbours

A computer cannot evaluate a derivative directly, so the simulation lays a grid over the plate and replaces each derivative with a difference between neighbouring cells. The standard central-difference approximation for the second derivative in one direction is (u[i+1] − 2u[i] + u[i−1]) / Δx²; add the same thing in the other direction and you get an update rule that moves every cell toward the average of its four neighbours, weighted by how far out of step it currently is.

next[i][j] = cur[i][j] + α * dt * (
  (cur[i+1][j] - 2*cur[i][j] + cur[i-1][j]) / dx2 +
  (cur[i][j+1] - 2*cur[i][j] + cur[i][j-1]) / dy2
)   // explicit FTCS scheme, one full grid pass per frame
live demo · finite-difference diffusion on a 2D grid● LIVE

Why the step size cannot be arbitrary

This explicit scheme (forward-time, centred-space, or FTCS) is cheap but not unconditionally safe. Von Neumann stability analysis — checking how each Fourier mode of the error grows from one step to the next — shows the scheme only stays bounded if α·dt·(1/dx² + 1/dy²) stays at or below one half. Push dt past that line and the grid does not just get slightly wrong, it oscillates and diverges within a handful of frames, because dx already appears squared in the denominator: halving the cell size forces the time step down by a factor of four. Implicit schemes such as Crank–Nicolson solve a linear system every step instead of reading neighbours directly, which costs more per step but removes the stability limit entirely, so large time steps stay well behaved.

Transient versus steady state

Running the update rule forward in time gives the transient solution — the plate cooling and warming as heat sources switch on. Left alone long enough with fixed boundary temperatures, the field stops changing and satisfies Laplace’s equation, ∇²u = 0: the steady state. You can reach it two ways — step the transient equation until it stops moving, which can take thousands of frames, or solve the steady equation directly with a relaxation method such as Gauss–Seidel or successive over-relaxation, which iterates purely in space and converges far faster when only the final picture matters.

Boundary conditions decide the picture

Painting a fixed hot or cold spot pins a cell’s temperature every step — a Dirichlet condition. An insulated edge instead forces the gradient across it to zero — a Neumann condition — so heat reflects back inward rather than leaking out. Real walls do a mix of both, losing heat in proportion to the temperature difference with the outside air, which is the Robin condition, the one actual radiators and windows obey.

Frequently asked questions

Why does the simulation blow up into noise if I push the speed slider too high?

The solver uses an explicit finite-difference scheme, which is only stable when the time step stays below a threshold set by the cell size and the diffusivity (the von Neumann stability condition). Cross it and rounding error grows every step instead of shrinking, turning a smooth field into checkerboard noise within a few frames.

What is actually different between steady state and transient mode?

Transient mode steps the full time-dependent equation forward, showing heat spreading frame by frame. Steady state instead solves ∇²u = 0 directly with a relaxation method, skipping straight to the temperature pattern the plate would settle into if you waited forever with the same boundary conditions.

Why do heat sources spread out as circles instead of squares, even on a square grid?

Diffusion is isotropic — heat conducts equally fast in every direction — so the temperature contours around a point source approach circles as the grid gets finer, even though the underlying simulation only ever talks to four axis-aligned neighbours per cell.

Try it live

Everything above runs in your browser — open Heat Equation and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Heat Equation simulation

What did you find?

Add reproduction steps (optional)