ArticlePDF Available

## Abstract and Figures

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 Differential Equation (ODE) systems are obtained respectively. These ODE systems usually present high stiffness, so numerical methods with good stability properties are required in their resolution. 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.
Content may be subject to copyright.
Implementation of an Adaptive BDF2 Formula and
Comparison with the MATLAB Ode15s
E. Alberdi Celaya
1
, J. J. Anza Aguirrezabala
2
, and P. Chatzipantelidis
3
1
Department of Applied Mathematics, University of the Basque Country UPV/EHU, Bilbao, Spain
elisabete.alberdi@ehu.es
2
Department of Applied Mathematics, University of the Basque Country UPV/EHU, Bilbao, Spain
juanjose.anza@ehu.es
3
Department of Mathematics, University of Crete, Heraklion-Crete, Greece
chatzipa@math.uoc.gr
Abstract
After applying the Finite Element Metho d (FEM) to the diﬀusion-type and wave-type
Partial Diﬀerential Equations (PDEs), a ﬁrst order and a second order Ordinary Diﬀeren-
tial Equation (ODE) systems are obtained respectively. These ODE systems usually present
high stiﬀness, so numerical methods with good stability properties are required in their reso-
lution. MATLAB oﬀers a set of open source adaptive step functions for solving ODEs. One
of these functions is the ode15s recommended to solve stiﬀ problems and which is based on
the Backward Diﬀerentiation 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 lo cal 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 eﬃcient than the one implemented in MATLAB.
Keywords: PDEs, stiﬀ ODEs, Backward Diﬀerentiation Formula, adaptive BDF2
1 Introduction
Numerous phenomena of science and engineering are modelled mathematically using systems of
Partial Diﬀerential 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, ﬂuids and gases with their corresp onding forces
can be deduced. Similarly, ﬂow solutions for heat and mass transport problems can be ob-
tained, and interaction problems between diﬀerent media (mechanical, thermal, chemical, or
electromagnetic) can be studied.
Procedia Computer Science
Volume 29, 2014, Pages 1014–1026
ICCS 2014. 14th International Conference on Computational Science
1014 Selection and peer-review under responsibility of the Scientiﬁc Programme Committee of ICCS 2014
doi: 10.1016/j.procs.2014.05.091
c
Open access under CC BY-NC-ND license.
The mathematical modelling of the continuous media by means of diﬀerential equations
shows the existing relationship between diﬀerent applications which lead to similar boundary
value problems. For example, the Laplace generalized PDE, which represents the behaviour of
many stationary problems, is given by:
·
Cu

Conductive flux
+ Du

Convective f lux
+
Eu

Absortion
= f

Source
(1)
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:
· (Cu)=f (2)
Equation
(2) governs the potential problem, which has many applications such as the ﬂux
of an incompressible and non-viscous ﬂuid, the torsion of a proﬁle of any section, the simple
heat conduction or the mass diﬀusion 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 diﬀusion and the wave equation.
The latter is obtained by taking
f = G · u
tt
(x,t):
· Cu(x,t)=G · u
tt
(x,t) u =
G
C
u
tt
(3)
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 diﬀusion-type
and wave-type PDEs with boundary conditions and initial conditions, a ﬁrst order and a second
order Ordinary Diﬀerential 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 stiﬀness, which
means that the greater the ratio of the eigenvalues of the Jacobian matrix, the more stiﬀ the
system of ODEs [5, 7, 11]. This means that a non-signiﬁcant part of the solution requires very
small step sizes to avoid instability of the whole solution. When we are solving systems of stiﬀ
ODEs by numerical integration, it is important to use an accurate algorithm with good stability
properties. Since they were introduced, the Backward Diﬀerentiation Formulae (BDF)  have
been widely used due to their good stability prop erties.
The software package MATLAB oﬀers a set of codes to solve initial value problems [10, 12]:
y
(t
)=f (t, y(t)) ,y(t
0
)=y
0
(4)
on a ﬁnite time interval
T =[t
0
,t
n
]. Some of these ode solvers are recommended to solve nonstiﬀ
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  and the ode45 based on the
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1015
Dormand Prince (5,4) pair . The ode113 is another nonstiﬀ ode solver, which is a PECE
implementation of the Adams Bashforth-Moulton methods .
For stiﬀ problems, the most popular code implemented in MATLAB is the ode15s which
uses the Backward Diﬀerentiation Formulae (BDF)  and the Numerical Diﬀerentiation For-
mulae (NDF) . 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 speciﬁed
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 eﬃcient.
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.
2 The Ode Solver Ode15s
The ode15s is based on the BDF methods , and it is possible to use the BDFs of orders
1 5. The ﬁnal s”oftheode15s indicates that the algorithm is suggested to solve stiﬀ
diﬀerential equations . By default ode15s uses NDF methods  which based on BDF
methods, anticipate a backward diﬀerence of order (
k + 1) when working in order k.Thisterm
has
a positive eﬀect on the local truncation error, making the NDFs more accurate than the
BDFs and not much less stable, see Table 1. This implies that the NDF2 can achieve the same
accuracy as the BDF2 with a step size 26% bigger. This modiﬁcation was proposed for orders
k =1, 2, 3, 4, because it is ineﬃcient for orders greater than 4.
The code always starts solving in order k = 1, and the maximum order to be reached can be
giv
en to the code as data. Assuming that the values
y
n
+1
, y
n
+2
, ...,
y
n+k1
are available, which
are the approximations to the exact solution at the points
t
n
+ h, t
n
+2h, ..., t
n
+(k 1)h,the
BDFs and NDFs compute the value
y
n+k
y(t
n+k
) using the following expressions:
BDFs:
k
j
=1
1
j
j
y
n+k
=
hf
n+k
.
NDFs:
k
j
=1
1
j
j
y
n+k
=
hf
n+k
+
κγ
k
k
+1
y
n+k
.
being f
n+k
= f(t
n+k
,y
n+k
)andγ
k
=
k
j
=1
1
j
.
k κ %step size A(α)ofBDFs A(α)ofNDFs
1 -0.1850 26% 90
90
2 -1/9 26% 90
90
3 -0.0823 26% 86
80
4 -0.0415 12% 73
66
Table 1: NDFs of Klopfenstein and Shampine: eﬃciency and stability with respect to BDFs.
In  an alternative form to write the left-hand side of these two expressions is given, which
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1016
is the same for both cases:
k
j
=1
1
j
j
y
n+k
= γ
k
y
n+k
y
(0)
n+k
+
k
j
=1
γ
j
j
y
n+k1
(5)
where:
γ
j
=
j
l
=1
1
l
y
(0)
n+k
=
k
j
=0
j
y
n+k1
=
0
y
n+k1
+ y
n+k1
+ ... +
k
y
n+k1
y
n+k
y
(0)
n+k
=
k
+1
y
n+k
(6)
Taking into account expression (5) the NDFs can be written as follows:
(1
κ) γ
k
y
n+k
y
(0)
n+k
+
k
j
=1
γ
j
j
y
n+k1
= hf
n+k
(7)
where the values of
κ are in the Table 1. BDF methods are obtained for κ =0.
2.1 Error Estimation in the Ode15s
The ode15s uses the lo cal truncation error as the error estimation:
est
LT E = Ch
k+1
y
k
+1
(t
n
)+O
h
k
+2
(8)
be
ing
C the error constant of the method and k the order of the BDF or NDF formula in which
the o
de15s is solving.
Backward diﬀerences are used to calculate an approximation of
y
k
+1
(t
n
). An approximation
of
y(t) is obtained by using the backward interpolating polynomial of Newton that passes from
the (
k + 2) points {(t
n+i
,y
n+i
)}
for i = 1, 0, 1, 2, ..., k:
y(t) Q(t
)=y
n+k
+
k
+1
j
=1
j
y
n+k
1
j!h
j
j1
m
=0
(t t
n+km
)(9)
And the (
k + 1)th derivative of expression (9) is calculated:
Q
(k
+1)
(t)=
k
+1
y
n+k
1
(k +1)!h
k
+1
(k +1)!=
k
+1
y
n+k
1
h
k
+1
(10)
Obtaining:
y
(k
+1)
(t) Q
(k
+1)
(t)=
k
+1
y
n+k
1
h
k
+1
(11)
Substituting the approximation (11) in (8), the error estimation of the ode15s in terms of
backward diﬀerences is obtained:
LT E
C ·∇
k+1
y
n+k
= est (12)
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1017
2.2 Step Size Control in the Ode15s
The ﬁrst step size can be given to the code as data . Nevertheless, a failed step is easily
repaired by the control of the step of the algorithm. Alternatively the ode15s can automatically
set a trial ﬁrst step size.
The ode15s is not allowed to change either the order or the step size until a minimum of
(k + 2) consecutive steps are given using the same order formula and the same step size. If one
step
is unsuccessful, the order of the method or the step size are reduced. When the compulsory
(k + 2) successful steps are given, it is possible to change the order and the step size. In this
case, the step sizes which correspond to orders (
k 1) (for k>1), k and (k + 1) (whenever the
maximum order deﬁned has not been reached) are calculated.
t
n1
to t
n
with step size h using the k-order BDF/NDF formula, the
local error estimation of the ode15s is:
est
LT E = h
k
+1
φ(t
n
)+O(h
k
+2
) (13)
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 veriﬁed the tolerance requirement.
In b oth 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 lo cal error will be :
(σ · h)
k
+1
φ(t
n
+1
)+
O
(σh)
k
+2
(14)
By making use of Taylor’s developments:
φ(t
n
+1
)=
φ(t
n
)+
(t
n
)+O
h
2
(15)
Expression (14) turns into:
(σ · h)
k
+1
φ(t
n
+1
)+
O
(σh)
k
+2
= σ
k
+1
h
k
+1
φ(t
n
)+O
h
k
+2
= σ
k
+1
est
+ O
h
k
+2
(16)
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 veriﬁed, where
Rtol is the speciﬁed tolerance. This step size is:
σ · h =
Rtol
est
1
/k+1
· h (17)
Because a failed step is expensive, the co des use a fraction of the predicted step. The ode15s
uses a safety factor
F
S
=
5
6
and the new step size for order k is:
h
k
= F · h
(18)
where
F = F
S
· σ
. A new variable z is deﬁned as follows:
z =1.2
est
Rtol
1/(k
+1)
(19)
Taking into account (19) the factor
F =1/z represen
ts the hyperbola of Figure 1. Two regions
can be clearly distinguished, separated by
est = Rtol,where
z
S
=1.2 is veriﬁed. In this
case, the factor F takes the value of the safety factor: F
S
=
5
6
. For a trial step h,theode15s
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1018
z
S
F
U
F
L
F
S
z
U
z
L
z
F
failed step
successful
step
Figure 1: The factor F as function of the variable z.
computes the values of est and z, and the step is considered successful if z z
S
=1.2is
veriﬁed.
When the given step is successful, that is to say
z [0, 1.2], or equivalently F
5
6
,
,an
upper threshold
F
U
= 10 is e stablished and the step size of the k-order method is deﬁned as:
h
k
=
F
U
·
h, z z
U
F ·
h, z
S
<z z
U
(20)
where
F
U
= 10, z
U
=
1
F
U
=0.1andz
S
=1.2.
In a similar way, the step sizes
h
k1
and h
k
+1
whichcorrespondtothemethodsoforders
(k 1) and (k + 1) are calculated, being the safety factors
10
13
and
10
14
respectively. The error
estimations of the methods of order (
k 1) and (k + 1) are calculated, est
k1
and est
k+1
.
And the actual step size is multiplied by the factors F
k1
=
1
z
k1
and F
k
+1
=
1
z
k
+1
respectively:
z
k1
=1.3 ·
est
k1
Rtol
1
/k
,z
k+1
=1
.4 ·
est
k+1
Rtol
1/(k
+2)
(21)
The step sizes
h
k1
and h
k
+1
are deﬁned as follows, being the upper thresholds
F
k1
,U
=10
and
F
k
+1,U
= 10:
h
k1
=
F
k1
,U
· h, z
k1
z
k1,U
F
k1
· h, z
k1,S
<z
k1
z
k1,U
(22)
h
k
+1
=
F
k
+1,U
· h, z
k+1
z
k
+1,U
F
k
+1
· h, z
k+1,S
<z
k+1
z
k
+1,U
(23)
where
z
k1
,U
=0
.1, z
k1
,S
=1
.3, z
k
+1,U
=0
.1andz
k
+1,S
=1
.4.
When the step sizes
h
k
, h
k1
and h
k
+1
are available, the process that the ode15s follows to
set the next step size is this one:
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1019
1. If h
k1
>h
k
is veriﬁed, the following assignments are made: h
new
= h
k1
and k
new
=
k
1. If h
k1
>h
k
is not veriﬁed, h
new
= h
k
and k
new
= k are considered.
2. Next,
h
k
+1
and
h
new
are compared. If
h
k
+1
>h
new
,thevalue
h
k
+1
is stored in
h
new
and
one unit is added to the order
k
new
.
3. Finally, the value h
new
is compared with the step size
h used in the last step. If h
new
>h
,
the next step size will b e h
new
and it will be given with order
k
new
. 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
form
ula is calculated using a lower threshold
F
L
=0.1 as follows:
h
k
=
F ·
h, z
S
<z z
L
F
L
·
h, z > z
L
(24)
where
z
L
=
1
F
L
=10andz
S
=1.2 as before.
When k>1, the step size for order (
k 1) is also calculated as:
h
k1
=
F
k1
·
h, z
k1,S
<z
k1
z
k1,L
F
k1
,L
· h, z
k1
>z
k1,L
(25)
where
F
k1
,L
=0
.1, z
k1
,L
=
1
F
k1
,L
=10and
z
k1
,S
=1
.3 as before.
If
h
k1
>h
k
, the next step will be given using the (k 1)-order formula and the step size
will be the minimum value between the present step
h and h
k1
.
In second or posterior trials after an unsuccessful step, the new step size is calulated by
dividing by 2 the actual step.
Even though the ode15s changes the step size depending on the local error estimation, the
advancing formula that uses for the BDFs or NDFs is the constant step size formula. We will
focus on the second order accurate and unconditionally stable BDF2. The advancing formula
used by the ode15s for this method is:
3
2
y
n
+2
2y
n
+1
+
1
2
y
n
=
hf
n+2
(26)
which is the constant step size formula. And the same happens with the expression used to
approximate the local truncation error (12).
Nevertheless, the advancing formula of the adaptive step size BDF2 is given by the next
expression :
y
n
+2
(1 + w
n
+1
)
2
1+2w
n
+1
y
n
+1
+
w
2
n
+1
1+2w
n
+1
y
n
= h
n
+2
1+
w
n
+1
1+2w
n
+1
f
n
+2
(27)
being
w
n
+1
= h
n
+2
/h
n+1
, h
n
+2
= t
n
+2
t
n
+1
and
h
n
+1
= t
n
+1
t
n
.
Taking into account the adaptive advancing formula of the BDF2, the local truncation error
of
the adaptive step size BDF2 becomes:
LT E
= y(t
n
+2
) y
n
+2
h
2
n
+2
(h
n
+1
+ h
n
+2
)
6
y
(3)
(t
n
+2
) (28)
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1020
Approximating the third derivative of (28) by:
y
(3)
(t
n
+2
)
1
h
2
n
+2
y
n
+2
y
n
+1
h
n
+2
1+
h
n
+2
h
n
+1
y
n
+1
y
n
h
n
+1
+
h
n
+2
h
n
+1
h
n
(y
n
y
n1
)
(29)
and substituting (29) in (28), the expression of the local truncation error of the adaptive step
size BDF2 is obtained:
LT E
(h
n
+1
+ h
n
+2
)
6
y
n
+2
y
n
+1
h
n
+2
1+
h
n
+2
h
n
+1
y
n
+1
y
n
h
n
+1
+
h
n
+2
h
n
+1
h
n
(y
n
y
n1
)
(30)
being
h
n
= t
n
t
n1
.
4 Numerical Results
In this section some problems are solved using the BDF2 in two diﬀerent 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 ﬁxed:
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.
of
the BDF2 are implemented. The new step size is deﬁned 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,
y
n1
, y
n
,
y
n
+1
. Hence, two additional values are required in the beginning, which have been calculated
by the trapezoidal rule. In both cases, the ﬁrst step size
h
0
has been taken as:
h
0
=
T
steps
ode15
s
(31)
being
T thetimeintervalandsteps
ode15
s
the number of steps given by the ode15s when solving
the same problem. The second step size
h
1
has been given using the same value as h
0
.
4.1 Example 1
Consider the problem :
y
(t
)=λ(y(t) g(t)) + g
(t),T=[0, 2.5],y(0) = 1 (32)
being
λ = 10
6
and g(t)=sin(10t)+t. Its exact solution is given by:
y(t)=e
λt
+ g(t) (33)
In Table 2 the number of steps given by each algorithm when diﬀerent 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
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1021
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 (diﬀerence 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
5and
in this problem it gives many steps in order 4.
Rtol Case A Case B ode15s
10
3
8638
steps 874 steps 160 steps
10
4
78175
steps 3024 steps 206 steps
Table 2: Number of steps given in example 1.
0 0.5 1 1.5 2 2.5
10
−14
10
−12
10
−10
10
−8
10
−6
10
−4
10
−2
10
0
10
2
t
error
Example 1, Rtol=10
−3
Case A
Case B
Ode15s
0 0.5 1 1.5 2 2.5
10
−14
10
−12
10
−10
10
−8
10
−6
10
−4
10
−2
10
0
10
2
t
error
Example 1, Rtol=10
−4
Case A
Case B
Ode15s
Figure 2: Euclidean norm of the error during the simulation in example 1.
4.2 Example 2
Consider the system of diﬀerential equations considered in :
y
1
=
20y
1
0.25y
2
19.75y
3
y
2
=20y
1
20.25y
2
+0.25y
3
y
3
=20y
1
19.75y
2
0.25y
3
,
T
=[0, 10],y(0)
= (1
, 0, 1)
T
(34)
The exact solution of this problem is:
y
1
(t
)=
1
2
e
0.5t
+ e
20t
(cos 20t +sin20t)
y
2
(t
)=
1
2
e
0.5t
e
20t
(cos 20t sin 20t)
y
3
(t
)=
1
2
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
;forRtol =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 o
de15s is superior as many steps are given in order 4.
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1022
Rtol Case A Case B ode15s
10
3
430
steps 126 steps 64 steps
10
4
3385
steps 329 steps 89 steps
10
5
28979
steps 1202 steps 122 steps
Table 3: Number of steps given in example 2.
0 2 4 6 8 10
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
10
0
t
error
Example 2, Rtol=10
−3
Case A
Case B
Ode15s
0 2 4 6 8 10
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
10
0
t
error
Example 2, Rtol=10
−4
Case A
Case B
Ode15s
0 2 4 6 8 10
10
−8
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
10
0
t
error
Example 2, Rtol=10
−5
Case A
Case B
Ode15s
Figure 3: Euclidean norm of the error during the simulation in example 2.
4.3 Example 3
We consider the following stiﬀ system considered by Hosseini and Hojjati in .
y
1
= 0.1y
1
49.9y
2
y
2
=
50y
2
y
3
=70y
2
120y
3
,
T
=[0, 1],y(0)
= (2
, 1, 2)
T
(35)
with stiﬀness ratio 1200 and exact solution:
y
1
(t
)=e
50t
+ e
0.1t
y
2
(t
)=e
50t
y
3
(t
)=e
50t
+ e
120t
Agai
n 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.
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1023
Rtol Case A Case B ode15s
10
3
75 steps 40 steps 68 steps
10
4
702
steps 275 steps 87 steps
10
5
13224
steps 727 steps 104 steps
Table 4: Number of steps given in example 3.
0 0.2 0.4 0.6 0.8 1
10
−8
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
10
0
t
error
Example 3, Rtol=10
−4
Case A
Case B
Ode15s
0 0.2 0.4 0.6 0.8 1
10
−10
10
−8
10
−6
10
−4
10
−2
10
0
t
error
Example 3, Rtol=10
−5
Case A
Case B
Ode15s
Figure 4: Euclidean norm of the error during the simulation in example 3.
4.4 Example 4
We consider the following stiﬀ system as considered by Cash in :
y
1
=
αy
1
βy
2
+(α + β 1)e
t
y
2
=
βy
1
αy
2
+(α β 1)e
t
,
T
=[0, 20],y(0)
= (1
, 1)
T
(36)
The eigenvalues of the Jacobian matrix are
α ± βi,
and its exact solution is this one:
y
1
(t)=y
2
(t)=e
t
. We have solved the problem for α =1 =15. InTable5thenumber
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 eﬃcient than the ode15s. Thisisbecausetheode15s
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.
Rtol Case A Case B ode15s
10
3
403
steps 41 steps 414 steps
10
4
3607
steps 353 steps 399 steps
10
5
35311
steps 654 steps 387 steps
Table 5: Number of steps given in example 4.
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1024
0 5 10 15 20
10
−9
10
−8
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
t
error
Example 4, Rtol=10
−3
Case A
Case B
Ode15s
0 5 10 15 20
10
−9
10
−8
10
−7
10
−6
10
−5
10
−4
10
−3
10
−2
10
−1
t
error
Example 4, Rtol=10
−4
Case A
Case B
Ode15s
Figure 5: Euclidean norm of the error during the simulation in example 4.
0 5 10 15 20
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
x 10
−3
t
error estimation
0 5 10 15 20
0
0.02
0.04
0.06
0.08
0.1
0.12
new step size
t
+ order 2
o order 1
* order 3
Figure 6: Error estimation and step sizes for example 4 in ode15s, Rtol =10
3
.
5 Conclusions
When we are solving systems of stiﬀ 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 eﬃcient than the one that uses the
Acknowledgements. The ﬁrst 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
 P. Bogacki and L. F. Shampine. A 3(2) pair of Runge-Kutta formulas. Appl. Math. Lett., 2:1–9,
1989.
 J. R. Cash. On the integration of stiﬀ systems of ODEs using extended backward diﬀerentiation
formula. Numer. Math., 34 (2):235–246, 1980.
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1025
 J. R. Dormand and P. J. Prince. A family of embedded Runge-Kutta formulae. J. Comput. Appl.
Math., 6 (1):19–26, 1980.
 C.W.Gear. Numerical initial value problems in Ordinary Diﬀerential Equations. Prentice Hall,
New Jersey, 1971.
 E. Hairer and G. Wanner. Solving ordinary diﬀerential equations, II, Stiﬀ and Diﬀerential Algebraic
Problems. Springer, Berlin, 1991.
 E. Hairer, G. Wanner, and S. P. N ørsett. Solving ordinary diﬀerential equations, I, Nonstiﬀ
problems. Springer, Berlin, 1993.
 M.T.Heath.Scientiﬁc Computing. An introductory survey. Mc Graw Hill, New York, 1997.
 G. Hojjati, M. Y. Rahimi Ardabili, and S. M. Hosseini. A-EBDF: an adaptative method for
numerical solution of stiﬀ systems of ODEs. Math. Comput. Simul., 66:33–41, 2004.
 S. M. Hosseini and G. Hojjati. Matrix-free MEBDF method for numerical solution of systems of
ODEs. Math. Comput. Modell., 29:67–77, 1999.
 The Math Works Inc. http://www.mathworks.com.
 J. D. Lambert. Computational Methods in Ordinary Diﬀerential Equations. Wiley, London, 1973.
 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.
 L. F. Shampine, I. Gladwell, and S. Thompson. Solving ODEs with Matlab. Cambridge University
Press, New York, 2003.
 L. F. Shampine and M. K. Gordon. Computer Solution of Ordinary Diﬀerential Equations: The
Initial Value Problem. W. H. Freeman, San Francisco, 1975.
 L. F. Shampine and M. W. Reichelt. The MATLAB ODE Suite. SIAM J. Sci. Comput.,18
(1):1–22, 1997.
 J. Vigo-Aguiar, J. Martin-Vaquero, and R. Criado. On the stability of exponential ﬁtting BDF
algorithms. Journal of Computational and Applied Mathematics, 175:183–194, 2005.
Implementation of an adaptive BDF2 formula Alb erdi, Anza and Chatzipantelidis
1026