Implementation of An Adaptive BDF2 Formula
Implementation of An Adaptive BDF2 Formula
Abstract
After applying the Finite Element Method (FEM) to the diffusion-type and wave-type
Partial Differential Equations (PDEs), a first order and a second order Ordinary Differen-
tial Equation (ODE) systems are obtained respectively. These ODE systems usually present
high stiffness, so numerical methods with good stability properties are required in their reso-
lution. MATLAB offers a set of open source adaptive step functions for solving ODEs. One
of these functions is the ode15s recommended to solve stiff problems and which is based on
the Backward Differentiation Formulae (BDF). We describe the error estimation and the step
size control implemented in this function. The ode15s is a variable order algorithm, and even
though it has an adaptive step size implementation, the advancing formula and the local error
estimation that uses correspond to the constant step size formula. We have focused on the
second order accurate and unconditionally stable BDF (BDF2) and we have implemented a
real adaptive step size BDF2 algorithm using the same strategy as the BDF2 implemented in
the ode15s, resulting the new algorithm more efficient than the one implemented in MATLAB.
Keywords: PDEs, stiff ODEs, Backward Differentiation Formula, adaptive BDF2
1 Introduction
Numerous phenomena of science and engineering are modelled mathematically using systems of
Partial Differential Equations (PDEs). Mass, momentum and energy balances, with appropri-
ate constitutive laws are the basis of a broad class of Boundary Condition (BC) problems from
which the macroscopic movement of solids, fluids and gases with their corresponding forces
can be deduced. Similarly, flow solutions for heat and mass transport problems can be ob-
tained, and interaction problems between different media (mechanical, thermal, chemical, or
electromagnetic) can be studied.
1014 Selection and peer-review under responsibility of the Scientific Programme Committee of ICCS 2014
c The Authors. Published by Elsevier B.V.
doi:10.1016/j.procs.2014.05.091
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
∇·⎣ −C∇u + Du
⎦+ Eu
= f (1)
Conductive f lux Convective f lux Absortion Source
where C and E are physical constants and D a vector that depends on the problem. This is the
case of the heat transfer problem where the unknown function u(x) represents the temperature.
If the convective and absorbing terms are not considered, the Laplace-Poisson PDE is obtained:
∇ · (−C∇u) = f (2)
Equation (2) governs the potential problem, which has many applications such as the flux
of an incompressible and non-viscous fluid, the torsion of a profile of any section, the simple
heat conduction or the mass diffusion without convection. All these examples are stationary
but it is enough to add an additional source term related to the inertia to time change to extend
any of these models to the general transient case, with Initial Conditions (IC) and Boundary
Conditions (BC). The simplest representative cases are the diffusion and the wave equation.
The latter is obtained by taking f = −G · utt (x, t):
G
∇ · C∇u(x, t) = G · utt (x, t) → Δu = utt (3)
C
If the unknown function u(x, t) represents the transverse displacement of a stretched string
with a force T (C = T ) and density ρ (G = ρ), the PDE governs the transverse vibrations of
the elastic string.
The analytical solution of PDEs in a general domain is not possible and it is necessary the
use of numerical methods, being the Finite Element Method (FEM) the most capable in general
to deal with any shape domains. After applying the Finite Element Method to the diffusion-type
and wave-type PDEs with boundary conditions and initial conditions, a first order and a second
order Ordinary Differential Equation (ODE) systems are obtained respectively. The process to
obtain approximate solutions of these problems using the FEM, consists of discretizing the
domain in elements and nodes. The solution approach is based on the elimination of the spatial
derivatives of the PDE and this leads to a system of ODEs.
The ODE system that results after the FEM discretization presents high stiffness, which
means that the greater the ratio of the eigenvalues of the Jacobian matrix, the more stiff the
system of ODEs [5, 7, 11]. This means that a non-significant part of the solution requires very
small step sizes to avoid instability of the whole solution. When we are solving systems of stiff
ODEs by numerical integration, it is important to use an accurate algorithm with good stability
properties. Since they were introduced, the Backward Differentiation Formulae (BDF) [4] have
been widely used due to their good stability properties.
The software package MATLAB offers a set of codes to solve initial value problems [10, 12]:
on a finite time interval T = [t0 , tn ]. Some of these ode solvers are recommended to solve nonstiff
problems. This is the case of the two explicit Runge-Kutta codes implemented in MATLAB:
the ode23 which is based on the Bogacki-Shampine 3(2) pair [1] and the ode45 based on the
1015
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
Dormand Prince (5,4) pair [3]. The ode113 is another nonstiff ode solver, which is a PECE
implementation of the Adams Bashforth-Moulton methods [14].
For stiff problems, the most popular code implemented in MATLAB is the ode15s which
uses the Backward Differentiation Formulae (BDF) [4] and the Numerical Differentiation For-
mulae (NDF) [15]. This paper studies the algorithm that supports the ode15s: the underlying
methods, the local error estimation and the adaptation of the step size to verify the specified
error tolerance. The ode15s is a variable order and variable step size algorithm, although it uses
an advancing formula and a local error estimation of the constant step size formula. We have
focused on the second order accurate BDF (BDF2), which is A-stable. We have implemented a
real adaptive step size BDF2 algorithm using the same strategy as the BDF2 implemented in
the ode15s, resulting the one implemented by us more efficient.
The article is organized as follows: characteristics of the ode15s have been studied in Section
2. In Section 3 the implementation of the variable step size new BDF2 is explained. In Section
4 some examples are solved and the number of steps given and the errors obtained are analysed.
Finally, some conclusions are presented in Section 5.
k 1 j
• NDFs: j=1 j ∇ yn+k = hfn+k + κγk ∇k+1 yn+k .
k 1
being fn+k = f (tn+k , yn+k ) and γk = j=1 j .
Table 1: NDFs of Klopfenstein and Shampine: efficiency and stability with respect to BDFs.
In [15] an alternative form to write the left-hand side of these two expressions is given, which
1016
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
k
1
k
(0)
∇j yn+k = γk yn+k − yn+k + γj ∇j yn+k−1 (5)
j=1
j j=1
where:
⎧
j 1
⎪
⎨γj = l=1
(0)
k l
yn+k = j=0 ∇j yn+k−1 = ∇0 yn+k−1 + ∇yn+k−1 + ... + ∇k yn+k−1 (6)
⎪
⎩ (0)
yn+k − yn+k = ∇k+1 yn+k
Taking into account expression (5) the NDFs can be written as follows:
k
(0)
(1 − κ) γk yn+k − yn+k + γj ∇j yn+k−1 = hfn+k (7)
j=1
where the values of κ are in the Table 1. BDF methods are obtained for κ = 0.
being C the error constant of the method and k the order of the BDF or NDF formula in which
the ode15s is solving.
Backward differences are used to calculate an approximation of y k+1 (tn ). An approximation
of y(t) is obtained by using the backward interpolating polynomial of Newton that passes from
the (k + 2) points {(tn+i , yn+i )} for i = −1, 0, 1, 2, ..., k:
k+1
1
j−1
y(t) ≈ Q(t) = yn+k + ∇j yn+k (t − tn+k−m ) (9)
j=1
j!hj m=0
1 1
Q(k+1) (t) = ∇k+1 yn+k (k + 1)! = ∇k+1 yn+k k+1 (10)
(k + 1)!h k+1 h
Obtaining:
1
y (k+1) (t) ≈ Q(k+1) (t) = ∇k+1 yn+k (11)
hk+1
Substituting the approximation (11) in (8), the error estimation of the ode15s in terms of
backward differences is obtained:
1017
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
We will suppose that we have just given a step using a step size h and that we are interested
in calculating the next step size which corresponds to order k. This step size could be a new step
or the repetition of the previous step because it has not been verified the tolerance requirement.
In both cases, the next step size is calculated by multiplying the previous step size by a constant
σ. Hence, the next step size will be (σ · h) and the local error will be [13]:
(σ · h)k+1 φ(tn+1 ) + O (σh)k+2 (14)
Expression (16) gives the local error made with a step size (σ · h). The largest step size that
will pass the error test is calculated by chosing σ so that σ k+1 est ≈ Rtol is verified, where
Rtol is the specified tolerance. This step size is:
1/k+1
Rtol
σ·h= ·h (17)
est
Because a failed step is expensive, the codes use a fraction of the predicted step. The ode15s
uses a safety factor FS = 56 and the new step size for order k is:
hk = F · h (18)
Taking into account (19) the factor F = 1/z represents the hyperbola of Figure 1. Two regions
can be clearly distinguished, separated by est = Rtol, where zS = 1.2 is verified. In this
case, the factor F takes the value of the safety factor: FS = 56 . For a trial step h, the ode15s
1018
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
F
successful failed step
step
F
U
F
S
FL
z zS zL
z
U
computes the values of est and z, and the step is considered successful if z ≤ zS = 1.2 is
verified.
When the given step is successful, that is to say z ∈ [0, 1.2], or equivalently F ∈ 56 , ∞ , an
upper threshold FU = 10 is established and the step size of the k-order method is defined as:
FU · h, z ≤ zU
hk = (20)
F · h, zS < z ≤ zU
1/k 1/(k+2)
estk−1 estk+1
zk−1 = 1.3 · , zk+1 = 1.4 · (21)
Rtol Rtol
The step sizes hk−1 and hk+1 are defined as follows, being the upper thresholds Fk−1,U = 10
and Fk+1,U = 10:
Fk−1,U · h, zk−1 ≤ zk−1,U
hk−1 = (22)
Fk−1 · h, zk−1,S < zk−1 ≤ zk−1,U
Fk+1,U · h, zk+1 ≤ zk+1,U
hk+1 = (23)
Fk+1 · h, zk+1,S < zk+1 ≤ zk+1,U
where zk−1,U = 0.1, zk−1,S = 1.3, zk+1,U = 0.1 and zk+1,S = 1.4.
When the step sizes hk , hk−1 and hk+1 are available, the process that the ode15s follows to
set the next step size is this one:
1019
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
1. If hk−1 > hk is verified, the following assignments are made: hnew = hk−1 and knew =
k − 1. If hk−1 > hk is not verified, hnew = hk and knew = k are considered.
2. Next, hk+1 and hnew are compared. If hk+1 > hnew , the value hk+1 is stored in hnew and
one unit is added to the order knew .
3. Finally, the value hnew is compared with the step size h used in the last step. If hnew > h,
the next step size will be hnew and it will be given with order knew . If not, the order and
the step size of the last step are maintained.
When the given step is unsuccessful, the step is repeated. The step size of the k-order
formula is calculated using a lower threshold FL = 0.1 as follows:
F · h, zS < z ≤ zL
hk = (24)
FL · h, z > zL
1020
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
and substituting (29) in (28), the expression of the local truncation error of the adaptive step
size BDF2 is obtained:
(hn+1 + hn+2 ) yn+2 − yn+1 hn+2 yn+1 − yn hn+2
LT E ≈ − 1+ + (yn − yn−1 ) (30)
6 hn+2 hn+1 hn+1 hn+1 hn
being hn = tn − tn−1 .
4 Numerical Results
In this section some problems are solved using the BDF2 in two different ways:
• Case A: The advancing formula (26) and the local truncation error (12) of the constant
step size BDF2 have been implemented. This is the way in which the ode15s operates
but it also changes the order of the method. In this case the order is fixed: k = 2. The
same criterion used in the ode15s to change the step size depending on the local error
estimation has been implemented: the step size that follows a successful step is calculated
using (20) and the failed steps are repeated by dividing the step size by 2.
• Case B: The adaptive advancing formula (27) and the adaptive local truncation error (30)
of the BDF2 are implemented. The new step size is defined depending on the local error
estimation, in the same way as in the Case A.
The initialization of both algorithms (Case A and B) has been done in the same way. The use
of the local truncation error as the local error control requires three previous values, yn−1 , yn ,
yn+1 . Hence, two additional values are required in the beginning, which have been calculated
by the trapezoidal rule. In both cases, the first step size h0 has been taken as:
T
h0 = (31)
stepsode15s
being T the time interval and stepsode15s the number of steps given by the ode15s when solving
the same problem. The second step size h1 has been given using the same value as h0 .
4.1 Example 1
Consider the problem [16]:
being λ = −106 and g(t) = sin(10t) + t. Its exact solution is given by:
In Table 2 the number of steps given by each algorithm when different values of Rtol are
considered are tabulated. The number of steps given by the ode15s is also included. We can
observe that the algorithm that uses the variable step formula (Case B) gives less steps than
1021
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
the other. For Rtol = 10−3 the total computational time of the algorithm of the Case B is
four times smaller than the one of the Case A. And for Rtol = 10−4 , the algorithm of the Case
B is 50 times quicker than the one of the Case A. In Figure 2 we can see the euclidean norm
of the error (difference between the exact value and the numerical value) during the interval
of integration. We can observe that the errors of the algorithm B are smaller than the ones
obtained with the algorithm A. The ode15s is superior as it works in variable order 1 − 5 and
in this problem it gives many steps in order 4.
−4 −4
10 10
error
error
−6 −6
10 10
−8 −8
10 10
−10 −10
10 10
−12 −12
10 10
−14 −14
10 10
0 0.5 1 1.5 2 2.5 0 0.5 1 1.5 2 2.5
t t
4.2 Example 2
Consider the system of differential equations considered in [8]:
⎧
⎪
⎨y1 = −20y1 − 0.25y2 − 19.75y3
y2 = 20y1 − 20.25y2 + 0.25y3 , T = [0, 10], y(0) = (1, 0, −1)T (34)
⎪
⎩
y3 = 20y1 − 19.75y2 − 0.25y3
⎧ −0.5t
1
⎪
⎨y1 (t) = 2 e + e−20t (cos 20t + sin 20t)
The exact solution of this problem is: y2 (t) = 12 e−0.5t − e−20t (cos 20t − sin 20t)
⎪
⎩
y3 (t) = − 12 e−0.5t + e−20t (cos 20t − sin 20t)
The variable step size algorithm (Case B) requires less steps than the algorithm A, Table
3. The computational time of both algorithms is similar for Rtol = 10−3 ; for Rtol = 10−4 the
algorithm B is 3 times quicker and it is 16 times quicker for Rtol = 10−5 . The errors obtained
by the algorithm B are also smaller than the ones obtained by the algorithm A, see Figure 3.
Again, the ode15s is superior as many steps are given in order 4.
1022
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
Case A Case A
−1 −1
10 10
Case B Case B
−2 −2
10 Ode15s 10 Ode15s
−3 −3
10 10
error
error
−4 −4
10 10
−5 −5
10 10
−6 −6
10 10
−7 −7
10 10
0 2 4 6 8 10 0 2 4 6 8 10
t t
Example 2, Rtol=10−5
0
10
−1 Case A
10
Case B
−2
10
Ode15s
−3
10
error
−4
10
−5
10
−6
10
−7
10
−8
10
0 2 4 6 8 10
t
4.3 Example 3
We consider the following stiff system considered by Hosseini and Hojjati in [9].
⎧
⎪
⎨y1 = −0.1y1 − 49.9y2
y2 = −50y2 , T = [0, 1], y(0) = (2, 1, 2)T (35)
⎪
⎩
y3 = 70y2 − 120y3
⎧
−50t
⎪
⎨y1 (t) = e + e−0.1t
with stiffness ratio 1200 and exact solution: y2 (t) = e−50t
⎪
⎩
y3 (t) = e−50t + e−120t
Again the algorithm of the case B requires less computational time, about 10 times less than
the algorithm A for Rtol = 10−5 and the results are superior, see Table 4 and Figure 4.
1023
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
Case A Case A
−1
10
Case B −2
10
Case B
−2
10
Ode15s Ode15s
−3
10 −4
10
error
error
−4
10
−6
−5 10
10
−6
10
−8
10
−7
10
−8 −10
10 10
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
t t
4.4 Example 4
We consider the following stiff system as considered by Cash in [2]:
y1 = −αy1 − βy2 + (α + β − 1)e−t
, T = [0, 20], y(0) = (1, 1)T (36)
y2 = βy1 − αy2 + (α − β − 1)e−t
The eigenvalues of the Jacobian matrix are −α ± βi, and its exact solution is this one:
y1 (t) = y2 (t) = e−t . We have solved the problem for α = 1, β = 15. In Table 5 the number
of steps given in each case is tabulated. The variable step size algorithm (Case B) requires
less steps than the algorithm A. In all the cases the computational time of the algorithm B
is smaller than the one of the algorithm A: 10 times smaller for Rtol = 10−3 , 3 times smaller
for Rtol = 10−4 and 30 times smaller for Rtol = 10−5 . Again, the results obtained with the
algorithm B are smaller than the ones obtained with the algorithm A, see Figure 5. This time
the adaptive BDF2 algorithm is also more efficient than the ode15s. This is because the ode15s
only reaches order 3 in this problem. In Figure 6 we can see the error estimations and the step
sizes given by the ode15s in this problem. The order in which each step has been given has
been represented too.
1024
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
Example 4, Rtol=10−3 −4
Example 4, Rtol=10
−1 −1
10 10
−2 Case A −2 Case A
10 10
Case B Case B
−3 −3
10 10
Ode15s Ode15s
−4 −4
10 10
error
error
−5 −5
10 10
−6 −6
10 10
−7 −7
10 10
−8 −8
10 10
−9 −9
10 10
0 5 10 15 20 0 5 10 15 20
t t
−3
x 10
0.12
1
o order 1
0.9 0.1 + order 2
0.8 * order 3
0.7 0.08
error estimation
0.6
0.06
0.5
0.4
0.04
0.3
0.2
0.02
0.1
0 0
0 5 10 15 20 0 5 10 15 20
t t
Figure 6: Error estimation and step sizes for example 4 in ode15s, Rtol = 10−3 .
5 Conclusions
When we are solving systems of stiff ODEs by numerical integration, it is crucial the use of
algorithms with good accuracy and stability properties. It can be concluded from this analysis
that in general, the adaptive BDF2 algorithm is more efficient than the one that uses the
constant step size advancing formulae.
Acknowledgements. The first author was partially funded by the Basque Government Con-
solidated Research Group Grant IT649-13 on “Mathematical Modeling, Simulation, and Indus-
trial Applications (M2SI)”.
References
[1] P. Bogacki and L. F. Shampine. A 3(2) pair of Runge-Kutta formulas. Appl. Math. Lett., 2:1–9,
1989.
[2] J. R. Cash. On the integration of stiff systems of ODEs using extended backward differentiation
formula. Numer. Math., 34 (2):235–246, 1980.
1025
Implementation of an adaptive BDF2 formula Alberdi, Anza and Chatzipantelidis
[3] J. R. Dormand and P. J. Prince. A family of embedded Runge-Kutta formulae. J. Comput. Appl.
Math., 6 (1):19–26, 1980.
[4] C. W. Gear. Numerical initial value problems in Ordinary Differential Equations. Prentice Hall,
New Jersey, 1971.
[5] E. Hairer and G. Wanner. Solving ordinary differential equations, II, Stiff and Differential Algebraic
Problems. Springer, Berlin, 1991.
[6] E. Hairer, G. Wanner, and S. P. N ørsett. Solving ordinary differential equations, I, Nonstiff
problems. Springer, Berlin, 1993.
[7] M. T. Heath. Scientific Computing. An introductory survey. Mc Graw Hill, New York, 1997.
[8] G. Hojjati, M. Y. Rahimi Ardabili, and S. M. Hosseini. A-EBDF: an adaptative method for
numerical solution of stiff systems of ODEs. Math. Comput. Simul., 66:33–41, 2004.
[9] S. M. Hosseini and G. Hojjati. Matrix-free MEBDF method for numerical solution of systems of
ODEs. Math. Comput. Modell., 29:67–77, 1999.
[10] The Math Works Inc. http://www.mathworks.com.
[11] J. D. Lambert. Computational Methods in Ordinary Differential Equations. Wiley, London, 1973.
[12] L. F. Shampine and R. M. Corless. Initial value problems for ODEs in problem solving environ-
ments. J. Comput. Appl. Math., 125:31–40, 2000.
[13] L. F. Shampine, I. Gladwell, and S. Thompson. Solving ODEs with Matlab. Cambridge University
Press, New York, 2003.
[14] L. F. Shampine and M. K. Gordon. Computer Solution of Ordinary Differential Equations: The
Initial Value Problem. W. H. Freeman, San Francisco, 1975.
[15] L. F. Shampine and M. W. Reichelt. The MATLAB ODE Suite. SIAM J. Sci. Comput., 18
(1):1–22, 1997.
[16] J. Vigo-Aguiar, J. Martin-Vaquero, and R. Criado. On the stability of exponential fitting BDF
algorithms. Journal of Computational and Applied Mathematics, 175:183–194, 2005.
1026