8.6 Exercises
281
combined, depends on the method. 11 With multi-step methods, more than one
starting value is required to get the scheme started. Thus, apart from the given initial
condition, the remaining starting values must be computed. This is done by some
other appropriate scheme (in such a way that the convergence rate of the overall
scheme is not reduced).
Note that the Runge-Kutta methods are single-step methods, even if they use
several intermediate steps (between t n and t n+1 ) when computing u n+1 , using no
other previous solution than u n .
One of the simplest multi-step methods is the (second order) two-step AdamsBashforth method. The computational scheme reads:
u
n+1
= u
n
+
Δt
2
3f (u
n , t n ) − f (u
n−1 , t n−1 )
,
for n = 1, 2, . . . , N t − 1, with u 0 = U 0 .
a) Implement the scheme in a function adams_bashforth_2 that takes appropriate
parameters, so that it is easy to import and use whenever needed. Use a Forward
Euler scheme to compute the missing starting value.
b) Write a function compare_FE_AdamsBashforth2 that compares graphically
the solutions produced by the Forward Euler and two-step Adams-Bashforth
methods, when they solve the population growth model u = 0.1u, with
u(0) = 100. Let the total time span T = 20, and use a time step dt = 2.
In the plot produced, include also the exact solution, so that the numerical
solutions can be assessed.
c) Suggest a reasonable asymptotic error model before you write a proper
test function test_convergence_rates that may be used to compute and check the convergence rates of the implemented AB2 method.
However, the test function should take appropriate input parameters,
so that it can be used also for other ODE solvers, in particular the
ode_FE implemented previously (if you already have written this test
function when doing Exercise 8.15, you may prefer to import the function).
Include your test function in a program, together with the two functions you
defined previously (AB2 and compare_FE_AdamsBashforth2). Write the code
with a test block, so that it gets easy to either import functions from the module,
or to run it as a program.
Finally, run the program (so that compare_FE_AdamsBashforth2 gets
called, as well as test_convergence_rates for both FE and AB2) and
confirm that it works as expected. In particular, does the plot look good,
and do you get the convergence rates you expected for Forward Euler and
AB2?
Filename: Adams_Bashforth_2.py.
11 Read more about multi-step methods, e.g., on Wikipedia (https://en.wikipedia.org/wiki/Linear_
multistep_method).
281
combined, depends on the method. 11 With multi-step methods, more than one
starting value is required to get the scheme started. Thus, apart from the given initial
condition, the remaining starting values must be computed. This is done by some
other appropriate scheme (in such a way that the convergence rate of the overall
scheme is not reduced).
Note that the Runge-Kutta methods are single-step methods, even if they use
several intermediate steps (between t n and t n+1 ) when computing u n+1 , using no
other previous solution than u n .
One of the simplest multi-step methods is the (second order) two-step AdamsBashforth method. The computational scheme reads:
u
n+1
= u
n
+
Δt
2
3f (u
n , t n ) − f (u
n−1 , t n−1 )
,
for n = 1, 2, . . . , N t − 1, with u 0 = U 0 .
a) Implement the scheme in a function adams_bashforth_2 that takes appropriate
parameters, so that it is easy to import and use whenever needed. Use a Forward
Euler scheme to compute the missing starting value.
b) Write a function compare_FE_AdamsBashforth2 that compares graphically
the solutions produced by the Forward Euler and two-step Adams-Bashforth
methods, when they solve the population growth model u = 0.1u, with
u(0) = 100. Let the total time span T = 20, and use a time step dt = 2.
In the plot produced, include also the exact solution, so that the numerical
solutions can be assessed.
c) Suggest a reasonable asymptotic error model before you write a proper
test function test_convergence_rates that may be used to compute and check the convergence rates of the implemented AB2 method.
However, the test function should take appropriate input parameters,
so that it can be used also for other ODE solvers, in particular the
ode_FE implemented previously (if you already have written this test
function when doing Exercise 8.15, you may prefer to import the function).
Include your test function in a program, together with the two functions you
defined previously (AB2 and compare_FE_AdamsBashforth2). Write the code
with a test block, so that it gets easy to either import functions from the module,
or to run it as a program.
Finally, run the program (so that compare_FE_AdamsBashforth2 gets
called, as well as test_convergence_rates for both FE and AB2) and
confirm that it works as expected. In particular, does the plot look good,
and do you get the convergence rates you expected for Forward Euler and
AB2?
Filename: Adams_Bashforth_2.py.
11 Read more about multi-step methods, e.g., on Wikipedia (https://en.wikipedia.org/wiki/Linear_
multistep_method).
