Sie sind auf Seite 1von 36

CISE301_Topic8L4&5 1

SE301: Numerical Methods


Topic 8
Ordinary Differential Equations (ODEs)
Lecture 28-36
KFUPM
(Term 101)
Section 04

Read 25.1-25.4, 26-2, 27-1
CISE301_Topic8L4&5 2
Outline of Topic 8
Lesson 1: Introduction to ODEs
Lesson 2: Taylor series methods
Lesson 3: Midpoint and Heuns 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 3

Lecture 31
Lesson 4: Runge-Kutta Methods
CISE301_Topic8L4&5 4
Learning Objectives of Lesson 4
To understand the motivation for using
Runge Kutta method and the basic idea
used in deriving them.
To Familiarize with Taylor series for
functions of two variables.
Use Runge Kutta of order 2 to solve
ODEs.
CISE301_Topic8L4&5 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.
CISE301_Topic8L4&5 6
Second Order Runge-Kutta Method
possible. as accurate as is that such
, , ,
: Problem
) , (
) , (
1
2 1
2 2 1 1 1
1 2
1
+
+
+ + =
+ + =
=
i
i i
i i
i i
y
w w Find
K w K w y y
K y h x f h K
y x f h K
| o
| o
CISE301_Topic8L4&5 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 8
Taylor Series in One Variable
h x and x between is x where
x f
n
h
x f
i
h
h x f
f (x) n
n
n
i
n
i
i
+
+
+ = +
+
+
=

) (
)! 1 (
) (
!
) (
of expansion Series Taylor order The
) 1 (
1
) (
0
th
Approximation
Error
CISE301_Topic8L4&5 9
Derivation of 2
nd
Order
Runge-Kutta Methods 1 of 5
) ( ) , ( '
2
) , (
: as written is which
) (
2
) , ( : ODE solve to Used
Expansion Series Taylor Order Second
3
2
1
3
2
2 2
1
h O y x f
h
y x f h y y
h O
dx
y d h
dx
dy
h y y
y x f
dx
dy
i i i i i i
i i
+ + + =
+ + + =
=
+
+
Derivation of 2
nd
Order
Runge-Kutta Methods 2 of 5
CISE301_Topic8L4&5 10
) (
2
) , ( ) , (
:
) , (
) , ( ) , (
) , ( '
ation differenti rule - chain by obtained is ) , ( ' where
3
2
1
h O
h
y x f
y
f
x
f
h y x f y y
ng Substituti
y x f
y
f
x
f
dx
dy
y
y x f
x
y x f
y x f
y x f
i i i i i i
+
|
|
.
|

\
|
c
c
+
c
c
+ + =
c
c
+
c
c
=
c
c
+
c
c
=
+
CISE301_Topic8L4&5 11
Taylor Series in Two Variables
) , ( and ) , ( between joining line the on is ) , (

) , (
)! 1 (
1
) , (
!
1

...

2
! 2
1

) , ( ) , (
1
0
2
2
2
2
2
2
2
k y h x y x y x
error ion approximat
y x f
y
k
x
h
n
y x f
y
k
x
h
i
y x
f
hk
y
f
k
x
f
h
y
f
k
x
f
h y x f k y h x f
n
n
i
i
+ +
|
|
.
|

\
|
c
c
+
c
c
+
+
|
|
.
|

\
|
c
c
+
c
c
=
+
|
|
.
|

\
|
c c
c
+
c
c
+
c
c
+
|
|
.
|

\
|
c
c
+
c
c
+ = + +
+
=

CISE301_Topic8L4&5 12
Derivation of 2
nd
Order
Runge-Kutta Methods 3 of 5
) , ( ) , (
: ng Substituti
) , (
) , (
that such , , , : Problem
1 2 1 1
2 2 1 1 1
1 2
1
2 1
K y h x f h w y x f h w y y
K w K w y y
K y h x f h K
y x f h K
w w Find
i i i i i i
i i
i i
i i
| o
| o
| o
+ + + + =
+ + =
+ + =
=
+
+
Derivation of 2
nd
Order
Runge-Kutta Methods 4 of 5
CISE301_Topic8L4&5 13
... ) , ( ) , ( ) (
... ) , ( ) (
... ) , ( ) , (
:
... ) , ( ) , (
2
2
2
2 2 1 1
1 2 2 1 1
1 2 1 1
1 1
+
c
c
+
c
c
+ + + =
|
|
.
|

\
|
+
c
c
+
c
c
+ + + =
|
|
.
|

\
|
+
c
c
+
c
c
+ + + =
+
c
c
+
c
c
+ = + +
+
+
+
i i i i i i
i i i i
i i i i i i
i i i i
y x f
y
f
h w
x
f
h w y x f h w w y y
y
f
K
x
f
h h w y x f h w w y y
y
f
K
x
f
h y x f h w y x f h w y y
ng Substituti
y
f
K
x
f
h y x f K y h x f
| o
| o
| o
| o | o
Derivation of 2
nd
Order
Runge-Kutta Methods 5 of 5
CISE301_Topic8L4&5 14
2
1
, 1 : solution possible One
solutions infinite unknowns 4 with equations 3
2
1
and ,
2
1
, 1
: equations three following the obtain we terms, Matching
) (
2
) , ( ) , (
... ) , ( ) , ( ) (
: for expansions two derived We
2 1
2 2 2 1
3
2
1
2
2
2
2 2 1 1
1
= = = =

= = = +
+
|
|
.
|

\
|
c
c
+
c
c
+ + =
+
c
c
+
c
c
+ + + =
+
+
+
w w
w w w w
h O
h
y x f
y
f
x
f
h y x f y y
y x f
y
f
h w
x
f
h w y x f h w w y y
y
i i i i i i
i i i i i i
i
| o
| o
| o
2
nd
Order Runge-Kutta Methods
CISE301_Topic8L4&5 15
2
1
and ,
2
1
, 1
: that such , , , Choose
) , (
) , (
2 2 2 1
2 1
2 2 1 1 1
1 2
1
= = = +
+ + =
+ + =
=
+
| o
| o
| o
w w w w
w w
K w K w y y
K y h x f h K
y x f h K
i i
i i
i i
CISE301_Topic8L4&5 16
Alternative Form
( )
2 2 1 1 1
1 2
1

) , (
) , (
Form e Alternativ
k w k w h y y
k h y h x f k
y x f k
i i
i i
i i
+ + =
+ + =
=
+
| o
2 2 1 1 1
1 2
1
) , (
) , (
Kutta e Order Rung Second
K w K w y y
K y h x f h K
y x f h K
i i
i i
i i
+ + =
+ + =
=
+
| o
CISE301_Topic8L4&5 17
Choosing , , w
1
and w
2
( ) ( )
Corrector Single a with ' is This
) , ( ) , (
2 2
1
) , (
) , (
: becomes method Kutta - e Order Rung Second
2
1
, 1 then , 1 choosing example, For
0
1 1 2 1 1
1 2
1
2 1
s Method Heun
y x f y x f
h
y K K y y
K y h x f h K
y x f h K
w w
i i i i i i i
i i
i i
+ + +
+ + = + + =
+ + =
=
= = = = | o
CISE301_Topic8L4&5 18
Choosing , , w
1
and w
2

Method Midpoint the is This
)
2
,
2
(
)
2
,
2
(
) , (
: becomes method Kutta - e Order Rung Second
1 , 0 ,
2
1
then
2
1
Choosing
1
2 1
1
2
1
2 1

K
y
h
x f h y K y y
K
y
h
x f h K
y x f h K
w w
i i i i i
i i
i i
+ + + = + =
+ + =
=
= = = =
+
| o
CISE301_Topic8L4&5 19
2
nd
Order Runge-Kutta Methods
Alternative Formulas
2 1 1
1 i 2
1
2
1
2
1
1
) , (
) , (
) 0 (select mulas Kutta For e Order Rung Second
K K y y
K y h x f h K
y x f h K
i i
i
i i
o o
o o
o
+
|
.
|

\
|
+ =
+ + =
=
=
+
o o
o | o
| o
2
1
1 ,
2
1
, : number nonzero any Pick
1 ,
2
1
,
2
1
1 2
2 1 2 2
= = =
= + = =
w w
w w w w
CISE301_Topic8L4&5 20
Second order Runge-Kutta Method
Example
( )
8269 . 3 2 / ) 1662 . 0 18 . 0 ( 4
2 / ) 1 ( ) 01 . 0 1 (
1662 . 0 ) ) 01 . ( ) 18 . 0 ( 1 ( 01 . 0
) , (
18 . 0 ) 1 ( 01 . 0 ) 4 , 1 (
: 1 STEP
1 , 01 . 0 , 4 ) 1 ( , 1 ) (
RK2 using (1.02) find to system following the Solve
2 1
3
0
2
0
1 0 0 2
3
0
2
0 0 0 1
3 2
= + + =
+ + = +
= + + + + =
+ + =
= + + = = = =
= = = + + =
K K x x
t x
K x h t f h K
t x x t f h K
h x t x t x
x
o

CISE301_Topic8L4&5 21
Second order Runge-Kutta Method
Example
( )
6662 . 3 ) 1546 . 0 1668 . 0 (
2
1
8269 . 3
2
1
) 01 . 1 ( ) 01 . 0 01 . 1 (
1546 . 0 ) ) 01 . ( ) 1668 . 0 ( 1 ( 01 . 0
) , (
1668 . 0 ) 1 ( 01 . 0 ) 8269 . 3 , 01 . 1 (
2 STEP
2 1
3
1
2
1
1 1 1 2
3
1
2
1 1 1 1
= + + =
+ + = +
= + + + + =
+ + =
= + + = = = =
K K x x
t x
K x h t f h K
t x x t f h K
CISE301_Topic8L4&5 22
1 RK2, Using
[1,2] for t Solution
, 4 ) 1 ( , ) ( 1 ) (
3 2
=
e
= + + =
o
x t t x t x

CISE301_Topic8L4&5 23

Lecture 32
Lesson 5: Applications of Runge-Kutta
Methods to Solve First Order ODEs
Using Runge-Kutta methods of different
orders to solve first order ODEs
CISE301_Topic8L4&5 24
2
nd
Order Runge-Kutta


















RK2
( )
) ( is error global and ) ( is error Local
2
) , (
) , (
corrector single a with method s Heun' to Equivalent
RK2 as Know 1, of value Typical
2 3
2 1 1
1 2
1
h O h O
k k
h
y y
h k y h x f k
y x f k
i i
i i
i i
+ + =
+ + =
=
=
+
o
CISE301_Topic8L4&5 25
Higher-Order Runge-Kutta
Higher order Runge-Kutta methods are available.

Derived similar to second-order Runge-Kutta.

Higher order methods are more accurate but
require more calculations.



CISE301_Topic8L4&5 26
3
rd
Order Runge-Kutta


















RK3
( )
) ( is error Global and ) ( is error Local
4
6
) 2 , (
)
2
1
,
2
(
) , (
RK3 as Know
3 4
3 2 1 1
2 1 3
1 2
1
h O h O
k k k
h
y y
h k h k y h x f k
h k y
h
x f k
y x f k
i i
i i
i i
i i
+ + + =
+ + =
+ + =
=
+
CISE301_Topic8L4&5 27
4
th
Order Runge-Kutta


















RK4
( )
) ( is error global and ) ( is error Local
2 2
6
) , (
)
2
1
,
2
(
)
2
1
,
2
(
) , (
4 5
4 3 2 1 1
3 i 4
2 i 3
1 2
1
h O h O
k k k k
h
y y
h k y h x f k
h k y
h
x f k
h k y
h
x f k
y x f k
i i
i
i
i i
i i
+ + + + =
+ + =
+ + =
+ + =
=
+
CISE301_Topic8L4&5 28
Higher-Order Runge-Kutta


















( )
6 5 4 3 1 1
5 4 3 2 1 6
4 1 5
3 2 4
2 1 3
1 2
1
7 32 12 32 7
90
)
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
(
) , (
k k k k k
h
y y
h k h k h k h k h k y h x f k
h k h k y h x f k
h k h k y h x f k
h k h k y h x f k
h k y h x f k
y x f k
i i
i i
i i
i i
i i
i i
i i
+ + + + + =
+ + + + =
+ + + =
+ + =
+ + + =
+ + =
=
+
CISE301_Topic8L4&5 29


















Example
4
th
-Order Runge-Kutta Method
) 4 . 0 ( ) 2 . 0 ( 4
2 . 0
5 . 0 ) 0 (
1
2
y and y compute to RK Use
h
y
x y
dx
dy
=
=
+ + =
RK4
CISE301_Topic8L4&5 30


















Example: RK4
) 4 . 0 ( ), 2 . 0 ( 4
5 . 0 ) 0 ( , 1
: Problem
2
y y find to RK Use
y x y
dx
dy
= + + =
CISE301_Topic8L4&5 31
4
th
Order Runge-Kutta


















RK4
( )
) ( is error global and ) ( is error Local
2 2
6
) , (
)
2
1
,
2
(
)
2
1
,
2
(
) , (
4 5
4 3 2 1 1
3 i 4
2 i 3
1 2
1
h O h O
k k k k
h
y y
h k y h x f k
h k y
h
x f k
h k y
h
x f k
y x f k
i i
i
i
i i
i i
+ + + + =
+ + =
+ + =
+ + =
=
+
CISE301_Topic8L4&5 32


















Example: RK4
5 . 0 , 0
1 ) , (
0.2
0 0
2
= =
+ + =
=
y x
x y y x f
h
( ) ( )
( ) ( )
( ) ( )
( ) 8293 . 0 2 2
6
7908 . 1 2 . 0 16545 . 0 1 ) , (
654 . 1 1 . 0 164 . 0 1 )
2
1
,
2
1
(
64 . 1 1 . 0 15 . 0 1 )
2
1
,
2
1
(
5 . 1 ) 1 ( ) , (
4 3 2 1 0 1
2
0 0 3 0 0 4
2
0 0 2 0 0 3
2
0 0 1 0 0 2
2
0 0 0 0 1
= + + + + =
= + + + + = + + =
= + + + + = + + =
= + + + + = + + =
= + + = =
k k k k
h
y y
x y h k y h x f k
x y h k y h x f k
x y h k y h x f k
x y y x f k
) 4 . 0 ( ), 2 . 0 ( 4
5 . 0 ) 0 ( , 1
: Problem
2
y y find to RK Use
y x y
dx
dy
= + + =
See RK4 Formula
S
t
e
p

1

CISE301_Topic8L4&5 33


















Example: RK4
8293 . 0 , 2 . 0
1 ) , (
0.2
1 1
2
= =
+ + =
=
y x
x y y x f
h
( ) 2141 . 1 2 2
6
2 . 0
0555 . 2 ) , (
9311 . 1 )
2
1
,
2
1
(
9182 . 1 )
2
1
,
2
1
(
1.7893 ) , (
4 3 2 1 1 2
3 1 1 4
2 1 1 3
1 1 1 2
1 1 1
= + + + + =
= + + =
= + + =
= + + =
= =
k k k k y y
h k y h x f k
h k y h x f k
h k y h x f k
y x f k
) 4 . 0 ( ), 2 . 0 ( 4
5 . 0 ) 0 ( , 1
: Problem
2
y y find to RK Use
y x y
dx
dy
= + + =
S
t
e
p

2

CISE301_Topic8L4&5 34


















Example: RK4
) 4 . 0 ( ), 2 . 0 ( 4
5 . 0 ) 0 ( , 1
: Problem
2
y y find to RK Use
y x y
dx
dy
= + + =
x
i
y
i
0.0 0.5
0.2 0.8293
0.4 1.2141
Summary of the solution
CISE301_Topic8L4&5 35
Summary
Runge Kutta methods generate an
accurate solution without the need to
calculate high order derivatives.
Second order RK have local truncation
error of order O(h
3
) and global truncation
error of order O(h
2
).
Higher order RK have better local and
global truncation errors.
N function evaluations are needed in the
N
th
order RK method.
CISE301_Topic8L4&5 36
Remaining Lessons in Topic 8
Lesson 6:
Solving Systems of high order ODE

Lesson 7:
Multi-step methods

Lessons 8-9:
Methods to solve Boundary Value Problems

Das könnte Ihnen auch gefallen