Heun’s Method

← Numerical Methods

Source inspiration: (Mathew 2000-2019).

Description

Heun’s method solves the initial value problem \(y' = f(t, y)\), \(y(t_0) = y_0\), on \([t_0, b]\), at the grid points \(t_n = t_0 + nh\) of \(m\) subintervals of width \(h = (b - t_0)/m\). It writes \(y(t_{n+1}) = y(t_n) + \int_{t_n}^{t_{n+1}} f(t, y(t))\,dt\), approximates the integral by the trapezoidal rule, and predicts the unknown \(y(t_{n+1})\) inside it with an Euler step:

\[ p_{n+1} = y_n + h\,f(t_n, y_n), \qquad y_{n+1} = y_n + \frac{h}{2}\Bigl(f(t_n, y_n) + f(t_{n+1}, p_{n+1})\Bigr). \]

Some books call this the improved or modified Euler method; Mathews’ modified Euler method, on the Euler page, is the midpoint method.

Mathews’ theorem for the method assumes that \(f\) is continuous and Lipschitz in \(y\), and his precision theorem that the solution is in \(C^3[t_0, b]\). Then, in general, the local truncation error is \(O(h^3)\) and the global error, including the final global error at \(t = b\), is \(O(h^2)\): for small \(h\), halving \(h\) divides the error by about 4, against 2 for Euler’s method.

The animations use \(y' = 1 - t\sqrt[3]{y}\), \(y(0) = 1\) on \([0, 5]\), with \(y(5) = 0.0081199205\). Here \(f\) is not Lipschitz near \(y = 0\), but the solution never falls below \(y(5)\). At \(m = 150\), the last frame of Mathews’ animation, Heun’s method gives \(y_{150} = 0.0081236\), the value it prints. The table gives the error \(y_m - y(5)\) and the largest error at any grid point, each with its ratio to the row above:

\(m\) \(h\) \(y_m\) error at \(t = 5\) ratio largest error ratio
150 0.03333 0.0081235818 \(3.661 \times 10^{-6}\) — \(3.273 \times 10^{-4}\) —
300 0.01667 0.0081203664 \(4.459 \times 10^{-7}\) 8.21 \(7.699 \times 10^{-5}\) 4.25
600 0.00833 0.0081200086 \(8.818 \times 10^{-8}\) 5.06 \(1.870 \times 10^{-5}\) 4.12
1200 0.00417 0.0081199404 \(1.995 \times 10^{-8}\) 4.42 \(4.608 \times 10^{-6}\) 4.06
2400 0.00208 0.0081199252 \(4.762 \times 10^{-9}\) 4.19 \(1.144 \times 10^{-6}\) 4.03

The error at \(t = 5\) alone misleads: at \(m = 150\) it is about twice Euler’s, and it stays larger than Euler’s up to \(m = 205\), although Heun’s largest error is 69 times smaller.

Heun’s method is explicit, and in general, on \(y' = \lambda y\), each step multiplies the error by \(1 + z + z^2/2\) with \(z = h\lambda\); for real \(z < 0\) this has size at most 1 only for \(-2 \le z \le 0\), Euler’s limit too. Here \(\partial f/\partial y = -t/(3y^{2/3})\) reaches \(-41.3\) at \(t = 5\), so for steps longer than about \(h = 0.0485\) (\(m \le 103\)), \(h\,|\partial f/\partial y|\) along the solution exceeds 2 before \(t = 5\), and every such run ends with a larger error than it had just before that point. At \(m = 70\) that point is \(t \approx 4.40\), and the error grows from \(1.0 \times 10^{-4}\) just before it to \(9.0 \times 10^{-3}\), so \(y_{70} = 0.0171\), about twice \(y(5)\). For \(m \le 68\) some predictions \(p_{n+1}\) are negative, so those runs also depend on how \(\sqrt[3]{y}\) is taken there (the real cube root on this site).

Heun’s method is Euler’s method with a trapezoidal correction, equation (4) of Predictor-Corrector Methods, and a second-order Runge-Kutta method; RK4 and the Taylor Series Method reach higher orders.

References

Mathew, John H. 2000-2019. Numerical Analysis - Numerical Methods Modules. https://web.archive.org/web/20190808102217/http://mathfaculty.fullerton.edu/mathews/n2003/NumericalUndergradMod.html.