282
8 Solving Ordinary Differential Equations
Exercise 8.18: The Three-Step Adams-Bashforth Method
This exercise builds on Exercise 8.17, so you better do that one first. Another multistep method, is the three-step Adams-Bashforth method. This is a third order method
with a computational scheme that reads:
u
n+1
= u
n
+
Δt
12
23f (u
n , t n ) − 16f (u
n−1 , t n−1 ) + 5f (u
n−2 , t n−2 )
.
for n = 2, 3, . . . , N t − 1, with u 0 = U 0 .
a) Assume that someone implemented the scheme as follows:
def adams_bashforth_3(f, U_0, dt, T):
"""Third-order Adams-Bashforth scheme for solving first order ODE"""
N_t = int(round(T/dt))
u = np.zeros(N_t+1)
t = np.linspace(0, N_t*dt, len(u))
u[0] = U_0
# Compute missing starting values
u[1] = 100*np.exp(0.1*dt)
u[2] = 100*np.exp(0.1*(2*dt))
for n in range(1, N_t, 1):
u[n+1] = u[n] + (dt/12)*(23*f(u[n], t[n]) - \
16*f(u[n-1], t[n-1]) +\
5*f(u[n-2], t[n-2]))
return u, t
There is one (known!) bug here, find it! Try first by simply reading the code. If not
successful, you may try to run it and do some testing on your computer.
Also, what would you say about the way that missing starting values are
computed?
b) Repeat Exercise 8.17, using the given three-step method in stead of the two-step
method.
Note that with the three-step method, you need 3 starting values. Use the
Runge-Kutta third order scheme for this purpose. However, check also the
convergence rate of the scheme when missing starting values are computed with
Forward Euler in stead.
Filename: Adams_Bashforth_3.py.
Exercise 8.19: Use a Backward Euler Scheme for Oscillations
Consider (8.43)–(8.44) modeling an oscillating engineering system. This 2×2 ODE
system can be solved by the Backward Euler scheme, which is based on discretizing
derivatives by collecting information backward in time. More specifically, u (t) is
approximated as
u
(t) ≈
u(t) − u(t − Δt)
Δt
.
Précédent

- 302/350

Suivant