You are on page 1of 26

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_Topic8L3 1
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_Topic8L3 2
Lecture 30
Lesson 3: Midpoint and
Heuns Predictor
Corrector Methods

CISE301_Topic8L3 3
Learning Objectives of
Lesson 3
To be able to solve first order
differential equations using the
Midpoint Method.
To be able to solve first order
differential equations using the
Heuns Predictor Corrector Method.

CISE301_Topic8L3 4
Topic 8: Lesson 3
Lesson 3: Midpoint and Heuns
Predictor-Corrector Methods

Review Euler Method


Heuns Method
Midpoint Method

CISE301_Topic8L3 5
Euler Method
Problem Euler Method
y ( x) f ( x, y ) y0 y ( x0 )
y ( x0 ) y0 yi 1 yi h f ( xi , yi )
for i 1,2,...

2
Local Truncation Error O(h )
Global Truncation Error O(h)
CISE301_Topic8L3 6
Introduction
Problem to be solved is a first order ODE :
y ( x) f ( x, y ), y ( x0 ) y0
The methods proposed in this lesson
have the general form:
yi 1 yi h
For the case of Euler: f ( xi , yi )
Different forms of will be used for
the Midpoint and Heuns Methods.
CISE301_Topic8L3 7
Midpoint Method
Problem Midpoint Method
y ( x) f ( x, y ) y0 y ( x0 )
h
y ( x0 ) y0 y 1 yi f ( xi , yi )
i
2 2
yi 1 yi h f ( x 1 ,y 1 )
i i
2 2

Local Truncation Error O(h 3 )


Global Truncation Error O(h 2 )
CISE301_Topic8L3 8
Motivation
The midpoint can be summarized as:
Euler method is used to estimate the solution
at the midpoint.
The value of the rate function f(x,y) at the mid
point is calculated.
This value is used to estimate yi+1.
Local Truncation error of order O(h3).
Comparable to Second order Taylor series
method.

CISE301_Topic8L3 9
Midpoint Method

( xi , yi )

x0 x 1 xi 1
i
2
h
y 1 yi f ( xi , yi ) , yi 1 yi h f ( x 1 ,y 1 )
i
2 2 i
2
i
2
CISE301_Topic8L3 10
Midpoint Method

slope f ( xi , yi )

( xi , yi )

x0 x 1 xi 1
i
2
h
y 1 yi f ( xi , yi ) , yi 1 yi h f ( x 1 ,y 1 )
i
2 2 i
2
i
2
CISE301_Topic8L3 11
Midpoint Method

(x ,y )
slope f ( xi , yi )
1 1
i i
2 2

( xi , yi )

x0 x 1 xi 1
i
2
h
y 1 yi f ( xi , yi ) , yi 1 yi h f ( x 1 ,y 1 )
i
2 2 i
2
i
2
CISE301_Topic8L3 12
Midpoint Method
slope f ( x 1 ,y 1 )
i i
(x 1 ,y 1 ) 2 2

i i
2 2

( xi , yi )

x0 x 1 xi 1
i
2
h
y 1 yi f ( xi , yi ) , yi 1 yi h f ( x 1 ,y 1 )
i
2 2 i
2
i
2
CISE301_Topic8L3 13
Midpoint Method
slope f ( x 1 ,y 1 )
i i
(x 1 ,y 1 ) 2 2
i i
2 2

( xi , yi )

x0 x 1 xi 1
i
2
h
y 1 yi f ( xi , yi ) , yi 1 yi h f ( x 1 ,y 1 )
i
2 2 i
2
i
2
CISE301_Topic8L3 14
Example 1

Use the Midpoint Method to solve the ODE


y ( x) 1 x 2 y
y (0) 1
Use h 0.1. Determine y(0.1) and y(0.2)

CISE301_Topic8L3 15
Example 1
Problem : f ( x, y ) 1 x 2 y , y0 y (0) 1, h 0.1
Step 1 :
h
y 1 y0 f ( x0 , y0 ) 1 0.05(1 0 1) 1.1
0
2
2
y1 y0 h f ( x 1, y 1) 1 0.1(1 0.0025 1.1) 1.2103
0 0
2 2
Step 2 :
h
y 1 y1 f ( x1 , y1 ) 1.2103 .05(1 0.01 1.2103) 1.3213
1
2
2
y2 y1 h f ( x 1, y 1) 1.2103 0.1( 2.3438) 1.4446
1 1
2 2
CISE301_Topic8L3 16
Heuns Predictor
Corrector

CISE301_Topic8L3 17
Heuns Predictor Corrector
Method
Problem Heun ' s Method
y ( x ) f ( x, y ) y0 y ( x0 )
y ( x0 ) y0 Predictor : yi01 yi h f ( xi , yi )

Corrector : yi11 yi
h
2

f ( xi , yi ) f ( xi 1, yi01 )

Local Truncation Error O(h 3 )


Global Truncation Error O(h 2 )

CISE301_Topic8L3 18
Heuns Predictor Corrector
(Prediction)

( xi 1 , yi01 )

( xi , yi )

xi xi 1
0
Prediction yi 1 yi h f ( xi , yi )
CISE301_Topic8L3 19
Heuns Predictor Corrector
(Prediction)

( xi 1 , yi01 )
slope f ( xi 1 , yi01 )

( xi , yi )

xi xi 1

Prediction y 0
i 1 yi h f ( xi , yi )
CISE301_Topic8L3 20
Heuns Predictor Corrector
(Correction)
f ( xi , yi ) f ( xi 1 , yi01 )
slope
2
( xi 1 , yi01 )

( xi , yi ) ( xi 1 , yi11 )

xi xi 1

y 1
i 1 yi
h
2

f ( xi , yi ) f ( xi 1 , yi01 )
CISE301_Topic8L3 21
Example 2
Use the Heun' s Method to solve the ODE
y ( x) 1 x y
2

y (0) 1
Use h 0.1. One correction only
Determine y(0.1) and y(0.2)

CISE301_Topic8L3 22
Example 2
Problem : f ( x, y ) 1 y x 2 , y0 y ( x0 ) 1, h 0.1

Step 1 :
Predictor : y10 y0 h f ( x0 , y0 ) 1 0.1(2) 1.2

Corrector : y y0
1
1
h
2

f ( x0 , y0 ) f ( x1 , y10 ) 1.2105

Step 2 :
Predictor : y20 y1 h f ( x1 , y1 ) 1.4326

Corrector : y y1
1
2
h
2

f ( x1 , y1 ) f ( x2 , y20 ) 1.4452

CISE301_Topic8L3 23
Summary
Euler, Midpoint and Heuns methods are
similar in the following sense:
yi 1 yi h slope
Different methods use different estimates of
the slope.
Both Midpoint and Heuns methods are
comparable in accuracy to the second
order Taylor series method.

CISE301_Topic8L3 24
Comparison
Method Local
truncation
Global
truncation
error error

Euler Method yi 1 yi h f ( xi , yi ) O(h 2 ) O ( h)


Heun' s Method
Predictor : yi01 yi h f ( xi , yi ) O(h 3 ) O(h 2 )
k 1
Corrector : y yi
i 1
h
2

f ( xi , yi ) f ( xi 1 , yik1 )
h
Midpoint y 1 yi f ( xi , yi ) O(h3 ) O(h 2 )
i
2 2
yi 1 yi h f ( x 1 ,y 1 )
i i
2 2

CISE301_Topic8L3 25
More in this Topic

Lessons 4-5: Runge-Kutta Methods


Lesson 6: Systems of High order ODE
Lesson 7: Multi-step methods
Lessons 8-9: Boundary Value Problems

CISE301_Topic8L3 26