Professional Documents
Culture Documents
dy (t ) at
ay (t ) y(t ) y(0)e
dt
Exponential growth or decay is governed by this
simple ODE. Put some t for a = -1.0 to check.
“Solving” an ODE
Answer the question:
what function can we construct such that it has
the relationship to its derivative that the ODE
expresses?
Solving an ODE by hand requires lots of mathematical
intuition and experience.
ODE is mathematical model
An engineering process can often be described using
ODEs; for example
• Radioactive decay
• Chemical processes
• Mechanical processes
• Controls of almost anything
• Population dynamics
• Diffusion of almost anything
• Transient electrical circuits
ODE’s and Linear Systems
y(t)=10e2t y(t)=10e-2t
d 2
ML 2 MG sin
dt L
d 2 G
2
sin
dt L M
y y y0 True
slope 1 value
x x1 x0 y1,
Predicted
slope f x0 , y0
. value
Φ
( x0 , y0)
y1 y0 f x0 , y0 x1 x0
Step size, h
y1 y0 f x0 , y0 h x
y2 y1 f x1 , y1 h
Figure 1. Graphical interpretation of the
first step of Euler’s method
Euler’s Method for ODEs
y1 y0 f x0 , y0 h y
y3 y2 f x2 , y2 h
yi+1,
: yi Predicted
: Φ value
h
yi 1 yi f xi , yi h Step size
xi xi+1 x
h xi 1 xi
Figure 2. General graphical interpretation of Euler’s method
Example 1 on Euler method
There are many differential equations that can not be solved.
We can still find an approximate solution.
Exact Solution:
dy 2 x dx y x2 C 1 0C
y x2 1
Example 1 on Euler method
dy
f ( x, y ) 2 x, y (0) 1
dx
First point: x1 x0 h 0 0.5 0.5
y1 y0 f x0 , y0 h y0 2 x0 h
1.0 ( 2 0) 0.5 1.0 0.0 1
exact (0) 2 1 1
error 0.
0 0 1 0 0 1 1
3
Euler method
grows as we 2
move forward
in x. 1
dy
f ( x, y ) x y , y (0) 1
dx
is rewritten as
dy
x y, y 0 1 f x, y x y
dx
x1 x0 h 0 0.1 0.1
y1 y0 f x0 , y0 h y0 x0 y0 h
1.0 (0 1.0) 0.1 1.0 0.1 0.9
A comparison table for estimated values and the true values and error
First point:
x1 x0 h 0 0.1 0.1
y1 y0 f x0 , y0 h y0 x0 2 y0 h
1.0 (0 2.0) 0.1 1.0 0.2 0.8
y4 y3 f x3 , y3 h y3 x3 2 y3 h
0.54 (0.3 2 0.54) 0.1 0.462
Fifth iteration:
x5 x0 5h 0.0 0.5 0.5
y5 y4 f x4 , y4 h y4 x4 2 y4 h
0.462 (0.4 2 0.462) 0.1 0.4096
Example 3 :
dy
Example (continued) - x 2 y, y (0) 1
dx
Actual solution is : 5 x 1
y exp( 2 x )
4 2 4
A comparison table for estimated values and the true values and error
for k=1:n
f = x - 2.0*y ;
y = y + f*h;
x = x + h;
yexact = 1.25*exp(-2.*x)+0.5*x-0.25;
error= yexact - y;
fprintf('%6.2f %12.6f %12.6f %12.6f\n', x,y,yexact,error);
end
Example 3 :
Results from computer program in MATLAB :
x1 x0 h x2 x0 2h x3 x0 3h
y( x1 ) y1 y( x2 ) y2 y( x3 ) y3
• h = step size
• Taylor series expansion
dy ( x) h 2 d 2 y ( x)
y ( x h) y ( x ) h 2
dx 2! dx
Forward Euler Method
• First-order Taylor series expansion
dy ( x)
y ( x h) y ( x ) h y ( x) hf ( x, y )
dx
• Iterative calculation
y1 y0 hf ( x0 , y0 ) y2 y1 hf ( x1 , y1 )
yn 1 yn hf ( xn , yn ) n 0,1,2,
• Approximation error
dy ( x) h 2 d 2 y ( )
y ( x h) y ( x ) h x xh
dx 2! dx 2
• Local truncation error: O(h2)
• Global truncation error: O(h) first-order method
Backward Euler Method
• Forward Euler
dy ( x) yn 1 yn
f ( x, y ) f ( xn , y n ) yn 1 yn hf ( xn , yn )
dx h
• Explicit formula for yn+1 (explicit method)
• Backward Euler
dy ( x) yn 1 yn
f ( x, y ) f ( xn 1 , yn 1 ) yn 1 yn hf ( xn 1 , yn 1 )
dx h
dy 1 d2y 2 1 d3y 3
y ( x 0 h) y ( x 0 ) h 2
h 3
h ....
dx 0 2! dx 0 3! dx 0
1 d2y 2 1 d3y 3
y( x0 h) y( x0 ) hf ( x0 , y( x0 )) 2
h 3
h ....
2! dx 0 3! dx 0
Euler Algorithm Truncation Error
• For the first step when we know f(x0,y(x0)), and we can see
the first term in the local truncation error.
• Local truncation error for Euler algorithm is of second
order and proportional to h2 .
• It can be show that when local error is of order n, the
method has a global error of order n-1.
Local and Global Error in Euler method
• The Euler method has second order local error;
• Then it will have first order global error;
•
• A rough comparison of errors versus step size (h) is
given below: