Lecture 09
Lecture 09
Lecture 09
Lecture 9
Ordinary Differential Equations (ODEs)
1
Learning Objectives
Derive Euler formula using the Taylor
series expansion.
Solve the first order ODEs using Euler
method.
Assess the error level when using Euler
method.
Appreciate different types of errors in the
numerical solution of ODEs.
Improve Euler method using higher-order
Taylor Series.
2
Taylor Series Method
The problem to be solved is a first order ODE:
dy ( x)
f ( x, y ), y ( x0 ) y0
dx
Estimates of the solution at different base points:
3
Taylor Series Expansion
Truncated Taylor Series Expansion
n
h k d k y
y ( x0 h)
k ! dx k
k 0
x x0 , y y 0
dy h2 d 2 y hn d n y
y ( x0 ) h 2
...
dx x x0 ,
y y
2! dx x x0 , n! dx n x x0 ,
0 y y0 y y0
4
Euler Method
First order Taylor series method is
known as Euler Method.
Notation :
xn x0 nh, yn y ( xn ),
dy
f ( xi , yi )
dx x xi ,
y yi
Euler Method
yi 1 yi h f ( xi , yi )
6
Euler Method
Problem :
Given the first order ODE : y ( x) f ( x, y )
with the initial condition : y0 y ( x0 )
Determine : yi y ( x0 ih) for i 1,2,...
Euler Method :
y0 y ( x0 )
yi 1 yi h f ( xi , yi ) for i 1,2,...
7
Interpretation of Euler Method
y2
y1
y0
x0 x1 x2 x
8
Interpretation of Euler Method
Slope=f(x0,y0)
y1
y1=y0+hf(x0,y0)
hf(x0,y0)
y0
x0 x1 x2 x
h
9
Interpretation of Euler Method
y2 y2=y1+hf(x1,y1)
Slope=f(x1,y1)
hf(x1,y1)
Slope=f(x0,y0)
y1 y1=y0+hf(x0,y0)
hf(x0,y0)
y0
x0 x1 x2 x
h h
10
Example 1
Use Euler method to solve the ODE:
dy
1 x ,
2
y (1) 4
dx
to determine y(1.01), y(1.02) and y(1.03).
11
Example 1
f ( x, y ) 1 x , 2
x0 1, y0 4 , h 0.01
Euler Method
yi 1 yi h f ( xi , yi )
Step3 :
y3 y2 h f ( x2 , y2 ) 3.9598 0.01 1 1.02 3.9394
2
12
Example 1
f ( x, y ) 1 x ,
2
x0 1, y0 4 , h 0.01
Summary of the result:
i xi yi
0 1.00 -4.00
1 1.01 -3.98
2 1.02 -3.9595
3 1.03 -3.9394
13
Example 1
f ( x, y ) 1 x ,
2
x0 1, y0 4 , h 0.01
Comparison with true value:
i xi yi True value of yi
0 1.00 -4.00 -4.00
1 1.01 -3.98 -3.97990
2 1.02 -3.9595 -3.95959
3 1.03 -3.9394 -3.93909
14
Example 1
f ( x, y ) 1 x ,
2
x0 1, y0 4 , h 0.01
A graph of the
solution of the
ODE for
1<x<2
15
Types of Errors
Local truncation error:
Error due to the use of truncated Taylor
series to compute x(t+h) in one step.
Global Truncation error:
Accumulated truncation over many steps.
Round off error:
Error due to finite number of bits used in
representation of numbers. This error could
be accumulated and magnified in
succeeding steps.
16
Example 2: Euler’s Method (1 of 3)
dx 2! dx
2
d y
2
needs to be derived analytically.
dx
22
Third Order Taylor Series Methods
dy ( x)
Given f ( y, x), y ( x0 ) y0
dx
Third order Taylor Series method
2 2 3 3
dy h d y h d y
yi 1 yi h 2
3
O(h )
4
dx 2! dx 3! dx
2 3
d y d y
2
and 3 need to be derived analytically.
dx dx
23
High Order Taylor Series Methods
dy ( x)
Given f ( y, x), y ( x0 ) y0
dx
th
n order Taylor Series method
dy h 2 d 2 y hn d n y n 1
yi 1 yi h 2
.... n
O(h )
dx 2! dx n! dx
2 3 n
d y d y d y
2
, 3 ,....., n need to be derived analytically.
dx dx dx
24
Higher Order Taylor Series Methods
High order Taylor series methods are
more accurate than Euler method.
25
Example 4
Second order Taylor Series Method
2
d x(t )
What is : 2
?
dt
26
Example 4
Use Second order Taylor Series method to solve :
dx
2 x t 1, x(0) 1,
2
use h 0.01
dt
dx
1 2x2 t
dt
d 2 x(t ) dx
2
0 4 x 1 4 x (1 2 x 2
t ) 1
dt dt
2
h
xi 1 xi h(1 2 xi ti ) ( 1 4 xi (1 2 xi ti ))
2 2
2
27
Example 2
f (t , x) 1 2 x 2 t , t0 0, x0 1, h 0.01
2
h
xi 1 xi h(1 2 xi ti ) ( 1 4 xi (1 2 xi ti ))
2 2
2
Step 1 :
x1 1 0.01(1 2(1) 2
0)
0.01
2
(1 4(1)(1 2 0)) 0.9901
2
Step 2 :
28
Example 4
f (t , x) 1 2 x 2 t , t0 0, x0 1, h 0.01
Summary of the results:
i ti xi
0 0.00 1
1 0.01 0.9901
2 0.02 0.9807
3 0.03 0.9716
29
Programming Euler Method
Write a MATLAB program to implement
Euler method to solve:
dv
1 2v t.
2
v(0) 1
dt
31
Programming Euler Method
f=inline('1-2*v^2-t','t','v')
h=0.01 Definition of the ODE
t=0
Initial condition
v=1
T(1)=t;
V(1)=v;
for i=1:100 Main loop
v=v+h*f(t,v)
t=t+h; Euler method
T(i+1)=t;
V(i+1)=v; Storing information
end
32
Programming Euler Method
Plot of the
solution
plot(T,V)
33