0% found this document useful (0 votes)
4 views

analytical method lecture week 3

analytical method lecture week 3

Uploaded by

Patrick Chan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

analytical method lecture week 3

analytical method lecture week 3

Uploaded by

Patrick Chan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

2023/24 Year 2/TRI 1 NAME

NME2101 Analytical Methods


CHAPTER 1
Ordinary Differential Equation (ODE)
Numerical Solution

Dr. Tay Zhi Yung


Associate Professor,
Engineering Cluster,
Singapore Institute of Technology.
Email: [email protected]
0
Numerical Solution of First Order ODEs

3
Some of Numerical Solutions
❑ Direction Field
❑ Euler Method

4
Plot:
𝑦 = 2𝑥 + 𝑐
𝑦=𝑥
𝑦=2
𝑥=3

5
Direction Fields

Consider any first-order equation of the form


𝑦 ′ = 𝑓(𝑥, 𝑦)
Any solution of this equation is a function 𝑦 = 𝑦(𝑥) whose slope
at any particular point (𝑥, 𝑦) is given by 𝑓(𝑥, 𝑦).
We draw a short line segment through each of a sequence of
points (𝑥, 𝑦) with slope 𝑓(𝑥, 𝑦).

This collection of line segments is called the


direction field or slope field, and it gives
an indication of the behavior of the family of Direction Field

solutions of a differential
equation.
Video: How to construct the direction field?
https://www.youtube.com/watch?v=D3V5FmAUrpE
Class Exercise 1

Construct the direction field of the following ODE and compare with
its exact solution 𝑑𝑦 1
= 𝑦
𝑑𝑥 2
slope

The direction field is


the numerical
solution to the ODE
Class Exercise 1: The Exact Solution

𝑥 𝑥
The exact
𝐴2 𝑒 𝐴3 𝑒
2 2 solution to the
ODE is given as
𝑥
𝐴1 𝑒 2
y = Ae x /2

𝑥 𝑥
−𝐴1 𝑒 2 −𝐴3 𝑒 2

𝑥
−𝐴2 𝑒 2
Class Exercise 1: Exact vs Numerical Solution

𝑑𝑦 1 y = Ae x /2

= 𝑦 𝑦′ = 4
𝑑𝑥 2
𝑦′ = 1

𝑦′ = 0
𝑦 ′ = −1
𝑦 ′ = −4
Euler’s Method
Consider the Initial Value Problem 𝑦 ′ = 𝑓 𝑥, 𝑦 , 𝑦 𝑥0 = 𝑦0
Any solution of this equation is a function 𝑦 = 𝑦(𝑥) whose
slope at any particular point (𝑥, 𝑦) is given by 𝑓(𝑥, 𝑦).

We know the point (x0, y0) is on


the solution curve.

We now consider how to


approximate the solution at 𝑥 =
𝑥1 [i.e., 𝑦(𝑥1)] using the tangent
line at (𝑥0, 𝑦0).
Euler’s Method (Con’t)

Assuming 𝑥1 is not too far from 𝑥0, we follow the tangent line at
(𝑥0, 𝑦0) to the point at 𝑥 = 𝑥1 and use the 𝑦-value at that point
(call it 𝑦1) as the approximation to 𝑦(𝑥1).
y y(x1)
(x1, y(x
1)1, y1)
y1 {
(x0, y0) y’(x0)(x1-x0)
y0

x
x0 x1
The equation
Thus of the
we get the tangent line at 𝑥 = 𝑥1 is
approximation
𝑦 𝑥1 𝑦≈= 𝑦1𝑦= 0+𝑦0 𝑦′(𝑥 0 )(𝑥
+ 𝑦′(𝑥 −1 −
0 )(𝑥 𝑥0𝑥)0 )
13
Euler’s Method (Con’t)

We wish to find an approximate solution at a sequence of points


in the interval [𝑎, 𝑏]. First, we partition the interval [𝑎, 𝑏] into 𝑛
equal-sized pieces We may now write
𝑎 = 𝑥0 < 𝑥1 < 𝑥2 < ⋯ < 𝑥𝑛 = 𝑏 𝒚 𝒙𝟏 ≈ 𝒚𝟏
y = 𝒚𝟎 + 𝒚′ 𝒙𝟎 𝒙𝟏 − 𝒙𝟎
𝑥𝑖+1 − 𝑥𝑖 = ℎ, y(x1)
𝑖 = 0,1, … , 𝑛 − 1
= 𝒚𝟎 + 𝒉𝒇 𝒙𝟎 , 𝒚𝟎
ℎ is called the step size.
(x1, y1)
y1 {
(x0, y0) y’(x0)(x1-x0)
y0
x1 x2 x3...
x
a=xx0 x1 n
b=x
Euler’s Method (Con’t)

We now approximate 𝑦(𝑥2) by using the 𝑡𝑎𝑛𝑔𝑒𝑛𝑡 𝑙𝑖𝑛𝑒 at the


point (𝑥1, 𝑦(𝑥1)).
𝑦 𝑥2 ≈ 𝑦 𝑥1 + 𝑦 ′ 𝑥1 𝑥2 − 𝑥1
= 𝑦 𝑥1 + ℎ𝑓(𝑥1 , 𝑦 𝑥1 )

Continuing in this way, leads to the method called Euler’s Method.

EULER’S METHOD

𝑦 𝑥𝑖+1 ≈ 𝑦𝑖+1 = 𝑦𝑖 + ℎ𝑓 𝑥𝑖 , 𝑦𝑖 , 𝑓𝑜𝑟 𝑖 = 0,1,2, …


Example 1
Using Euler’s Method

Use Euler’s method to approximate the solution of the IVP


𝑦 ′ = 𝑦, 𝑦 0 =1

Note: We can easily obtain the solution to this IVP.


𝑦 = 𝑦 𝑥 = 𝑒𝑥

We will use it to evaluate the performance of Euler’s method.


Solution:

𝑦 ′ = 𝑦, 𝑦 0 =1

We have 𝑓(𝑥, 𝑦) = 𝑦 and we will take ℎ = 1.


𝑦 𝑥𝑖+1 ≈ 𝑦𝑖+1 = 𝑦𝑖 + ℎ𝑓 𝑥𝑖 , 𝑦𝑖 , 𝑓𝑜𝑟 𝑖 = 0,1,2, …

and so on…
Solution (Con’t)

We may continue in this way


obtaining a sequence of
approximate values. The
graph shows how the error
grows.

➢ Error grows as x gets farther and farther from the initial point.
➢ This is characteristic of Euler’s method.
Solution (Con’t)
Error=Exact- 1.7
x Euler Exact
Euler (× 𝟏𝟎−𝟏 )
0 1.00 1.00 0.00 1.6
0.1 1.10 1.11 0.05 1.5
0.2 1.21 1.22 0.11
0.3 1.33 1.35 0.19 1.4

f(x)
0.4 1.46 1.49 0.28
0.5 1.61 1.65 0.38 1.3
0.6 1.77 1.82 0.51 1.2
0.7 1.95 2.01 0.65
0.8 2.14 2.23 0.82 1.1
0.9 2.36 2.46 1.02
1
In this table Euler’s 0 0.2 0.4
method with ℎ = 0.1 was x
used to obtain the Euler, h=0.1 Euler, h=0.01
Exact
approximate values.
Note that the smaller the h, the more accurate the
approximation and the more steps it takes to reach a
given value of x.

Here, the exact value of the solution is y = e1 ≈ 2.718281.


Class Exercise 1

Use Euler’s method to obtain an approximation to the initial-


value problem

dx
= x 2 te −t , x(0) = 0.91
dt

for step sizes ℎ = 0.05, 0.025, and 0.0125.

(This example is meant to show you that the smaller the


step size, the more accurate the approximation. )
21
Solution:

22
Class Exercise 3

Use Euler’s method to obtain an approximation to the initial-value


problem

𝑑𝑦 1
= 𝑥 2 + 𝑦2, y (−1) = −
𝑑𝑥 2
for step size ℎ = 0.1.

Find 𝑦(−0.5)

23
Solution:
dy 1
= x2 + y 2 , y (−1) = −
dt 2
Using Euler's method with ℎ = 0.1, we get
𝑦 𝑥1 ≈ 𝑦1 = 𝑦0 + ℎ𝑓 𝑥0 + 𝑦0
= y0 + ℎ x02 + 𝑦02
2
1 2
1
= − + 0.1 −1 + −
2 2
= −0.375
𝑦 𝑥2 ≈ 𝑦2 = 𝑦1 + ℎ𝑓 𝑥1 , 𝑦1
= y1 + ℎ𝑓 x12 + 𝑦12
= −0.375 + 0.1 0.9 2 + −0.375 2

= −0.2799375
and so on… 24
Continuing in this way, we generate the table of values
that follows.
x Euler x Euler x Euler
-1.0 -0.5000 0.1 -0.0576 1.2 0.4693
-0.9 -0.3750 0.2 -0.0563 1.3 0.6354
-0.8 -0.2799 0.3 -0.0519 1.4 0.8447
-0.7 -0.2081 0.4 -0.0427 1.5 1.1121
-0.6 -0.1548 0.5 -0.0265 1.6 1.4608
-0.5 -0.1164 0.6 -0.0014 1.7 1.9301
-0.4 -0.0900 0.7 0.0346 1.8 2.5917
-0.3 -0.0732 0.8 0.0837 1.9 3.5874
-0.2 -0.0637 0.9 0.1484 2.0 5.2353
-0.1 -0.0593 1.0 0.2316 2.1 8.3761
0.0 -0.0579 1.1 0.3370 2.2 15.8329
25
Plot using the data in the table, we obtain the
approximate solution.

26
We can see that the approximate solution
superimposed on the direction field, indicating a
reasonable approximation. dy
= x2 + y 2 ,
dt

27

You might also like