Make plots for comparing the Crank-Nicolson scheme with the Forward and Backward Euler schemes in the same test problem as in Exercise 8.12..
1.It is recommended to do Exercise 8.12 prior to the present one. Here we look at the same population growth model N
(t) = rN(t), N(0) = N0. The time derivative N
(t) can be approximated by various types of finite differences. Exercise 8.12 considers a backward difference (Fig. 8.22), while Sect. 8.2.2 explained the forward difference (Fig. 8.4). A centered difference is more accurate than a backward or forward difference: N
(tn + 1 2 Δt) ≈ N(tn + Δt) − N(tn) Δt = Nn+1 − Nn Δt . This type of difference, applied at the point t n+1 2 = tn + 1 2Δt, is illustrated geometrically in Fig. 8.23.
a) Insert the finite difference approximation in the ODE N
= rN and solve for the unknown Nn+1, assuming Nn is already computed and hence known. The resulting computational scheme is often referred to as a Crank-Nicolson scheme.
b) Implement the algorithm in a) in a function growth_CN(N_0, dt, T) for solving N
= rN, N(0) = N0, t ∈ (0, T ], with time step Δt (dt).
c) Make plots for comparing the Crank-Nicolson scheme with the Forward and Backward Euler schemes in the same test problem as in Exercise 8.12.
