The Dirichlet problem: accuracy against cost#
An interactive tutorial on solving the Dirichlet problem for Laplace's and Poisson's equations, in one and two dimensions, with every method written as a MATLAB-syntax script that you can edit and run in the page. It runs in your browser through numbl; there is no server, nothing to install, and nothing is sent anywhere.
The organising idea is that every problem in it has an exact solution known in closed form, by construction, so the error of every computation is known at every point to full precision. What the tutorial then measures is not whether a method works but what accuracy it delivers for what cost, and under which conditions that answer changes.
The problems#
In one dimension, Laplace's equation is and its solution is a straight line, so Part I uses Poisson's equation with the source manufactured from a chosen solution. Five solutions are available, differing in how hard they are to resolve: an entire function of moderate amplitude, an oscillatory one, a narrow Gaussian, a boundary layer, and one that is but not .
In two dimensions the equation is Laplace's, and the exact solutions are harmonic functions written down in closed form: , , , and with the singularity just outside the domain. Their boundary traces are the data, so the only error in the computation is the error of the method.
The chapters#
One dimension
- Ground truth by construction — manufactured solutions, the three-point scheme, the tridiagonal solve, and what the error field looks like.
- Second order, to its limit — the condition number , the roundoff floor near , and Richardson extrapolation.
- Two more orders, almost free — Numerov's compact fourth-order scheme, which changes only the right-hand side, and how to read a work-precision diagram.
- Chebyshev collocation — a dense matrix, geometric convergence to with 64 points, and the two situations that take that away.
Two dimensions
- The five-point Laplacian — harmonic ground truth, second order, and the wall of a dense solve.
- The fast Poisson solver — the same system diagonalised by the discrete sine transform: a million unknowns in half a second, identical answers.
- Sixth order for the same price — the compact nine-point stencil, which is sixth-order accurate on Laplace's equation and uses the same fast solver, and two-dimensional Chebyshev collocation by matrix decomposition.
- Iterating instead of solving — Jacobi, Gauss-Seidel, SOR, conjugate gradients and a multigrid V-cycle on one problem, and the question of when to stop.
Beyond the square
- A corner, and what it costs — the L-shaped domain, the loss of second order to the singularity, and the method of particular solutions, which puts the singularity into the basis and reaches .
- Boundary integral equations — a smooth curved domain, the double-layer potential, a second-kind Fredholm equation, the spectral accuracy of the periodic trapezoid rule, and the close-evaluation problem that comes with it.
A shared MATLAB library page lists the small function files every lab boots with.
Using it#
Each lab has controls above the figures and, behind the "show script" button, the method itself. Edit the script and press run: the session reboots with your version compiled in, and the figures are whatever your code produces. Ctrl-Enter (Cmd-Enter) runs from inside the editor, and "reset" restores the original.
Some labs run as soon as the chapter opens; the heavier ones wait for the run button, which the caption says.
Development#
npm install
npm run dev # vite dev server
npm run build # typecheck and bundle to dist/
npm run test:matlab # the .m layer, through the numbl CLI (needs a numbl checkout)
npm run test:browser # the built app in headless Chrome
test:matlab needs a numbl clone; set NUMBL_DIR if it is not at ~/src/numbl.
Every assertion in it is a number claimed somewhere in the prose, so a failure means
either the code or the text is wrong. test:browser needs npm run build first, and
takes --shots to write a full-page screenshot of each chapter into tmp/.
See CLAUDE.md for how the pieces fit together, and in particular for the numbl performance rules that the drivers are written around.
Licence#
Apache-2.0.