/ tutorials / laplace-dirichlet
Sign in
tutorials / laplace-dirichlet
laplace-dirichlet / src / chapters / ch02 / text.md
3.7 KBPreviewCodeBlameHistoryRaw

Second order says that halving hh divides the error by four. Taken literally it promises any accuracy at all, given enough points. It does not deliver, and the two reasons it does not are the subject of this chapter: arithmetic is not exact, and the matrix gets worse as the mesh gets finer.

The condition number of the difference matrix#

The eigenvalues of the (N−1)×(N−1)(N-1) \times (N-1) matrix tridiag(−1,2,−1)\mathrm{tridiag}(-1,2,-1) are known in closed form,

λk  =  4sin⁡2 ⁣(kπh2),k=1,…,N−1,\lambda_k \;=\; 4\sin^2\!\Big(\frac{k\pi h}{2}\Big), \qquad k = 1, \dots, N-1,

so after the factor 1/h21/h^2 the extreme eigenvalues of AA are about π2\pi^2 and 4/h24/h^2, and

κ(A)  =  λN−1λ1  ≈  4π2h2  ≈  0.4 N2.\kappa(A) \;=\; \frac{\lambda_{N-1}}{\lambda_1} \;\approx\; \frac{4}{\pi^2 h^2} \;\approx\; 0.4\,N^2 .

This is not a defect of the discretisation. The continuous operator −d2/dx2-d^2/dx^2 is unbounded, and any consistent discretisation of it must have a condition number that grows as the mesh is refined. The practical consequence is a floor: solving in double precision, with unit roundoff ε≈2.2×10−16\varepsilon \approx 2.2 \times 10^{-16}, cannot be expected to give a relative accuracy better than roughly εκ(A)≈10−16N2\varepsilon \kappa(A) \approx 10^{-16} N^2. Setting that equal to the discretisation error Ch2=CN−2C h^2 = C N^{-2} gives

Nbest  ∼  ε−1/4≈104,errorbest  ∼  ε≈10−8.N_{\text{best}} \;\sim\; \varepsilon^{-1/4} \approx 10^4, \qquad \text{error}_{\text{best}} \;\sim\; \sqrt{\varepsilon} \approx 10^{-8}.

About half the digits, and no more, whatever the machine and however long one is willing to wait.

The prediction is quantitative and the lab confirms it. The error falls at exactly second order until N≈105N \approx 10^5, reaches a little under 10−810^{-8}, and then climbs again. The climb is roundoff amplified by the condition number, and its detailed rate depends on how the rounding errors happen to fall, but the shape of the curve is completely reproducible: past the minimum, refining the mesh makes the answer worse and takes longer to do it.

Note also the cost. Each row of the table is a solve of O(N)O(N) work, so the wall clock in the last column grows linearly, and the whole 20-fold improvement in accuracy from N=103N = 10^3 to N=105N = 10^5 costs a factor of 100 in time.

Getting a better rate without a better scheme#

The error expansion of the previous chapter says more than "the error is O(h2)O(h^2)". For smooth uu the nodal error has an asymptotic expansion in even powers of hh,

uh(x)=u(x)+c2(x) h2+c4(x) h4+⋯ ,u_h(x) = u(x) + c_2(x)\,h^2 + c_4(x)\,h^4 + \cdots,

with coefficients independent of hh. Two solves, at hh and h/2h/2, then give two equations at the points the meshes share, and the combination

uR  =  4 uh/2−uh3u_R \;=\; \frac{4\,u_{h/2} - u_h}{3}

cancels c2c_2 exactly and leaves O(h4)O(h^4). This is Richardson extrapolation. It costs one extra solve, which for a tridiagonal system is a factor of three in total work, and it needs no new discretisation, no new stencil, and no new code.

On the smooth solution the observed order goes from 2 to 4, and at N=512N = 512 the extrapolated answer is about five orders of magnitude better than the one it was built from. Switch to lowreg and the gain in order disappears entirely: both curves converge at about 1.51.5, because u′′′′u'''' does not exist at x=1/2x = 1/2 and the expansion in powers of h2h^2 that justifies the combination is not valid there. The extrapolation still improves the constant, by a factor of about seven, which is a fair return for one extra solve but is not what it was asked to do.

That is the honest summary of extrapolation. It is nearly free when it works, it is easy to check whether it worked, since the observed order tells you, and when the assumed expansion is absent it degenerates into a mildly better constant. The next chapter takes the other route: change the discretisation itself.

↑↓ move↵openescclose