+++unit 3 - Numerical Solution Techniques For ODEs
+++unit 3 - Numerical Solution Techniques For ODEs
2
Derive the forward difference
approximation from Taylor series
Taylor’s theorem says that if you know the value of a function ' f ' at a point
xi and all its derivatives at that point, provided the derivatives are
f xi
f xi 1 f xi f xi Δx Δx 2
2!
f xi 1 f xi
f xi 0x
x 3
Forward Difference Approximation
limf x Δx f x
f x
Δx 0 Δx
f x x f x
f x
x
*
4
Graphical Representation Of Forward Difference
Approximation
f(x)
x x+Δx
5
Example 1:
The velocity of a rocket is given by
14 10 4
t 2000 ln 9.8t ,0 t 30
14 10 2100t
4
6
Solution 14 10 4
18 2000 ln 9.818
14 10 4
2100 18
453.02m/s
14 10 4
16 2000 ln 9.816
ti 1 ti 14 10 210016
4
ati
t 392.07m/s
Hence
ti 16
18 16
a16
Δt 2 2
453.02 392.07
ti 1 ti t
2
16 2
18 30.474m/s 2
18 16
a16 The exact value of a 16 ?
2
7
Finite Difference Approximation of Higher Derivatives
f xi
f xi 2 f xi f xi 2Δx 2Δx 2 f xi 2Δx 3
2! 3!
where
xi 2 xi 2Δx
f xi
f xi 1 f xi f xi x x 2 f xi x 3
2! 3!
where
𝑥𝑖+1 =𝑥 𝑖 + Δ 𝑥
8
Finite Difference Approximation of Higher Derivatives Cont.
9
Classification of the Methods
Numerical Methods
for Solving ODE
10
Numerical Methods for ODE
• Euler Methods
– Forward Euler Methods
– Backward Euler Method
– Modified Euler Method
• Runge-Kutta Methods
– Second Order
– Third Order
– Fourth Order
11
(I) Euler’s Method
𝑑𝑦
yi 1 yi f xi , yi h
= 𝑓 ( 𝑥 , 𝑦 ) , 𝑦 ( 0) =𝑦0
𝑑𝑥
y1 y 0 f x0 , y 0 x1 x0
h xi 1 xi
y0 f x0 , y0 h
Example 2:
dy
2 y 1.3e x , y 0 5
dx
is rewritten as
dy
1.3e x 2 y, y 0 5
dx
In this case
f x, y 1.3e x 2 y
13
Example 3:Compare with exact sol
dy
y , y ( 0) 1
dx
f ( x, y ) y, f (0,1) 1
Choose x 0.1
y (0.1) y (0) (1) 0.1 1 0.1 0.9
y (0.2) y (0.1) (0.9) 0.1 0.9 0.09 0.81
y (0.3) y (0.2) (0.81) 0.1 0.81 0.081 0.729
14
Example (cont)
y
1
Exact Solution :
dy
y
dx
ln y x c
y=e–x
y ce x y ( 0) c 1
y ex
x
0.1
15
Example 4: solve
y ' ty 1, y0 y (0) 1, 0 t 1, h 0.25
Solution:
for t0 0, y0 y (0) 1
d
dt
2.2067 10 12 4 81 108 , 0 1200 K
Find the temperature at t 480 seconds using Euler’s method. Assume a step size of
h 240 seconds.
17
Solution
Step 1:
d
dt
2.2067 10 12 4 81 10 8
f t , 2.2067 10 12 4 81 10 8
i 1 i f ti , i h
1 0 f t0 , 0 h
1200 f 0,1200 240
1200 2.2067 10 12 1200 4 81 108 240
1200 4.5579 240
106.09 K
2 1 f t1 , 1 h
106.09 f 240,106.09 240
106.09 2.2067 10 12 106.09 4 81 108 240
106.09 0.017595240
110 .32 K
19
Solution Cont.
The exact solution of the ordinary differential equation is given by the
solution of a non-linear equation as
300
0.92593 ln 1.8519 tan 1 0.00333 0.22067 10 3 t 2.9282
300
The solution to this nonlinear equation at t=480 seconds is (480) 647.57 K
20
Effect of step size?
Table: Temperature at 480 seconds as a function of step size, h
21
Exercise 1:
22
Exercise 2
Solution 1
23
Exercise 2 (Cont’d)
Continue Solution 1
24
Exercise 2 (Cont’d)
Solution 2
25
Exercise 2 (Cont’d)
Continue Solution 2
26
Runge – Kutta Methods
• Euler Method is not very powerful in practical problems, as it
requires very small step size h for reasonable accuracy.
27
nth order R.K. Method
• This method employs the recurrence formula of the form:
yi+1 = yi + a1 k1 + a2 k2 + L + an kn
where k 1 = h f ( x i, y i)
28
(II) Runge-Kutta 2nd Order Method
fi h : a1 a2 1
f 3 eqns,
x h :
2
a2 p1 2
1
f 4 unknowns
y f i h : a2 q11 2
2 1
a2 1 a1 0, p1 1 2 , q11 1
2
yi 1 yi (a1k1 a2 k 2 )h
yi k 2 h yi f ( xi p1h, yi q11 k1h)h
yi 1 yi f ( xi 12 h, yi 12 f ( xi , yi )) h
1
𝑦 𝑖+1 =𝑦 𝑖 + ( 𝑎1 𝑘1 +𝑎2 𝑘2) h =𝑦 𝑖 + ( 𝑘1 +𝑘2 ) h
2
29
Example 6:
A ball at 1200K is allowed to cool down in air at an ambient temperature of 300K.
Assuming heat is lost only due to radiation, the differential equation for the temperature of
the ball is given by
d
2.2067 10 12 4 81 10 8 , 0 1200 K
dt
Find the temperature at t 480 seconds using Runge-Kutta 2nd Order method.
d
2.2067 10 12 4 81 10 8
dt
1 1
i 1 i k1 k 2 h
2 2
30
Solution
Step 1: i 0, t0 0, 0 (0) 1200 K
k 2 f t0 h, 0 k1h
k1 f t0 , o
f 0 240,1200 4.5579 240
f 0,1200
f 240,106.09
2.2067 10 12 1200 4 81 108 2.2067 10 12 106.09 4 81108
4.5579 0.017595
1 1
1 0 k1 k 2 h
2 2
1 1
1200 4.5579 0.017595240
2 2
1200 2.2702 240
655.16 K
31
Solution Cont.
Step 2: i 1, t1 t 0 h 0 240 240, 1 655.16 K
1 1
2 1 k1 k 2 h
2 2
1 1
655.16 0.38869 0.20206240
2 2
655.16 0.29538240
584.27 K
32
Comparison of Euler and Runge-Kutta 2nd Order Methods
q(480)
Step size,
h Runge-Kutta 2nd
Euler
33
(III) Runge-Kutta 4th Order Method
• Mostly commonly used one
• Higher order … more evaluation, but less gain
on accuracy
yn 1 yn 16 (k1 2k 2 2k3 k 4 )h
where
Classical 4th
k1 f ( xn ,yn ) order RK
k 2 f ( xn 12 h,yn 12 k1h)
k3 f ( xn 12 h,yn 12 k 2 h)
k 4 f ( xn h,yn k3 h)
34
Example 7:
• Using R.K. Method of 4th order find y(0.1) and y(0.2).
dy
Given that =3x + ½ y, y (0) = 1 taking h = 0.1.
dx
Solution:
k3 = h f ( x0 + h2 , y0 + k2
2
) = 0.0667
35
Example 8:
A ball at 1200K is allowed to cool down in air at an ambient temperature of 300K.
Assuming heat is lost only due to radiation, the differential equation for the temperature of
the ball is given by
d
dt
2.2067 10 12 4 81 10 8 , 0 1200 K
Find the temperature at t 480 seconds using Runge-Kutta 4th order method.
d
dt
2.2067 10 12 4 81 10 8
f t , 2.2067 10 12 4 81 10 8
1
i 1 i k1 2k 2 2k 3 k 4 h
6
36
Solution
Step 1: i 0, t0 0, 0 (0) 1200
k1 f t0 , o f 0,1200 2.2067 10 12 1200 4 81 108 4.5579
1 1 1 1
k 2 f t0 h, 0 k1h f 0 240 ,1200 4.5579 240
2 2 2 2
f 120,653.05 2.2067 10 12 653.054 81 108 0.38347
1 1 1 1
k3 f t0 h, 0 k 2 h f 0 240 ,1200 0.38347 240
2 2 2 2
f 120,1154 .0 2.2067 10 12 1154 .0 4 81108 3.8954
t t1 t0 h 0 240 240
240 1 675.65 K
38
Solution Cont.
Step 2: i 1, t1 240,1 675.65 K
k1 f t1 , 1 f 240,675.65 2.2067 10 12 675.654 81 108 0.44199
1 1 1 1
k 2 f t1 h, 1 k1h f 240 240 , 675.65 0.44199 240
2 2 2 2
f 360,622.61 2.2067 10 12 622.614 81 108 0.31372
1 1 1 1
k3 f t1 h, 1 k 2 h f 240 240 ,675.65 0.31372 240
2 2 2 2
f 360, 638.00 2.2067 10 12 638.00 4 81108 0.34775
39
Solution Cont.
1
2 1 k1 2k2 2k3 k4 h
6
1
675.65 0.44199 2 0.31372 2 0.34775 0.25351240
6
1
675.65 2.0184 240
6
594.91K
480 2 594.91K
40
Thank you
+974 4495 2222
Location
University of Doha for Science &
Technology
68 Al Tarfa, Duhail North
P.O. Box 24449 Doha, Qatar