Computer Computation - Chapter6 Ode
Computer Computation - Chapter6 Ode
NUMERICAL INTEGRATION OF
ORDINARY DIFFERENTIAL
EQUATIONS
Nabil R. Nassif and Dolly K. Fayad
December 2012
INTRODUCTION
Two types of formulae , explicit or implicit formulae are usually proposed for calculating Yn . Explicit methods reduce to explicit formulae
of the form:
(1)
or equivalently
yi+1 = F (h, ti , yi )
or equivalently
h0+ 1in
yi = F (ti1 , ti , yi1 )
Since our main interest is in the global behavior of the method, i.e.
maxi |ei |, the last inequality indicates that the global error is due to the
accumulation of local truncation errors from previous steps.
Remark 1 The naive expectation is that since the number of steps n =
(T t0 )/h increases as O(h1 ), if the truncation error is O(hp+1) , then
under favorable conditions, the global error would decrease as O(hp ). We
say then that the method is of order p.
Given the value of the solution y at the single point t0 , the purpose of Eulers
method is to compute the value of y at a new point.
A simple and direct approach is to use a rectangular rule to compute integrals,
by making the approximation
f (t, y(t)) f (ti , y(ti )) for all t [ti , ti + h]
where the time step h is sufficiently small. This leads to the following result:
Z ti+1
f (t, y(t)) dt = h f (ti , y(ti )) + O(h2 )
ti
where it can be proved in this case that the local truncation error is O(h2 ).
Thus, integrating (IVP) from ti to ti+1 :
y(ti+1 ) = y(ti ) + h f (ti , y(ti )) + O(h2 )
(8)
Proposition 2 The Eulers explicit method is a first order method. (The Global
Error of RK1 is O(h)).
Example 1 Use Eulers explicit scheme to solve the following initial value problem with time step h = 0.5:
0
y (t) = 1.2y + 7e0.3t t [0, 1.5]
y(0) = 3
The corresponding discrete scheme with one stage is given by:
k1 = 1.2yi + 7e0.3ti
(RK1)
yi+1 = yi + hk1
The numerical results could be presented in a table as follows:
i
0
1
2
3
ti
yi
y0 = 3
y1 = 4.7
y2 = 4.893
y3 = 4.550
0
0.5
1
1.5
k1 = 1.2yi + 7e0.3ti
3.4
0.386
0.686
yi+1 = yi + hK1
y1 = 4.7
y2 = 4.893
y3 = 4.550
9 e
compute the absolute error at each ti value:
i
0
1
2
3
ti
0
0.5
1
1.5
yi
y0 = 3
y1 = 4.7
y2 = 4.893
y3 = 4.550
y(ti )
y(t0 ) = 3
y(t1 ) = 4.072
y(t2 ) = 4.323
y(t3 ) = 4.170
43 1.2t
,
9 e
we can therefore
E= |y(ti ) yi |
E=0
E =0.6277
E = 0.5696
E = 0.3803
The Runge-Kutta methods of order 2 solving the initial value problem (IVP)
are modified Euler s schemes.
The following consequence of the Mean value theorem is needed:
Proposition 3 If f : R2 R is a function of 2 variables and is at least of
class C 1 , then:
f (t, y + O()) = f (t, y) + O()
ti+1
y(ti+1 ) = y(ti ) +
f (t, y(t)) dt
ti
Assuming moreover that f C 2 , the Integral on the right hand side will be
approximated successively by: the Midpoint Rule and the Trapezoidal Rule.
1. The Midpoint Rule method:
Based on the Midpoint Rule, (9) is then:
(10)
h
h
, y(ti + )) + O(h3 )
2
2
By Eulers method:
y(ti +
h
h
) = y(ti ) + f (ti , y(ti )) + O(h2 )
2
2
h
h
, y(ti ) + f (ti , y(ti )) + O(h2 )) + O(h3 )
2
2
Or equivalently:
(12)
h
h
, y(ti ) + f (ti , y(ti )) + O(h3 )
2
2
This last equation suggests the following discrete RK-scheme with 2 stages
k1 = f (ti , yi )
(RK2.M )
k = f (ti + h2 , yi + h2 k1 )
2
yi+1 = yi + hk2
with a local truncation error of O(h3 ).
2. The Trapezoidal Rule method: Heuns method
The second Runge Kutta method of order 2- Heuns method- is also called
the the improved Euler method.
Integrating (IVP), and based on the Trapezoidal Rule, (9) is then:
(13)
y(ti+1 ) = y(ti ) +
h
[f (ti , y(ti )) + f (ti+1 , y(ti+1 ))] + O(h3 )
2
By Eulers method:
y(ti+1 ) = y(ti ) + h f (ti , y(ti )) + O(h2 )
7
implying that:
f (ti+1 , y(ti+1 )) = f (ti+1 , y(ti ) + h f (ti , y(ti )) + O(h2 ))
Equation ( 13 ) is then:
h
[f (ti , y(ti )) + f (ti+1 , y(ti ) + hf (ti , y(ti )))] + O(h3 )
2
This last equation suggests the following discrete RK-scheme with 2 stages
k1 = f (ti , yi )
k2 = f (ti + h, yi + hk1 )
(RK2.H)
yi+1 = yi + h2 (k1 + k2 )
y(ti+1 ) = y(ti ) +
(14)
k1 = 1.2yi + 7e0.3ti
k2 = 1.2(yi + h(1.2yi + 7e0.3ti )) + 7e0.3(ti +h)
(RK2.H)
yi+1 = yi + h2 [k1 + k2 ]
The numerical results could be presented in a table as follows:
i
0
1
2
3
ti
0
0.5
1
1.5
yi
3
3.946
4.188
4.063
k1
3.4
1.290
0.160
k2
0.385
0.323
0.6586
yi+1 = yi + h2 (K1 + K2 )
3.946
4.188
4.063
ti
0
0.5
1
1.5
yi
y0 = 3
y1 =
y2 = 4.188
y3 = 4.063
y(ti )
y(t0 ) = 3
y(t1 ) = 4.072
y(t2 ) = 4.323
y(t3 ) = 4.170
8
E= |y(ti ) yi |
E=0
E =0.126
E = 0.135
E = 0.106
1
yi+1 = yi + h(k1 + 2k2 + 2k3 + k4 )
6
k1
k2
k
3
k4
= f (ti , yi )
= f (ti + h2 , yi + h2 k1 )
= f (ti + h2 , yi + h2 k2 )
= f (ti + h, yi + hk3 )
Thus, the next value yi+1 is obtained at the expense of evaluating the
function f four times. It is determined by the present value yi plus the
product of the time step h and an estimated slope. That slope is a weighted
average of slopes:
k1 is the slope at the beginning of the interval
k2 is the slope at the midpoint of the interval, using slope k1 to
determine the value of y at the point tn + h2 using Eulers method.
k3 is again the slope at the midpoint of the interval, but now using
slope k2 to determine the y-value
k4 is the slope at the end of the interval, with its y-value determined
using k3 .
In averaging the 4 slopes, greater weight is given to the slopes at the midpoint.
The corresponding discrete scheme is then:
k1 = f (ti , yi )
k
2 = f (ti + h2 , yi + h2 k1 )
(RK4)
k3 = f (ti + h2 , yi + h2 k2 )
k4 = f (ti + h, yi + hk3 )
10
EXERCISES
ti
.
.
yi
.
.
K1
.
.
yi+1
.
.
(b) Write first the discrete scheme of Heuns method, (RK2.H), then use
2 steps of this scheme to approximate y(1.25) and y(1.50).
Discrete Scheme
...............................................................
................................................................
(RK2.H)
yi+1 = ....................................................
Express all the computed results with a precision p = 3.
i
0
1
ti
.
.
yi
.
.
K1
.
.
11
K2
.
.
yi+1
.
.
(c) Write first the discrete scheme of the Midpoint Rule method, (RK2.M),
then use 2 steps of this scheme to approximate y(1.25) and y(1.50).
Discrete Scheme
...............................................................
................................................................
(RK2.M )
yi+1 = ....................................................
Express all the computed results with a precision p = 3.
i
0
1
ti
.
.
yi
.
.
K1
.
.
K2
.
.
12
yi+1
.
.