cise301 : numerical methods topic 8 ordinary differential equations (odes) lecture 28-36

50
CISE301_Topic8L4&5 KFUPM 1 Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36 KFUPM Read 25.1-25.4, 26-2, 27-1

Upload: morey

Post on 22-Feb-2016

71 views

Category:

Documents


0 download

DESCRIPTION

CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36. KFUPM Read 25.1-25.4, 26-2, 27-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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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

Page 2: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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

Page 3: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 3

Lecture 31Lesson 4: Runge-Kutta

Methods

Page 4: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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.

Page 5: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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.

Page 6: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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 xK h f t h x Kx t h x t w K w K

Find w wx(t h)

Page 7: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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.

Page 8: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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 xi n

where x is between x and x h

Approximation Error

Page 9: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 9

Taylor Series in One Variable- Another Look -

hxxx

xfdxdh

nxf

dxdh

ihxf

f(x)

hxfdxxfdhxf

dxdh

nn

i

i

iii

ii

i

and between is

)(!

1)(!1)(

ofexpansion SeriesTaylor The

)()()(

Define

1

0

)(

Page 10: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 10

Definitions

2

22

2

2

22

2

1

0

),(),(2),(),(

),(),(),(

),(),(

),(

yyxfk

yxyxfkh

xyxfhyxf

yk

xh

yyxfk

xyxfhyxf

yk

xh

yxfyxfy

kx

h

xfhyxf

xh

Define

i

ii

i

Page 11: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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

Page 12: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 12

Taylor Series in Two Variables

),( and ),(between joining line on the is),(

),(!

1),(!

1),(

, ofexpansion SeriesTaylor The1

0

kyhxyxyxerrorionapproximat

yxfy

kx

hn

yxfy

kx

hi

kyhxf

y)f(xnn

i

i

x x+h

y

y+k

Page 13: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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 xK h f t h x Kx t h x t w K w K

Find w wx(t h)

Page 14: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 14

Runge-Kutta Method

)( ),()()(

),(21 ),(

)),(,( ),()()(

...)('''6

)(''2

)(')()(

possible. as many terms asmatch to,,, :Problem

3'22

'2221

2''

21

32

21

hOffhwfhwxtfhwwtxhtx

xtfx

ht

hffhfhffhxhtf

xtfhxhtfhwxtfhwtxhtx

txhtxhthxtxhtx

wwFind

xt

xt

Page 15: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 15

Runge-Kutta Method

)( ),()()(

...)('''6

)(''2

)(')()(

3'22

'2221

32

hOffhwfhwxtfhwwtxhtx

txhtxhthxtxhtx

xt

1,1,5.0,5.0solution possibleOne

5.0,5.0,1

21

2221

ww

wwww

Page 16: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 16

Runge-Kutta Method

1

2 1

1 2

( , )( , )

1( ) ( )2

RK2K h f t xK h f t h x K

x t h x t K K

Page 17: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 17

Runge-Kutta MethodAlternative Formula

1

2 1

1 2

( , )( , )

( ) ( )2

RK2F f t xF f t h x hF

hx t h x t F F

Page 18: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 18

Runge-Kutta MethodAlternative Formula

1

2 1

1 2

( , )(

Alternative F

, )

( ) ( )2

ormF f t xF f t h x hF

hx t h x t F F

1

2 1

1 2

( , )( , )

1( ) ( )2

RK2K h f t xK h f t h x K

x t h x t K K

Page 19: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 19

Runge-Kutta MethodAlternative Formulas

1

2 1

1 2

RK2 Formulas (select 0) ( , )( , )

1 1( ) ( ) 12 2

K h f t xK h f t h x K

x t h x t F F

21,

211,

number zero-nonany Picksolutionanother

5.0,5.0,1

21

2221

ww

wwww

Page 20: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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 26

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

Page 21: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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

Page 22: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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.16621 1(1 0.01) (1) 4 (0.182 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

Page 23: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 23

Second order Runge-Kutta Method Example

6662.3)1546.01668.0(218269.3

21)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

Page 24: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 24

RK2 Using [1,2]for tSolution

,4)1(,)(1)( 32

xttxtx

Page 25: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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.

Page 26: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 26

Lecture 32Lesson 5: Applications of Runge-Kutta Methods to Solve First Order ODEs

Page 27: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 27

Learning Objectives of Lesson 5 Use Runge-Kutta methods of different

orders to solve first order ODEs.

Page 28: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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 yK f x h y K hy y w K w K

Find w wy

Page 29: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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 yK f x h y K h

hy y K K

Page 30: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 30

Runge-Kutta Methods

1

2 1

3 1 2

1 2 3

(Third

, )1 1( , )2 2

( , 2 )1( ) ( ) 46

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

Page 31: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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 hhy y K K K K

RK4

Page 32: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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.

Page 33: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 33

Fifth Order Runge-Kutta Methods

654311

543216

415

324

213

12

1

7321232790

)78

712

712

72

73,(

)169

163,

43(

)21,

21(

)81

81,

41(

)41,

41(

),(

KKKKKhyy

hKhKhKhKhKyhxfK

hKhKyhxfK

hKhKyhxfK

hKhKyhxfK

hKyhxfK

yxfK

ii

ii

ii

ii

ii

ii

ii

Page 34: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 34

Second Order Runge-Kutta Method

needed steps of# Determine

)(

),(

:Given

00

hyxy

yxfdxdy

Page 35: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 35

Second Order Runge-Kutta Method

211

12

1

00

2

),(),(

2needed steps of# Determine

)(

),(

:Given

KKhyy

hKyhxfKyxfK

formulaRK

hyxy

yxfdxdy

ii

ii

ii

Page 36: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 36

Second Order Runge-Kutta Method

2112

1112

111

01

2101

1002

001

2

),(),(

:2 Step

2

),(),(

:1 Step

KKhyy

hKyhxfKyxfK

hxx

KKhyy

hKyhxfKyxfK

211

12

1

00

2

),(),(

2needed steps of# Determine

)(

),(

:Given

KKhyy

hKyhxfKyxfK

formulaRK

hyxy

yxfdxdy

ii

ii

ii

Page 37: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 37

Example 1Second Order Runge-Kutta Method

)02.1(),01.1(findto

4)1(,1

equation aldifferenti thesolve tomethod Kutta Rungeorder second theUse

32

yy

yxydxdy

Page 38: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 38

Example 1Second Order Runge-Kutta Method

)02.1(),01.1(2

4)1(,1

:Problem

32

yyfindtoRKUse

yxydxdy

4,1

1),(

0.01h

00

32

yxxyyxf

Page 39: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 39

Example 1Second Order Runge-Kutta Method

8269.3)62.1618(201.04

2

62.16))01.()18.0(1(),(

0.18)1(),(

:1 Step

2101

30

201002

30

20001

KKhyy

xyhKyhxfK

xyyxfK

)02.1(),01.1(2

4)1(,1

:Problem

32

yyfindtoRKUse

yxydxdy

4,1

1),(

0.01h

00

32

yxxyyxf

Page 40: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 40

Example 1Second Order Runge-Kutta Method

)02.1(),01.1(2

4)1(,1

:Problem

32

yyfindtoRKUse

yxydxdy

8269.3,01.11),(

0.01h

11

32

yxxyyxf

Page 41: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 41

Example 1Second Order Runge-Kutta Method

6662.3)46.1568.16(201.08269.3

2

46.15))01.()1668.0(1(),(

68.16)1(),(

:2 Step

2112

31

211112

31

21111

KKhyy

xyhKyhxfK

xyyxfK

)02.1(),01.1(2

4)1(,1

:Problem

32

yyfindtoRKUse

yxydxdy

8269.3,01.11),(

0.01h

11

32

yxxyyxf

Page 42: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 42

Example 1Summary of the solution

6662.302128269.301110000.40010

...

yxi ii

)02.1(),01.1(2

4)1(,1

:Problem

32

yyfindtoRKUse

yxydxdy

Summary of the solution

Page 43: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 43

Solution after 100 steps

Page 44: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 44

Example 24th-Order Runge-Kutta Method

)4.0()2.0(42.0

5.0)0(

1 2

yandycomputetoRKUsehy

xydxdy

See RK4 Formula

Page 45: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 45

Example 2Fourth Order Runge-Kutta Method

)4.0(),2.0(4

5.0)0(,1

:Problem

2

yyfindtoRKUse

yxydxdy

Page 46: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 46

Example 2Fourth Order Runge-Kutta Method

5.0,01),(

0.2h

00

2

yxxyyxf

8293.0226

7908.12.016545.01),(

654.11.0164.01)21,

21(

64.11.015.01)21,

21(

5.11),(

:1Step

432101

2003004

2002003

2001002

200001

KKKKhyy

xyhKyhxfK

xyhKyhxfK

xyhKyhxfK

xyyxfK

)4.0(),2.0(4

5.0)0(,1

:Problem

2

yyfindtoRKUse

yxydxdy

See RK4 Formula

Page 47: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 47

Runge-Kutta Methods

43211

34

23

12

1

226

),(

)21,

21(

)21,

21(

),((RK4) Kutta RungeOrder Fourth

KKKKhyy

hKyhxfK

hKyhxfK

hKyhxfK

yxfK

ii

ii

ii

ii

ii

RK4

Page 48: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 48

Example 2 Fourth Order Runge-Kutta Method

8293.0,2.01),(

0.2h

00

2

yxxyyxf

2141.12262.0

0555.2),(

9311.1)21,

21(

9182.1)21,

21(

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

yxydxdy

Page 49: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

CISE301_Topic8L4&5 KFUPM 49

Example 2Summary of the solution

2141.14.028293.02.015.00.00ii yxi

)4.0(),2.0(4

5.0)0(,1

:Problem

2

yyfindtoRKUse

yxydxdy

Summary of the solution

Page 50: CISE301 : Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture 28-36

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