8.6 Exercises
277
Exercise 8.13: Use a Crank-Nicolson Scheme for Population Growth
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) = N 0 . 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
(t n +
1
2
Δt) ≈
N(t n + Δt) − N(t n )
Δt
=
N n+1 − N n
Δt
.
This type of difference, applied at the point t n+
1
2
= t n +
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 N n+1 , assuming N n 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) = N 0 , 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.
Filename: growth_CN.py.
Exercise 8.14: Understand Finite Differences via Taylor Series
The Taylor series around a point x = a can for a function f (x) be written
f (x) = f (a) +
d
dx
f (a)(x − a) +
1
2!
d 2
dx 2 f (a)(x − a)
2
+
1
3!
d 3
dx 3 f (a)(x − a)
3
+ . . .
=
∞
i=0
1
i!
d i
dx i f (a)(x − a)
i .
For a function of time, as addressed in our ODE problems, we would use u instead
of f , t instead of x, and a time point t n instead of a:
u(t) = u(t n ) +
d
dt
u(t n )(t − t n ) +
1
2!
d 2
dt 2 u(t n )(t − t n )
2
+
1
3!
d 3
dt 3 u(t n )(t − t n )
3
+ . . .
=
∞
i=0
1
i!
d i
dt i u(t n )(t − t n )
i .
277
Exercise 8.13: Use a Crank-Nicolson Scheme for Population Growth
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) = N 0 . 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
(t n +
1
2
Δt) ≈
N(t n + Δt) − N(t n )
Δt
=
N n+1 − N n
Δt
.
This type of difference, applied at the point t n+
1
2
= t n +
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 N n+1 , assuming N n 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) = N 0 , 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.
Filename: growth_CN.py.
Exercise 8.14: Understand Finite Differences via Taylor Series
The Taylor series around a point x = a can for a function f (x) be written
f (x) = f (a) +
d
dx
f (a)(x − a) +
1
2!
d 2
dx 2 f (a)(x − a)
2
+
1
3!
d 3
dx 3 f (a)(x − a)
3
+ . . .
=
∞
i=0
1
i!
d i
dx i f (a)(x − a)
i .
For a function of time, as addressed in our ODE problems, we would use u instead
of f , t instead of x, and a time point t n instead of a:
u(t) = u(t n ) +
d
dt
u(t n )(t − t n ) +
1
2!
d 2
dt 2 u(t n )(t − t n )
2
+
1
3!
d 3
dt 3 u(t n )(t − t n )
3
+ . . .
=
∞
i=0
1
i!
d i
dt i u(t n )(t − t n )
i .
