Task 5 of 5

Stable Is Not Accurate

Time to put the two schemes on the same clock. Both runs below finish at T = 16: the explicit one in small steps of 0.2, the implicit one in steps of 2 — ten times larger, and four times past the explicit limit. A third run takes the explicit scheme at the implicit step size, for the pleasure of watching it fail in eight steps.

The two survivors will not agree. Backward Euler is first-order accurate, just like forward Euler, so a ten-times-larger step carries a ten-times-larger error — it damps sharp features harder than the real equation does. Expect the two fields to differ by a few percent of the peak. That is the honest trade, and it is worth stating plainly: unconditional stability is not accuracy. What implicit stepping buys you is the right to choose dt for the accuracy you need, rather than having it dictated by the smallest cell in your mesh.

Nor is it free. Each implicit step here costs 25 sweeps, so the coarse run makes 8 × 25 = 200 kernel launches against the fine run's 80 — implicit loses the launch count at this size. It wins when the explicit limit gets brutal: refine dx by 10× and the explicit run needs 100× the steps, while the implicit one needs the same eight and a slightly harder solve.

Goal: finish the Jacobi sweep with α arriving as an argument, work out how many steps of each size reach T, and run all three.

Requirements

Hint 1 — alpha as an argument

Only the spelling changes: a plain alpha where the constant used to be, and the caller passes it. Everything else is last task's body:

return (uOld[y][x] + alpha * neighbours)
  / (1 + 4 * alpha);
Hint 2 — how many steps?

Steps × step size = elapsed time, so it is T / dt: 16 / 0.2 = 80 and 16 / 2 = 8.

Same idea elsewhere

Choosing a scheme by what limits it — accuracy or stability — is the daily work of numerical simulation everywhere: stiff chemistry and implicit thermal solvers pay for a linear solve per step because the explicit alternative would need millions of them, while explicit codes dominate wave propagation and particle work, where the stability step is close to the accuracy step anyway. On a GPU the arithmetic is nearly free, so the calculus is really about launches and memory traffic per unit of simulated time.

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.