Section 1.10 Implicit Euler method
The problematic behavior of the explicit Euler method disappears if, at the step \(n\text{,}\) we evaluate the right hand side at \(x_{n+1}\) rather than \(x_n\text{:}\)
\begin{equation*}
x_{n+1} = x_n + h f(t_{n+1},x_{n+1}).
\end{equation*}
This time, though, we do not evaluate \(x_{n+1}\) with Euler's method, as we did in case of Heun method, but rather we consider the relation above as an equation in \(x_{n+1}\) and look for its solution closest to \(x_{n}\text{.}\) This method is called Implicit Euler method and it is of global order 1. The word implicit referes to the fact that the relation above defines \(x_{n+1}\) only implicitly: an equation must be solved, usually numerically, to get its value. Although clearly much less trivial than its explicit counterpart, the implicit version has a great advantage: it behaves well with stiff problems! This can be seen explicitly in the example case:
\begin{equation*}
x_{n+1} = x_n - hkx_{n+1},\;\;x_0=1,
\end{equation*}
so that
\begin{equation*}
x_{n} = \frac{1}{(1+hk)^{n}}.
\end{equation*}
This sequence, for every value of \(h>0\text{,}\) does converge monotonically to 0, just like the exact solution! In the code below, we solve again the ODE \(\dot x = -15x\) but now with the Implicit Euler method. Notice that, in this case, there is no need to solve the equation numerically: \(x_{n+1} = \frac{x_n}{1+hk}.\) Below we solve with the implicit method the same ODE we have been solving so far with the explicit methods we covered, namely
\begin{equation*}
x' = -x\cos t,\;x(0)=1.
\end{equation*}
This time, we need to solve numerically at each step \(n\) the equation
\begin{equation*}
x_{n+1} = x_n - h\,x_{n+1}\cos t_{n+1}.
\end{equation*}
While we could solve explicitly this equation, in the implementation below we use the secant algorithm to evaluate numerically the value of \(x_{n+1}\text{.}\) This way, we will be able to apply the same code to functions \(f(t,x)\) for which the solution cannot be found explicitly.
Stability region of the implicit Euler method. The implicit method is good with stiff ODEs. Indeed, consider the linear ODE
\begin{equation*}
\dot x = Kx,\;\;x(t_0)=x_0,\;\;K\in\mathbb C,\; Re(K)<0.
\end{equation*}
As in the previous section, we pose the following question: for which values of \(K\) does its numerical solution \(x_n\) obtained through the implicit Euler method behave qualitatively similarly to its exact solution \(x(t)=x_0e^{K(t-t_0)}\text{?}\) The same argument above shows that
\begin{equation*}
x_n = \frac{x_0}{(1-Kh)^n},
\end{equation*}
and we get the same qualitative behavior as long as \(x_n\) remains bounded for all \(n\text{.}\) In turn, this happens if and only if
\begin{equation*}
|1-Kh|^{-1}\leq1.
\end{equation*}
We plot this region of the complex plane below.