analytical method lecture week 3
analytical method lecture week 3
3
Some of Numerical Solutions
❑ Direction Field
❑ Euler Method
4
Plot:
𝑦 = 2𝑥 + 𝑐
𝑦=𝑥
𝑦=2
𝑥=3
5
Direction Fields
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 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 𝑓(𝑥, 𝑦).
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)
EULER’S METHOD
𝑦 ′ = 𝑦, 𝑦 0 =1
and so on…
Solution (Con’t)
➢ 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.
dx
= x 2 te −t , x(0) = 0.91
dt
22
Class Exercise 3
𝑑𝑦 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