cise301_topic8l4&5kfupm1 cise301: numerical methods topic 8 ordinary differential equations...
TRANSCRIPT
CISE301_Topic8L4&5 KFUPM 1
CISE301: Numerical Methods
Topic 8 Ordinary Differential
Equations (ODEs)Lecture 28-36
KFUPM
Read 25.1-25.4, 26-2, 27-1
CISE301_Topic8L4&5 KFUPM 2
Outline of Topic 8 Lesson 1: Introduction to ODEs Lesson 2: Taylor series methods Lesson 3: Midpoint and Heun’s method Lessons 4-5: Runge-Kutta methods Lesson 6: Solving systems of ODEs Lesson 7: Multiple step Methods Lesson 8-9: Boundary value Problems
CISE301_Topic8L4&5 KFUPM 3
Lecture 31Lesson 4: Runge-Kutta
Methods
CISE301_Topic8L4&5 KFUPM 4
Learning Objectives of Lesson 4 To understand the motivation for using
Runge-Kutta (RK) method and the basic idea used in deriving them.
To get familiar with Taylor series for functions of two variables.
To use RK method of order 2 to solve ODEs.
CISE301_Topic8L4&5 KFUPM 5
Motivation We seek accurate methods to solve ODEs
that do not require calculating high order derivatives.
The approach is to use a formula involving unknown coefficients then determine these coefficients to match as many terms of the Taylor series expansion as possible.
CISE301_Topic8L4&5 KFUPM 6
Runge-Kutta Method
1
2 1
1 1 2 2
1 2
( , )
( , )
( ) (
Second Order Rung
)
Problem:
, , ,
such that is as accurate as poss
e-Kutta (
ible
RK2
.
)
K h f t x
K h f t h x K
x t h x t w K w K
Find w w
x(t h)
CISE301_Topic8L4&5 KFUPM 7
Taylor Series in Two Variables
The Taylor Series discussed in Chapter 4 is extended to the 2-independent
variable case.This is used to prove RK formula.
CISE301_Topic8L4&5 KFUPM 8
Taylor Series in One Variable
1( ) ( )
0
The Taylor Series expansion of ( )
( ) ( ) ( )! !
i nni n
i
f x
h hf x h f x f x
i n
where x is between x and x h
Approximation Error
CISE301_Topic8L4&5 KFUPM 9
Taylor Series in One Variable- Another Look -
hxxx
xfdx
dh
nxf
dx
dh
ihxf
f(x)
hxfdx
xfdhxf
dx
dh
nn
i
i
iii
ii
i
and between is
)(!
1)(
!
1)(
ofexpansion SeriesTaylor The
)()(
)(
Define
1
0
)(
CISE301_Topic8L4&5 KFUPM 10
Definitions
2
22
2
2
22
2
1
0
),(),(2
),(),(
),(),(),(
),(),(
),(
y
yxfk
yx
yxfkh
x
yxfhyxf
yk
xh
y
yxfk
x
yxfhyxf
yk
xh
yxfyxfy
kx
h
x
fhyxf
xh
Define
i
ii
i
CISE301_Topic8L4&5 KFUPM 11
Taylor Series Expansion
)0,0(
''
)0.0(
1
)0.0(
0
2
),(
4),(
(0,0)at evaluated sderivative Parial
)2)(1(,
yx fkfhyxfy
kx
h
yxfy
kx
h
yxxy)f(x
CISE301_Topic8L4&5 KFUPM 12
Taylor Series in Two Variables
),( and ),(between joining line on the is),(
),(!
1),(
!
1),(
, ofexpansion SeriesTaylor The
1
0
kyhxyxyx
errorionapproximat
yxfy
kx
hn
yxfy
kx
hi
kyhxf
y)f(xnn
i
i
x x+h
y
y+k
CISE301_Topic8L4&5 KFUPM 13
Runge-Kutta Method
1
2 1
1 1 2 2
1 2
( , )
( , )
( ) ( )
Problem:
RK
, , ,
such that is as accurate as possibl
2
e.
K h f t x
K h f t h x K
x t h x t w K w K
Find w w
x(t h)
CISE301_Topic8L4&5 KFUPM 14
Runge-Kutta Method
)( ),()()(
),(2
1 ),(
)),(,( ),()()(
...)('''6
)(''2
)(')()(
possible. as many terms asmatch to
,,, :Problem
3'22
'2221
2''
21
32
21
hOffhwfhwxtfhwwtxhtx
xtfx
ht
hffhfhffhxhtf
xtfhxhtfhwxtfhwtxhtx
txh
txh
thxtxhtx
wwFind
xt
xt
CISE301_Topic8L4&5 KFUPM 15
Runge-Kutta Method
)( ),()()(
...)('''6
)(''2
)(')()(
3'22
'2221
32
hOffhwfhwxtfhwwtxhtx
txh
txh
thxtxhtx
xt
1,1,5.0,5.0
solution possibleOne
5.0,5.0,1
21
2221
ww
wwww
CISE301_Topic8L4&5 KFUPM 16
Runge-Kutta Method
1
2 1
1 2
( , )
( , )
1( ) ( )
2
RK2
K h f t x
K h f t h x K
x t h x t K K
CISE301_Topic8L4&5 KFUPM 17
Runge-Kutta MethodAlternative Formula
1
2 1
1 2
( , )
( , )
( ) ( )2
RK2
F f t x
F f t h x hF
hx t h x t F F
CISE301_Topic8L4&5 KFUPM 18
Runge-Kutta MethodAlternative Formula
1
2 1
1 2
( , )
(
Alternative F
, )
( ) ( )2
orm
F f t x
F f t h x hF
hx t h x t F F
1
2 1
1 2
( , )
( , )
1( ) ( )
2
RK2
K h f t x
K h f t h x K
x t h x t K K
CISE301_Topic8L4&5 KFUPM 19
Runge-Kutta MethodAlternative Formulas
1
2 1
1 2
RK2 Formulas (select 0)
( , )
( , )
1 1( ) ( ) 1
2 2
K h f t x
K h f t h x K
x t h x t F F
2
1,
2
11,
number zero-nonany Pick
solutionanother
5.0,5.0,1
21
2221
ww
wwww
CISE301_Topic8L4&5 KFUPM 20
Runge-Kutta Method
1
2 1
3 2
4 3
1 2 3 4
( , )
1 1( , )
2 21 1
( , )2 2
( , )
Fourth Order Runge-Kutta (R
1( ) ( ) 2 2
6
K4)
K h f t x
K h f t h x K
K h f t h x K
K h f t h x K
x t h x t K K K K
CISE301_Topic8L4&5 KFUPM 21
Second order Runge-Kutta Method Example
2 3
Solve the following system to find (1.02) using RK2
( ) 1 ( ) , (1) 4, 0.01
x
x t x t t x h
CISE301_Topic8L4&5 KFUPM 22
Second order Runge-Kutta Method Example
2 3
2 31
2 32 1
1 2
Solve the following system to find (1.02) using RK2
( ) 1 ( ) , (1) 4, 0.01
STEP1:
( , ) 0.01(1 ) 0.18
( , ) 0.01(1 ( 0.18) ( .01) ) 0.1662
1 1(1 0.01) (1) 4 (0.18
2 2
x
x t x t t x h
K h f t x x t
K h f t h x K x t
x x K K
0.1662) 3.8269
CISE301_Topic8L4&5 KFUPM 23
Second order Runge-Kutta Method Example
6662.3)1546.01668.0(2
18269.3
2
1)01.1()01.001.1(
1546.0))01.()1668.0(1(01.0),(
1668.0)1(01.0),(
2 STEP
21
3212
321
KKxx
txKxhtfhK
txxtfhK
CISE301_Topic8L4&5 KFUPM 24
RK2 Using
[1,2]for tSolution
,4)1(,)(1)( 32
xttxtx
CISE301_Topic8L4&5 KFUPM 25
Summary RK methods generate an accurate solution
without the need to calculate high order derivatives.
Second order RK have local truncation error of order O(h3).
Fourth order RK have local truncation error of order O(h5).
N function evaluations are needed in the Nth order RK method.
CISE301_Topic8L4&5 KFUPM 26
Lecture 32Lesson 5: Applications of Runge-Kutta Methods to Solve First Order ODEs
CISE301_Topic8L4&5 KFUPM 27
Learning Objectives of Lesson 5 Use Runge-Kutta methods of different
orders to solve first order ODEs.
CISE301_Topic8L4&5 KFUPM 28
Runge-Kutta Method
1
2 1
1 1 1 2 2
1 2
1
( , )
( , )
Problem:
, , ,
such that i
Second Order Runge Kutta (
s as accurate as possible.
RK2)
i i
i i
i i
i
K f x y
K f x h y K h
y y w K w K
Find w w
y
CISE301_Topic8L4&5 KFUPM 29
Runge-Kutta Methods
RK2
1
2 1
1 1 2
Second Order Runge-Kutta
( , )
( , )
R
2
( K2)
i i
i i
i i
K f x y
K f x h y K h
hy y K K
CISE301_Topic8L4&5 KFUPM 30
Runge-Kutta Methods
1
2 1
3 1 2
1 2 3
(
Third
, )
1 1( , )
2 2( , 2 )
1( ) ( ) 4
6
Order Runge Kutta (RK3)
i i
i i
i i
K f x y
K f x h y K h
K f x h y K h K h
y x h y x K K K
RK3
CISE301_Topic8L4&5 KFUPM 31
Runge-Kutta Methods
1
2 1
3 2
4 3
1 1 2 3 4
( , )
1 1( , )
2 21 1
( , )2
Fourth Order R
2(
unge Kutta (
, )
2 2
K4
6
R )
i i
i i
i i
i i
i i
K f x y
K f x h y K h
K f x h y K h
K f x h y K h
hy y K K K K
RK4
CISE301_Topic8L4&5 KFUPM 32
Runge-Kutta Methods
Higher order Runge-Kutta methods are available.
Higher order methods are more accurate butrequire more calculations.
Fourth order is a good choice. It offers good accuracy with a reasonable calculation effort.
CISE301_Topic8L4&5 KFUPM 33
Fifth Order Runge-Kutta Methods
654311
543216
415
324
213
12
1
7321232790
)7
8
7
12
7
12
7
2
7
3,(
)16
9
16
3,
4
3(
)2
1,
2
1(
)8
1
8
1,
4
1(
)4
1,
4
1(
),(
KKKKKh
yy
hKhKhKhKhKyhxfK
hKhKyhxfK
hKhKyhxfK
hKhKyhxfK
hKyhxfK
yxfK
ii
ii
ii
ii
ii
ii
ii
CISE301_Topic8L4&5 KFUPM 34
Second Order Runge-Kutta Method
needed steps of# Determine
)(
),(
:Given
00
h
yxy
yxfdx
dy
CISE301_Topic8L4&5 KFUPM 35
Second Order Runge-Kutta Method
211
12
1
00
2
),(
),(
2
needed steps of# Determine
)(
),(
:Given
KKh
yy
hKyhxfK
yxfK
formulaRK
h
yxy
yxfdx
dy
ii
ii
ii
CISE301_Topic8L4&5 KFUPM 36
Second Order Runge-Kutta Method
2112
1112
111
01
2101
1002
001
2
),(
),(
:2 Step
2
),(
),(
:1 Step
KKh
yy
hKyhxfK
yxfK
hxx
KKh
yy
hKyhxfK
yxfK
211
12
1
00
2
),(
),(
2
needed steps of# Determine
)(
),(
:Given
KKh
yy
hKyhxfK
yxfK
formulaRK
h
yxy
yxfdx
dy
ii
ii
ii
CISE301_Topic8L4&5 KFUPM 37
Example 1Second Order Runge-Kutta Method
)02.1(),01.1(findto
4)1(,1
equation aldifferenti thesolve to
method Kutta Rungeorder second theUse
32
yy
yxydx
dy
CISE301_Topic8L4&5 KFUPM 38
Example 1Second Order Runge-Kutta Method
)02.1(),01.1(2
4)1(,1
:Problem
32
yyfindtoRKUse
yxydx
dy
4,1
1),(
0.01h
00
32
yx
xyyxf
CISE301_Topic8L4&5 KFUPM 39
Example 1Second Order Runge-Kutta Method
8269.3)62.1618(2
01.04
2
62.16))01.()18.0(1(),(
0.18)1(),(
:1 Step
2101
30
201002
30
20001
KKh
yy
xyhKyhxfK
xyyxfK
)02.1(),01.1(2
4)1(,1
:Problem
32
yyfindtoRKUse
yxydx
dy
4,1
1),(
0.01h
00
32
yx
xyyxf
CISE301_Topic8L4&5 KFUPM 40
Example 1Second Order Runge-Kutta Method
)02.1(),01.1(2
4)1(,1
:Problem
32
yyfindtoRKUse
yxydx
dy
8269.3,01.1
1),(
0.01h
11
32
yx
xyyxf
CISE301_Topic8L4&5 KFUPM 41
Example 1Second Order Runge-Kutta Method
6662.3)46.1568.16(2
01.08269.3
2
46.15))01.()1668.0(1(),(
68.16)1(),(
:2 Step
2112
31
211112
31
21111
KKh
yy
xyhKyhxfK
xyyxfK
)02.1(),01.1(2
4)1(,1
:Problem
32
yyfindtoRKUse
yxydx
dy
8269.3,01.1
1),(
0.01h
11
32
yx
xyyxf
CISE301_Topic8L4&5 KFUPM 42
Example 1Summary of the solution
6662.30212
8269.30111
0000.40010
.
.
.
yxi ii
)02.1(),01.1(2
4)1(,1
:Problem
32
yyfindtoRKUse
yxydx
dy
Summary of the solution
CISE301_Topic8L4&5 KFUPM 43
Solution after 100 steps
CISE301_Topic8L4&5 KFUPM 44
Example 24th-Order Runge-Kutta Method
)4.0()2.0(4
2.0
5.0)0(
1 2
yandycomputetoRKUse
h
y
xydx
dy
See RK4 Formula
CISE301_Topic8L4&5 KFUPM 45
Example 2Fourth Order Runge-Kutta Method
)4.0(),2.0(4
5.0)0(,1
:Problem
2
yyfindtoRKUse
yxydx
dy
CISE301_Topic8L4&5 KFUPM 46
Example 2Fourth Order Runge-Kutta Method
5.0,0
1),(
0.2h
00
2
yx
xyyxf
8293.0226
7908.12.016545.01),(
654.11.0164.01)2
1,
2
1(
64.11.015.01)2
1,
2
1(
5.11),(
:1Step
432101
2003004
2002003
2001002
200001
KKKKh
yy
xyhKyhxfK
xyhKyhxfK
xyhKyhxfK
xyyxfK
)4.0(),2.0(4
5.0)0(,1
:Problem
2
yyfindtoRKUse
yxydx
dy
See RK4 Formula
CISE301_Topic8L4&5 KFUPM 47
Runge-Kutta Methods
43211
34
23
12
1
226
),(
)2
1,
2
1(
)2
1,
2
1(
),(
(RK4) Kutta RungeOrder Fourth
KKKKh
yy
hKyhxfK
hKyhxfK
hKyhxfK
yxfK
ii
ii
ii
ii
ii
RK4
CISE301_Topic8L4&5 KFUPM 48
Example 2 Fourth Order Runge-Kutta Method
8293.0,2.0
1),(
0.2h
00
2
yx
xyyxf
2141.1226
2.0
0555.2),(
9311.1)2
1,
2
1(
9182.1)2
1,
2
1(
1.7893 ),(
:2Step
432112
3114
2113
1112
111
KKKKyy
hKyhxfK
hKyhxfK
hKyhxfK
yxfK
)4.0(),2.0(4
5.0)0(,1
:Problem
2
yyfindtoRKUse
yxydx
dy
CISE301_Topic8L4&5 KFUPM 49
Example 2Summary of the solution
2141.14.02
8293.02.01
5.00.00ii yxi
)4.0(),2.0(4
5.0)0(,1
:Problem
2
yyfindtoRKUse
yxydx
dy
Summary of the solution
CISE301_Topic8L4&5 KFUPM 50
Remaining Lessons in Topic 8Lesson 6:Solving Systems of high order ODE
Lesson 7:Multi-step methods
Lessons 8-9:Methods to solve Boundary Value Problems