6.6. Implicit and Semi-Implicit Schemes Consider once again the trivial linear ODE y 10 y (6.42) with y(0) 1. We can modified the Euler method by evaluating the RHS at the “new” step instead of the “old”, i.e., (6.43) yk 1 yk h 10 yk 1 This procedure is sometimes called the backward Euler method since it can be derived using the backward-difference approximation for y'. The simplicity of the present example allows us to solve (6.43) for yk+1 explicitly so that yk 1 1 yk 1 10h (6.44) Obviously, this kind of explicit inversion is not possible for a general nonlinear ODE. For example, consider the equation y 2 y 5 6 y which is equivalent to y z and (6.45) z 2 y 5 6 y Applying the backward Euler method, we get yk 1 yk hzk 1 zk 1 zk h 2 yk51 6 yk 1 (6.46) which cannot be inverted analytically. For this reason, the scheme is also called the implicit Euler method. Returning to (6.42), we recall the results of §6.2.2 that the Euler scheme fails completely for h 3/10 , which produces a rapidly diverging oscillatory solution instead of the exponential decay of the exact solution. For convenience, the results obtained from the two schemes are tabulized below together with the exact result: k 0 Implicit 1 yk 1 0.25 2 3 0.0625 0.0156 Euler 1 0.5 0.25 0.125 Exact 1 0.607 0.368 0.223 Although the “implicit” result differs significantly from the exact solution, it is a great improvememt over that of the Euler method in that at least the correct qualitative behavior is displayed. Another demonstration of the power of the implicit Euler method is provided by the stiff harmonic oscillator (6.40), which is equivalent to x y and y 20 y 1 x 100 so that the backward-difference scheme gives xk 1 xk h yk 1 1 1 h yk 1 yk h 20 yk 1 xk 1 xk 1 yk 100 1 20h 100 which can be inverted to give xk 1 xk yk 1 h h xk 1 yk 1 20h 100 1 h xk yk 2 h 1 20h 1 100 1 20h 1 1 20h xk hyk 1 20h 0.01h 2 1 h 1 1 20h xk hyk yk 2 1 20h 100 1 20h 0.01h 1 yk 0.01hxk 1 20h 0.01h 2 (6.47) If, as before, we start at t 10 and take h 0.2, a qualitatively correct solution is obtained as shown in Fig.6.13 [cf. the Euler result in Fig.6.11]. To create a stable 2nd order implicit scheme, we can average the “old” and the “new” on the RHS. ( This is also the basis for the semi-implicit Crank-Nicolson scheme for solving nonlinear PDEs [see Chapter 11] ). For example, (6.42) is written as yk 1 yk 10h 1 yk yk 1 2 (6.48) 1 5h yk 1 5h (6.49) Expanding in powers of h, we have yk 1 1 5h 1 5h 25h 2 125h 3 1 10h 50h 2 250h 3 Comparing with the Taylor expansion 1 1 yk 1 yk hyk h 2 yk h 3 yk 2 6 y k y k 1 1 2 3 yk 10hyk h 2 10 yk h 3 10 yk 2 6 we see that (6.49) is accurate to O(h3), as claimed. Turning to nonlinear systems, we now apply the 1st order implicit method to the fox rabies system, first introduced in §2.2.2 and solved in MF05 using the Mathematica NDSolve command with the RungeKutta option. To begin, we insert the constraint X Y Z N into the original coupled equations X aX b N X XZ Y XZ b N Y (2.22) Z Y b N Z to display the nonlinear terms more clearly, viz., X a b X X 2 XY XZ Y b Y XZ XY Y 2 YZ (6.51) Z Y b Z XZ YZ Z 2 To 1st order accuracy, the corresponding implicit algorithm is X k 1 X k h a b X k 1 X k21 X k 1Yk 1 X k 1Z k 1 Yk 1 Yk h b Yk 1 X k 1Z k 1 X k 1Yk 1 Yk21 Yk 1Z k 1 Z k 1 Z k h Yk 1 b Z k 1 X k 1Z k 1 Yk 1Z k 1 Z k21 (6.52) The presence of the nonlinear terms prevents an analytic inversion of (6.52). To proceed further, the standard procedure is to expand each nonlinear term according to f f f xk 1 , zk 1 f xk , zk xk 1 xk zk 1 zk (6.53) x xk , zk z xk , zk For example, X k 1Zk 1 XZ k 1 X k Zk X k 1 X k Zk Zk 1 Zk X k (6.54) where the RHS is linear in both Xk+1 and Zk+1. Converting each nonlinear term in (6.52) this way and collecting terms, we get, with the help of Mathematica, 1 hA1k X k 1 hB1kYk 1 hC1k Zk 1 X k hD1k hA2k X k 1 1 hB2k X k 1 hC2k Zk 1 Yk hD2k (6.55) hA3k X k 1 hB3kYk 1 1 hC3k Zk 1 Zk hD3k where A1k b a Nk X k Zk B1k X k A2k Yk Z k B2k b N k Yk C1k X k D1k N k X k X k Z k C2k Yk X k A3k Z k B3k Z k C3k b Nk Zk D2k N kYk X k Z k D3k N k Z k N k X k Yk Z k Since (6.55) is linear in Xk+1 , Yk+1 , and Yk+1 , it can be inverted to give the formula for step k+1. This length code is in Semi-Implicit Scheme Applied to Fox Rabies System MF27.nb MF27.mws Taking the same initial values and parameters as in MF05, the trajectory for h 0.004 and 5000 time steps is shown in Fig.6.14, which, aside from orientation, closely resembles that in Fig.2.7. Since the implicit algorithm is of the lowest order and no adaptive step size is used, the computing time for MF27 is much longer than in MF05 owing to the small h required for stability. As can be imagined, implicit and semi-implicit schemes are much more complicated than the explicit ones. The incorporation of an adaptive step size is particularly difficult. Also, stability of such schemes are not guaranteed, though they usually are. Fig.6.13. Implicit Euler method applied to stiff equation. fig.6.14. Semi-implicit solution of fox rabies equation.