/ tutorials / laplace-dirichlet
Sign in
tutorials / laplace-dirichlet
laplace-dirichlet / README.md
97 lines · 4.5 KBCodeBlameHistory
088be4cAn interactive tutorial on the Dirichlet problem, accuracy against costJeremy Magland 1# The Dirichlet problem: accuracy against cost
3An interactive tutorial on solving the Dirichlet problem for Laplace's and Poisson's
4equations, in one and two dimensions, with every method written as a MATLAB-syntax
5script that you can edit and run in the page. It runs in your browser through
6[numbl](https://numbl.org); there is no server, nothing to install, and nothing is
7sent anywhere.
9The organising idea is that every problem in it has an exact solution known in
10closed form, by construction, so the error of every computation is known at every
11point to full precision. What the tutorial then measures is not whether a method
12works but what accuracy it delivers for what cost, and under which conditions that
13answer changes.
15## The problems
17In one dimension, Laplace's equation is $u'' = 0$ and its solution is a straight
18line, so Part I uses Poisson's equation $-u'' = f$ with the source manufactured from
19a chosen solution. Five solutions are available, differing in how hard they are to
20resolve: an entire function of moderate amplitude, an oscillatory one, a narrow
21Gaussian, a boundary layer, and one that is $C^2$ but not $C^3$.
23In two dimensions the equation is Laplace's, and the exact solutions are harmonic
24functions written down in closed form: $e^x \sin y$, $\operatorname{Re}(x+iy)^k$,
25$e^{ky}\sin kx$, and $\log|z - z_0|$ with the singularity just outside the domain.
26Their boundary traces are the data, so the only error in the computation is the
27error of the method.
29## The chapters
31**One dimension**
331. **Ground truth by construction** — manufactured solutions, the three-point
34 scheme, the tridiagonal solve, and what the error field looks like.
352. **Second order, to its limit** — the condition number $\kappa \approx 0.4N^2$,
36 the roundoff floor near $10^{-8.5}$, and Richardson extrapolation.
373. **Two more orders, almost free** — Numerov's compact fourth-order scheme, which
38 changes only the right-hand side, and how to read a work-precision diagram.
394. **Chebyshev collocation** — a dense matrix, geometric convergence to $10^{-13}$
40 with 64 points, and the two situations that take that away.
42**Two dimensions**
445. **The five-point Laplacian** — harmonic ground truth, second order, and the
45 $O(N^6)$ wall of a dense solve.
466. **The fast Poisson solver** — the same system diagonalised by the discrete sine
47 transform: a million unknowns in half a second, identical answers.
487. **Sixth order for the same price** — the compact nine-point stencil, which is
49 sixth-order accurate on Laplace's equation and uses the same fast solver, and
50 two-dimensional Chebyshev collocation by matrix decomposition.
518. **Iterating instead of solving** — Jacobi, Gauss-Seidel, SOR, conjugate
52 gradients and a multigrid V-cycle on one problem, and the question of when to
53 stop.
55**Beyond the square**
579. **A corner, and what it costs** — the L-shaped domain, the loss of second order
58 to the $r^{2/3}$ singularity, and the method of particular solutions, which puts
59 the singularity into the basis and reaches $10^{-14}$.
6010. **Boundary integral equations** — a smooth curved domain, the double-layer
61 potential, a second-kind Fredholm equation, the spectral accuracy of the
62 periodic trapezoid rule, and the close-evaluation problem that comes with it.
64A **shared MATLAB library** page lists the small function files every lab boots
65with.
67## Using it
69Each lab has controls above the figures and, behind the "show script" button, the
70method itself. Edit the script and press run: the session reboots with your version
71compiled in, and the figures are whatever your code produces. Ctrl-Enter (Cmd-Enter)
72runs from inside the editor, and "reset" restores the original.
74Some labs run as soon as the chapter opens; the heavier ones wait for the run
75button, which the caption says.
77## Development
79```
80npm install
81npm run dev # vite dev server
82npm run build # typecheck and bundle to dist/
83npm run test:matlab # the .m layer, through the numbl CLI (needs a numbl checkout)
84npm run test:browser # the built app in headless Chrome
85```
87`test:matlab` needs a numbl clone; set `NUMBL_DIR` if it is not at `~/src/numbl`.
88Every assertion in it is a number claimed somewhere in the prose, so a failure means
89either the code or the text is wrong. `test:browser` needs `npm run build` first, and
90takes `--shots` to write a full-page screenshot of each chapter into `tmp/`.
92See [CLAUDE.md](CLAUDE.md) for how the pieces fit together, and in particular for the
93numbl performance rules that the drivers are written around.
95## Licence
97Apache-2.0.
↑↓ move↵openescclose