0% found this document useful (0 votes)
77 views10 pages

Chapter 1 Numerical Methods

The document summarizes numerical methods for solving differential equations, including Euler's method and the second order Runge-Kutta method. It provides the formulas, steps, and an example for applying Euler's method. It also defines the second order Runge-Kutta method and notes it uses a trial step at the midpoint to reduce errors.

Uploaded by

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

Chapter 1 Numerical Methods

The document summarizes numerical methods for solving differential equations, including Euler's method and the second order Runge-Kutta method. It provides the formulas, steps, and an example for applying Euler's method. It also defines the second order Runge-Kutta method and notes it uses a trial step at the midpoint to reduce errors.

Uploaded by

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

BMCG 1013 Differential Equations

Chapter 1: Numerical Methods

- Euler’s Method
- 2nd Order Runge-Kutta Method

Prepared by Dr. Loh Ser Lee (FKE)


[email protected]

BMCG 1013 Differential Equations


1.3 Numerical Methods for DE

Solution of Differential Equation

Analytical Methods Numerical Methods

- Separable Runge-
- Exact Euler’s
Kutta
- Homogeneous Method
Method
- Linear
- Bernoulli

Exact solution Approximated solution


[email protected]

1
BMCG 1013 Differential Equations

1.3.1 Euler’s Method


 Most basic explicit method for solving ordinary differential
equation (ODE)
 The simplest Runge-Kutta Method

Formula:
𝑦𝑖+1 = 𝑦𝑖 + ℎ𝑓(𝑥𝑖 , 𝑦𝑖 )

Illustration of the Euler method. The unknown curve


is in blue, and its polygonal approximation is in red
Source: www.wikipedia.com
[email protected]

BMCG 1013 Differential Equations

1.3.1 Euler’s Method


Draw a line structure and pull in the initial conditions
𝑦0 𝑦1 𝑦2 𝑦𝑛−1 𝑦𝑛
𝑥0 𝑥1 𝑥2 𝑥𝑛−1 𝑥𝑛

Rearrange the given ODE in the form of


𝑦 ′ = 𝑓(𝑥, 𝑦)

Discretize the equation into nth terms:


𝑦𝑖′ = 𝑓 𝑥𝑖 , 𝑦𝑖 ; 𝑖 = 0,1,2, … 𝑛

Compute the next term by using formula


𝑦𝑖+1 = 𝑦𝑖 + ℎ𝑓 𝑥𝑖 , 𝑦𝑖 ; 𝑖 = 0,1,2, … 𝑛

[email protected]

2
BMCG 1013 Differential Equations

1.3.1 Euler’s Method

Example:
Use Euler’s method to numerically integrate

𝑑𝑦
+ 𝑦 = 3𝑥 3 − 7𝑥 2 + 5𝑥, 𝑦 0 =1
𝑑𝑥
from 𝑥 = 0 to 𝑥 = 2 with a step size of 0.5.

[email protected]

BMCG 1013 Differential Equations

1.3.1 Euler’s Method


Reminder:
Solution: 𝑦 ′ = 𝑓(𝑥, 𝑦)
𝑑𝑦
= 𝑓 𝑥, 𝑦 = 3𝑥 3 − 7𝑥 2 + 5𝑥 − 𝑦
𝑑𝑥
0 ≤ 𝑥 ≤ 2, ℎ = 0.5, 𝑦 0 = 1
Construct the time line:
1
||
𝑦0 𝑦1 𝑦2 𝑦3 𝑦4

𝑥0 𝑥1 𝑥2 𝑥3 𝑥4
|| || || || ||
0 0.5 1.0 1.5 2.0

Let 𝑖 = 0,
𝑦1 = 𝑦0 + ℎ𝑓 𝑥0 , 𝑦0
= 1 + 0.5𝑓(0, 1)
= 1 + 0.5 3 0 3 − 7 0 2
+5 0 −1
[email protected]
= 0.5

3
BMCG 1013 Differential Equations

1.3.1 Euler’s Method


Solution: (cont.)
𝑑𝑦
= 𝑓 𝑥, 𝑦 = 3𝑥 3 − 7𝑥 2 + 5𝑥 − 𝑦
𝑑𝑥
Update the time line:
1 0.5
|| ||
𝑦0 𝑦1 𝑦2 𝑦3 𝑦4

𝑥0 𝑥1 𝑥2 𝑥3 𝑥4
|| || || || ||
0 0.5 1.0 1.5 2.0
Let 𝑖 = 1,
𝑦2 = 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 )
= 0.5 + 0.5𝑓(0.5, 0.5)
= 0.5 + 0.5 3 0.5 3 − 7 0.5 2
+ 5 0.5 − 0.5
= 0.8125
[email protected]

BMCG 1013 Differential Equations

1.3.1 Euler’s Method


Solution: (cont.)
𝑑𝑦
= 𝑓 𝑥, 𝑦 = 3𝑥 3 − 7𝑥 2 + 5𝑥 − 𝑦
𝑑𝑥
Update the time line:
1 0.5 0.8125
|| || ||
𝑦0 𝑦1 𝑦2 𝑦3 𝑦4

𝑥0 𝑥1 𝑥2 𝑥3 𝑥4
|| || || || ||
0 0.5 1.0 1.5 2.0
Let 𝑖 = 2,
𝑦3 = 𝑦2 + ℎ𝑓(𝑥2 , 𝑦2 )
= 0.8125 + 0.5𝑓(1, 0.8125)
= 0.8125 + 0.5 3 1 3 − 7 1 2
+ 5 1 − 0.8125
= 0.9063
[email protected]

4
BMCG 1013 Differential Equations

1.3.1 Euler’s Method


Solution: (cont.)
𝑑𝑦
= 𝑓 𝑥, 𝑦 = 3𝑥 3 − 7𝑥 2 + 5𝑥 − 𝑦
𝑑𝑥
Update the time line:
1 0.5 0.8125 0.9063
|| || || ||
𝑦0 𝑦1 𝑦2 𝑦3 𝑦4

𝑥0 𝑥1 𝑥2 𝑥3 𝑥4
|| || || || ||
0 0.5 1.0 1.5 2.0

Let 𝑖 = 3,
𝑦4 = 𝑦3 + ℎ𝑓(𝑥3 , 𝑦3 )
= 0.9063 + 0.5𝑓(1.5, 0.9063)
= 0.9063 + 0.5 3 1.5 3 − 7 1.5 2
+ 5 1.5 − 0.9063
= 1.3907
[email protected]

BMCG 1013 Differential Equations

1.3.1 Euler’s Method


Solution: (cont.)
Update the time line:

1 0.5 0.8125 0.9063 1.3907


|| || || || ||
𝑦0 𝑦1 𝑦2 𝑦3 𝑦4

𝑥0 𝑥1 𝑥2 𝑥3 𝑥4
|| || || || ||
0 0.5 1.0 1.5 2.0

[email protected]

5
BMCG 1013 Differential Equations

1.3.1 Euler’s Method


Exercise 1.7:
Use Euler’s method to numerically integrate

𝑑𝑦
= 3𝑦 2 − 5𝑥 − 1, 𝑦 0 =0
𝑑𝑥
from 𝑥 = 0 to 𝑥 = 1 with a step size of 0.25.

[email protected]

BMCG 1013 Differential Equations

1.3.2 Second Order Runge-Kutta Method (RK2)


A method of numerically integrating ODE by using a trial
step at the midpoint of an interval to cancel out lower-order
error terms.

Second Order Formula: (known as RK2 or Ralson’s Method)


1 2
𝑦𝑖+1 = 𝑦𝑖 + 𝑘1 + 𝑘2 ℎ
3 3
where
𝑘1 = 𝑓 𝑥𝑖 , 𝑦𝑖
3 3
𝑘2 = 𝑓 𝑥𝑖 + 4 ℎ, 𝑦𝑖 + 4 𝑘1 ℎ

[email protected]

6
BMCG 1013 Differential Equations

1.3.2 Second Order Runge-Kutta Method (RK2)


The steps of RK2:

Line Rearrange: Discretizing: Compute


Structure 𝑦 ′ = 𝑓(𝑥, 𝑦) 𝑦𝑖′ = 𝑓 𝑥𝑖 , 𝑦𝑖 𝑦𝑖+1
& compute
values of 𝑘

Example:
Use the second order Runge-Kutta method to numerically
integrate
𝑦 ′ − 𝑦 = −𝑥 2 , 𝑦 0 =0
from 𝑥 = 0 to 𝑥 = 2 with a step size of 0.5.
[email protected]

BMCG 1013 Differential Equations

1.3.2 Second Order Runge-Kutta Method (RK2)


Reminder:
Solution: 𝑦 ′ = 𝑓(𝑥, 𝑦)
𝑦 ′ = 𝑓 𝑥, 𝑦 = 𝑦 − 𝑥 2
0 ≤ 𝑥 ≤ 2, ℎ = 0.5, 𝑦 0 =0

Construct the time line:


0
||
𝑦0 𝑦1 𝑦2 𝑦3 𝑦4
𝑥0 𝑥1 𝑥2 𝑥3 𝑥4
|| || || || ||
0 0.5 1.0 1.5 2.0

[email protected]

7
BMCG 1013 Differential Equations

1.3.2 Second Order Runge-Kutta Method (RK2)


Solution: (cont.)
𝑦 ′ = 𝑓 𝑥, 𝑦 = 𝑦 − 𝑥 2
0
||
𝑦0 𝑦1 𝑦2 𝑦3 𝑦4

𝑥0 𝑥1 𝑥2 𝑥3 𝑥4
|| || || || ||
0 0.5 1.0 1.5 2.0
Let 𝑖 = 0,
𝑘1 = 𝑓 𝑥0 , 𝑦0 = 𝑓 0, 0 1 2
𝑦1 = 𝑦0 + 𝑘1 + 𝑘2 ℎ
=0 3 3
1 2
3 3 = 0 + 3 0 + 3 −0.1406 (0.5)
𝑘2 = 𝑓 𝑥0 + ℎ, 𝑦0 + 𝑘1 ℎ = −0.0469
4 4
= 𝑓 0.375, 0
= −0.1406
[email protected]

BMCG 1013 Differential Equations

1.3.2 Second Order Runge-Kutta Method (RK2)


Solution: (cont.)
𝑦 ′ = 𝑓 𝑥, 𝑦 = 𝑦 − 𝑥 2
0 −0.0469
|| ||
𝑦0 𝑦1 𝑦2 𝑦3 𝑦4

𝑥0 𝑥1 𝑥2 𝑥3 𝑥4
|| || || || ||
0 0.5 1.0 1.5 2.0
Let 𝑖 = 1, 1 2
𝑦2 = 𝑦1 + 𝑘1 + 𝑘2 ℎ
𝑘1 = 𝑓 𝑥1 , 𝑦1 3 3
= 𝑓 0.5, −0.0469 = −0.0469
= −0.2969 1 2
+ −0.2969 + −0.9238 (0.5)
3 3
3 3 = −0.4043
𝑘2 = 𝑓 𝑥1 + ℎ, 𝑦1 + 𝑘1 ℎ
4 4
= 𝑓 0.875, −0.1582
= −0.9238
[email protected]

8
BMCG 1013 Differential Equations

1.3.2 Second Order Runge-Kutta Method (RK2)


Solution: (cont.)
𝑦 ′ = 𝑓 𝑥, 𝑦 = 𝑦 − 𝑥 2
0 −0.0469 −0.4043
|| || ||
𝑦0 𝑦1 𝑦2 𝑦3 𝑦4

𝑥0 𝑥1 𝑥2 𝑥3 𝑥4
|| || || || ||
0 0.5 1.0 1.5 2.0
Let 𝑖 = 2, 1 2
𝑦3 = 𝑦2 + 𝑘1 + 𝑘2 ℎ
𝑘1 = 𝑓 𝑥2 , 𝑦2 3 3
= 𝑓 1, −0.4043 = −0.4043
= −1.4043 1 2
+ 3 −1.4043 + 3 −2.8215 (0.5)
3 3 = −1.5789
𝑘2 = 𝑓 𝑥2 + ℎ, 𝑦2 + 𝑘1 ℎ
4 4
= 𝑓 1.375, −0.9309
= −2.8215
[email protected]

BMCG 1013 Differential Equations

1.3.2 Second Order Runge-Kutta Method (RK2)


Solution: (cont.)
𝑦 ′ = 𝑓 𝑥, 𝑦 = 𝑦 − 𝑥 2
0 −0.0469 −0.4043 −1.5789
|| || || ||
𝑦0 𝑦1 𝑦2 𝑦3 𝑦4

𝑥0 𝑥1 𝑥2 𝑥3 𝑥4
|| || || || ||
0 0.5 1.0 1.5 2.0
Let 𝑖 = 3, 1 2
𝑦4 = 𝑦3 + 𝑘1 + 𝑘2 ℎ
𝑘1 = 𝑓 𝑥3 , 𝑦3 3 3
= 𝑓 1.5, −1.5789 = −1.5789
= −3.8289 1 2
+ −3.8289 + −6.5303 (0.5)
3 3
3 3 = −4.3938
𝑘2 = 𝑓 𝑥3 + ℎ, 𝑦3 + 𝑘1 ℎ
4 4
= 𝑓 1.875, −3.0147
= −6.5303
[email protected]

9
BMCG 1013 Differential Equations

1.3.2 Second Order Runge-Kutta Method (RK2)


Solution: (cont.)
𝑦 ′ = 𝑓 𝑥, 𝑦 = 𝑦 − 𝑥 2

0 −0.0469 −0.4043 −1.5789 −4.3938


|| || || || ||
𝑦0 𝑦1 𝑦2 𝑦3 𝑦4
𝑥0 𝑥1 𝑥2 𝑥3 𝑥4
|| || || || ||
0 0.5 1.0 1.5 2.0

[email protected]

BMCG 1013 Differential Equations

1.3.2 Second Order Runge-Kutta Method (RK2)

Exercise 1.8:
Use the second order Runge-Kutta method to numerically
integrate

𝑑𝑦
+ 𝑦 = sin 𝑥 , 𝑦 0 =1
𝑑𝑥
from 𝑥 = 0 to 𝑥 = 3 with a step size of ℎ = 1.

[email protected]

10

You might also like