Skip to main content

Section 9.4 Heun Method

As mentioned before, all methods for numerical quadrature do translate into methods for numerical solution of ODEs.

As an example, here we show only what happens in case of the trapezoidal method. If \(f(t,x)\) depended on \(t\) only, the "local" version of the method would be
\begin{equation*} x_{n+1}=x_n+\frac{h}{2}\left(f(t_n)+f(t_{n+1})\right). \end{equation*}

Naively, one would want to use
\begin{equation*} x_{n+1}=x_n+\frac{h}{2}\left(f(t_n,x_n)+f(t_{n+1},x_{n+1})\right) \end{equation*}
but we now we have \(x_{n+1}\) on both sides! Of course we do not know \(x_{n+1}\text{,}\) that is exactly what we are trying to evaluate. A way to overcome the problem above is evaluating a first time \(x_{n+1}\) using Euler`s method and use that value into the trapezoidal algorithm.

The method obtained this way is an example of "two steps method", since two steps are needed to evaluate \(x_{n+1}\text{,}\) and it is called Heun method:

  1. \(\displaystyle \hat x_{n+1} = x_n + h f(t_n,x_n)\)
  2. \(\displaystyle x_{n+1} = x_n + \frac{h}{2}(f(t_n,x_n)+f(t_{n+1},\;\;\hat x_{n+1}))\)
This particular implementation subdivides the "time" interval \([0,1.5]\) in 10 subintervals, namely \(h=0.15\text{.}\) The code saves all intermediate steps and plots them together with the corresponding values of the exact solution \(x(t)=\sqrt{1.25+\sin(\pi t)}\text{.}\)

Just like the trapezoidal method, one can prove that Heun method`s local error is \(O(h^3)\) and global error is \(O(h^2)\text{.}\) Below we verify this fact numerically: