Transcript PPT

Euler Method
Chemical Engineering Majors
Authors: Autar Kaw, Charlie Barker
http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates
7/12/2016
http://numericalmethods.eng.usf.edu
1
Euler Method
http://numericalmethods.eng.usf.edu
Euler’s Method
y
dy
 f x, y , y 0  y 0
dx
Slope

Rise
Run

y1  y0
x1  x0
 f  x0 , y 0 
y1  y0  f x0 , y0 x1  x0 
 y0  f x0 , y0 h
3
True value
Φ
x0,y0
y1, Predicted
value
Step size, h
x
Figure 1 Graphical interpretation of the first step of Euler’s method
http://numericalmethods.eng.usf.edu
Euler’s Method
y
yi 1  yi  f xi , yi h
True Value
h  xi 1  xi
yi+1, Predicted value
Φ
yi
h
Step size
xi
xi+1
x
Figure 2. General graphical interpretation of Euler’s method
4
http://numericalmethods.eng.usf.edu
How to write Ordinary Differential
Equation
How does one write a first order differential equation in the form of
dy
 f  x, y 
dx
Example
dy
 2 y  1.3e  x , y 0   5
dx
is rewritten as
dy
 1.3e  x  2 y, y 0   5
dx
In this case
f x, y   1.3e  x  2 y
5
http://numericalmethods.eng.usf.edu
Example
The concentration of salt, x in a home made soap maker
is given as a function of time by
dx
 37.5  3.5 x
dt
At the initial time, t = 0, the salt concentration in the tank is
50g/L. Using Euler’s method and a step size of h = 1.5 min,
what is the salt concentration after 3 minutes.
dx
 37.5  3.5 x
dt
f t , x  37.5  3.5x
xi 1  xi  f t i , xi h
6
http://numericalmethods.eng.usf.edu
Solution
For i  0, t0  0, x0  50
Step 1:
x1  x0  f t0 , x0 h
 50  f 0,501.5
 50  37.5  3.5501.5
 50   137.501.5
 156.25 g / L
x1 is the approximate concentration of salt at
t  t1  t0  h  0  1.5  1.5 min
x1.5  x1  156.25g / L
7
http://numericalmethods.eng.usf.edu
Solution Cont
For i  1, t1  1.5, x1  156.25
Step 2:
x2  x1  f t1 , x1 h
 156.25  f 1.5,156.251.5
 156.25  37.5  3.5 156.251.5
 156.25  584.381.5
 720.31g / L
x 2 is the approximate concentration of salt at
t  t2  t1  h  15.  1.5  3 min
x3  x2  720.31g / L
8
http://numericalmethods.eng.usf.edu
Solution Cont
The exact solution of the ordinary differential equation is
given by
xt   10.714  39.286e 3.5 x
The solution to this nonlinear equation at t=3 minutes is
x3  10.715 g/L
9
http://numericalmethods.eng.usf.edu
Comparison of Exact and
Numerical Solutions
Figure 3. Comparing exact and Euler’s method
10
http://numericalmethods.eng.usf.edu
Effect of step size
Table 1. Concentration of salt at 3 minutes as a
function of step size, h
h
Step
3
1.5
0.75
0.375
0.1875
11
x3
Et
|t | %
−362.50
720.31
284.65
10.718
10.714
373.22
−709.60
−273.93
−0.0024912
0.0010803
3483.0
6622.2
2556.5
0.023249
0.010082
http://numericalmethods.eng.usf.edu
Comparison with exact results
Figure 4. Comparison of Euler’s method with
exact solution for different step sizes
12
http://numericalmethods.eng.usf.edu
Effects of step size on Euler’s
Method
Figure 5. Effect of step size in Euler’s method.
13
http://numericalmethods.eng.usf.edu
Errors in Euler’s Method
It can be seen that Euler’s method has large errors. This can be illustrated using
Taylor series.
dy
1 d2y
1 d3y
2
3
xi 1  xi  




y i 1  y i 
x

x

x

x
 ...
i

1
i
i

1
i
2
3
dx xi , yi
2! dx x , y
3! dx x , y
i
yi 1  yi  f ( xi , yi )xi 1  xi  
i
i
i
1
1
2
3
f ' ( xi , yi )xi 1  xi   f ' ' ( xi , yi )xi 1  xi   ...
2!
3!
As you can see the first two terms of the Taylor series
yi 1  yi  f xi , yi h are the Euler’s method.
The true error in the approximation is given by
Et 
14
f xi , yi  2 f xi , yi  3
h 
h  ...
2!
3!
Et  h 2
http://numericalmethods.eng.usf.edu
Additional Resources
For all resources on this topic such as digital audiovisual
lectures, primers, textbook chapters, multiple-choice
tests, worksheets in MATLAB, MATHEMATICA, MathCad
and MAPLE, blogs, related physical problems, please
visit
http://numericalmethods.eng.usf.edu/topics/euler_meth
od.html
THE END
http://numericalmethods.eng.usf.edu