0% found this document useful (0 votes)
7 views36 pages

CISE301 Topic8L4&5

The document outlines a series of lectures on Ordinary Differential Equations (ODEs) at KFUPM, focusing on various methods including Taylor series, Runge-Kutta methods, and boundary value problems. It specifically details the second-order Runge-Kutta method, its derivation, and applications, including examples of solving ODEs. The learning objectives emphasize understanding the motivation behind these methods and their practical implementation.

Uploaded by

Huyền Huyền
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views36 pages

CISE301 Topic8L4&5

The document outlines a series of lectures on Ordinary Differential Equations (ODEs) at KFUPM, focusing on various methods including Taylor series, Runge-Kutta methods, and boundary value problems. It specifically details the second-order Runge-Kutta method, its derivation, and applications, including examples of solving ODEs. The learning objectives emphasize understanding the motivation behind these methods and their practical implementation.

Uploaded by

Huyền Huyền
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 36

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 1
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 2
Lecture 31
Lesson 4: Runge-Kutta
Methods

CISE301_Topic8L4&5 3
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 4
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 5
Second Order Runge-Kutta
Method
K1 h f ( xi , yi )
K 2 h f ( xi   h, yi   K1 )
yi 1  yi  w1K1  w2 K 2
Problem :
Find  ,  , w1 , w2
such that yi 1 is as accurate as possible.

CISE301_Topic8L4&5 6
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 7
Taylor Series in One
Variable
The n th order Taylor Series expansion of f(x)
n

f ( x  h) 
i 0
hi (i )
i!
f ( x) 
h n 1
( n  1)!
f ( n 1) ( x )

Approximation Error

where x is between x and x  h


CISE301_Topic8L4&5 8
Runge-Kutta Methods – 1
of 5
Second Order Taylor Series Expansion
dy
Used to solve ODE :  f ( x, y )
dx
dy h 2 d 2 y 3
yi 1  yi  h  2
 O (h )
dx 2 dx
which is written as :
h2 3
yi 1  yi  h f ( xi , yi )  f ' ( xi , yi )  O ( h )
2
CISE301_Topic8L4&5 9
Runge-Kutta Methods – 2
of 5

where f ' ( x, y ) is obtained by chain - rule differenti ation


f ( x, y ) f ( x, y ) dy f f
f ' ( x, y )     f ( x, y )
x y dx x y
Substituting :
 f f  h2 3
yi 1  yi  f ( xi , yi )h    f ( xi , yi )   O ( h )
 x y  2

CISE301_Topic8L4&5 10
Taylor Series in Two
Variables
 f f 
f ( x  h, y  k )  f ( x, y )   h  k  
 x y 
1  2 2 f 2  2
f  2
f 
h k  2hk   ...

2!  x 2
y 2
x y 
n


i n 1
1   1   
  h  k  f ( x , y )   h  k  f ( x, y)
i!  x y  ( n  1)!  x y 
i 0
approximation error

( x , y ) is on the line joining between ( x, y ) and ( x  h, y  k )


CISE301_Topic8L4&5 11
Runge-Kutta Methods – 3
of 5
Problem : Find  ,  , w1 , w2 such that
K1 h f ( xi , yi )
K 2 h f ( xi   h, yi   K1 )
yi 1  yi  w1K1  w2 K 2

Substituting :
yi 1  yi  w1h f ( xi , yi )  w2h f ( xi   h, yi   K1 )

CISE301_Topic8L4&5 12
Runge-Kutta Methods – 4
of 5
f f
f ( xi  h, yi  K1 )  f ( xi , yi )  h  K1  ...
x y
Substituting :
 f f 
yi 1  yi  w1h f ( xi , yi )  w2h  f ( xi , yi )  h  K1  ...
 x y 
 f f 
yi 1  yi  ( w1  w2 )h f ( xi , yi )  w2h  h  K1  ...
 x y 
2 f 2 f
yi 1  yi  ( w1  w2 )h f ( xi , yi )  w2h  w2 h f ( xi , yi )  ...
x y

CISE301_Topic8L4&5 13
Runge-Kutta Methods – 5
of 5
We derived two expansions for yi 1 :
2f 2 f
yi 1  yi  ( w1  w2 )h f ( xi , yi )  w2h  w2 h f ( xi , yi )  ...
x y
 f f  h2
yi 1  yi  f ( xi , yi )h    f ( xi , yi )   O ( h 3 )
 x y  2
Matching terms, we obtain the following three equations :
1 1
w1  w2 1 , w2  , and w2  
2 2
3 equations with 4 unknowns  infinite solutions
1
One possible solution :   1, w1 w2 
2
CISE301_Topic8L4&5 14
2nd Order Runge-Kutta
Methods
K1 h f ( xi , yi )
K 2 h f ( xi   h, yi   K1 )
yi 1  yi  w1K1  w2 K 2

Choose  ,  , w1 , w2 such that :


1 1
w1  w2 1, w2  , and w2  
2 2
CISE301_Topic8L4&5 15
Alternative Form
Second Order Runge Kutta
K1 h f ( xi , yi )
K 2 h f ( xi   h, y i   K1 )
yi 1  yi  w1K1  w2 K 2

Alternative Form
k1  f ( xi , yi )
k2  f ( xi   h, yi   h k1 )
CISE301_Topic8L4&5
yi 1  yi  h w1 k1  w2 k2  16
Choosing , , w1 and w2
1
For example, choosing  1, then  1, w1 w2 
2
Second Order Runge - Kutta method becomes :
K1 h f ( xi , yi )
K 2 h f ( xi  h, yi  K1 )
1 h

yi 1  yi  K1  K 2   yi  f ( xi , yi )  f ( xi 1 , yi 1 )
2 2
0

This is Heun ' s Method with a Single Corrector

CISE301_Topic8L4&5 17
Choosing , , w1 and w2
1 1
Choosing   then   , w1 0, w2 1
2 2
Second Order Runge - Kutta method becomes :
K1 h f ( xi , yi )
h K1
K 2 h f ( xi  , yi  )
2 2
h K1
yi 1  yi  K 2  yi  h f ( xi  , yi  )
2 2
This is the Midpoint Method
CISE301_Topic8L4&5 18
2 Order Runge-Kutta
Methods
Alternative Formulas
1 1
 w2  ,  w2  , w1  w2 1
2 2
1 1
Pick any nonzero  number :   , w2  , w1 1 
2 2

Second Order Runge Kutta Formulas (select 0)


K1  h f ( xi , yi )
K 2 h f ( xi   h, yi   K1 )
 1  1
yi 1  yi   1   K1  K2
 2  2
CISE301_Topic8L4&5 19
Second order Runge-Kutta
Method
Example
Solve the following system to find x (1.02) using RK2
x (t ) 1  x 2  t 3 , x (1)  4, h 0.01,  1

STEP 1 :
K1 h f (t0 1, x0  4) 0.01(1  x02  t03 ) 0.18
K 2 h f (t0  h, x0  K1 )
0.01(1  ( x0  0.18)2  (t0  .01)3 ) 0.1662
x (1  0.01)  x (1)  K1  K 2 / 2
 4  (0.18  0.1662) / 2  3.8269
CISE301_Topic8L4&5 20
Second order Runge-Kutta
Method
Example
STEP 2

K1 h f (t1 1.01, x1  3.8269) 0.01(1  x12  t13 ) 0.1668


K 2 h f (t1  h, x1  K1 )
0.01(1  ( x1  0.1668)2  (t1  .01)3 ) 0.1546
1
x (1.01  0.01)  x (1.01)  K1  K 2 
2
1
 3.8269  (0.1668  0.1546)  3.6662
2

CISE301_Topic8L4&5 21
2 3
x (t ) 1  x (t )  t , x (1)  4,
Solution for t  [1,2]
Using RK2,  1

CISE301_Topic8L4&5 22
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 23
2nd Order Runge-Kutta RK2

Typical value of  1, Know as RK2


Equivalent to Heun' s method with a single corrector
k1  f ( xi , yi )
k2  f ( xi  h, yi  k1 h )
h
yi 1  yi  k1  k2 
2
Local error is O ( h 3 ) and global error is O ( h 2 )

CISE301_Topic8L4&5 24
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 25
3rd Order Runge-Kutta RK3

Know as RK3
k1  f ( xi , yi )
h 1
k2  f ( xi  , yi  k1h )
2 2
k3  f ( xi  h, yi  k1h  2k2h )
h
yi 1  yi  k1  4k2  k3 
6
4 3
Local error is O ( h ) and Global error is O ( h )
CISE301_Topic8L4&5 26
4th Order Runge-Kutta RK4

k1  f ( xi , yi )
h 1
k2  f ( xi  , yi  k1h )
2 2
h 1
k3  f ( xi  , yi  k2h )
2 2
k4  f ( xi  h, yi  k3h )
h
yi 1  yi  k1  2k2  2k3  k4 
6
5 4
Local error is O ( h ) and global error is O ( h )
CISE301_Topic8L4&5 27
Higher-Order Runge-
Kutta
k1  f ( xi , yi )
1 1
k2  f ( xi  h, yi  k1h )
4 4
1 1 1
k3  f ( xi  h, yi  k1h  k2h )
4 8 8
1 1
k4  f ( xi  h, yi  k2h  k3h )
2 2
3 3 9
k5  f ( xi  h, yi  k1h  k4h )
4 16 16
3 2 12 12 8
k6  f ( xi  h, yi  k1h  k2h  k3h  k 4 h  k 5h )
7 7 7 7 7
h
yi 1  yi  7k1  32k3  12k4  32k5  7k6 
90
CISE301_Topic8L4&5 28
Example
4th-Order Runge-Kutta Method RK4

dy 2
1  y  x
dx
y (0) 0.5
h 0.2
Use RK 4 to compute y (0.2) and y (0.4)

CISE301_Topic8L4&5 29
Example: RK4
Problem :
dy
1  y  x 2 , y (0) 0.5
dx
Use RK 4 to find y (0.2), y (0.4)

CISE301_Topic8L4&5 30
4th Order Runge-Kutta RK4

k1  f ( xi , yi )
h 1
k2  f ( xi  , yi  k1h )
2 2
h 1
k3  f ( xi  , yi  k2h )
2 2
k4  f ( xi  h, yi  k3h )
h
yi 1  yi  k1  2k2  2k3  k4 
6
5 4
Local error is O ( h ) and global error is O ( h )
CISE301_Topic8L4&5 31
Example: RK4 See RK4 Formula
Problem : h 0.2
dy
1  y  x 2 , y (0) 0.5 f ( x, y ) 1  y  x 2
dx
x0 0, y0 0.5
Use RK 4 to find y (0.2), y (0.4)
k1  f ( x0 , y0 ) (1  y0  x02 ) 1.5
1 1
k2  f ( x0  h, y0  k1h ) 1  y0  0.15 x0  0.12 1.64
2 2
1 1
k3  f ( x0  h, y0  k2h ) 1  y0  0.164 x0  0.12 1.654
2 2
k4  f ( x0  h, y0  k3h ) 1  y0  0.16545 x0  0.2 2 1.7908
h
y1  y0  k1  2k2  2k3  k4  0.8293
6
CISE301_Topic8L4&5 32
Example: RK4
Problem :
h 0.2
dy
1  y  x 2 , y (0) 0.5 f ( x, y ) 1  y  x 2
dx
x1 0.2, y1 0.8293
Use RK 4 to find y (0.2), y (0.4)
k1  f ( x1 , y1 ) 1.7893
1 1
k2  f ( x1  h, y1  k1h ) 1.9182
2 2
1 1
k3  f ( x1  h, y1  k2h ) 1.9311
2 2
k4  f ( x1  h, y1  k3h ) 2.0555
0. 2
y2  y1  k1  2k2  2k3  k4  1.2141
6
CISE301_Topic8L4&5 33
Example: RK4
Problem :
dy
1  y  x 2 , y (0) 0.5
dx
Use RK 4 to find y (0.2), y (0.4)

Summary of the solution


xi yi
0.0 0.5
0.2 0.8293
0.4 1.2141
CISE301_Topic8L4&5 34
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(h3) and global truncation
error of order O(h2).
 Higher order RK have better local and
global truncation errors.
 N function evaluations are needed in the
Nth order RK method.
CISE301_Topic8L4&5 35
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

CISE301_Topic8L4&5 36

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy