Euler's Method for Differential Equations
Euler's Method for Differential Equations
Method
Analisis Numerik
1
Euler’s
Method y
dy
f x, y, y0 True value
dx
y0
y1, Predicted
Rise value
Slope x0,y 0 Φ
Run
y1 y0 Step size, h
x1 x0
x
f x0 , y0
y1 y0 f x0 , y0 x1 x0
Figure 1 Graphical interpretation of the first step of Euler’s
method
y 0 f x 0 , y 0 h
2
Euler’s Method
y
f xi , yi True
yi1 yi Value
h
h xi1 xi yi+1, Predicted
value
Φ
yi
h
St
ep
x
xi siz
e xi+1
dy
2 y 1.3ex , y0
dx
5
is rewritten as
dy
1.3ex 2 y, y0
dx
5
In this case
f x, y 1.3e x 2
y 4
Example
A ball at 1200K is allowed to cool down in air at an ambient temperature
of 300K. Assuming heat is lost only due to radiation, the differential
equation for the temperature of the ball is given by
d
2.2067 1012 4 81108 , 0 1200K
dt
Find the temperature at t 480 seconds using Euler’s method. Assume a step size
h seconds. of
240
5
Solution
Step 1:
106.09 4 240
106.09 0.017595 240
110.32K
2 is the approximate temperature at t t2 t1 h 240 240 480
480 2 110.32K
7
Solution
Cont
300
0.92593 ln 1.8519 tan10.00333 0.22067 103 t 2.9282
300
8
Comparison of Exact and Numerical
Solutions
140
0
Temperature, θ(K)
120
0
Exact
80
100 Solution
00
60
0
h=24
40 0
0
0
20 0 10 200 40 50
0 0 300 0 0
Time, t(sec)
(480) (exact
647.57K )
10
Comparison with exact
results
150
0
Exact
Temperature, θ(K)
100 solution
050
0
h=12
0 h=2 40
0
0 100 200 30 400
- 0
500 Time, t (sec) h=48 500
-
0
1000
-
1500
Temperature,θ(K) 40
0
-
1200
1 2 1 3
yi1 yi f (xi , yi )xi1 x i f ' (xi , i i1 x i f ' ' (xi , yi )i1x xi ..
2! 3 .
x you can see the first two terms of the Taylor !
y )As
series
f xi , yi
yi1 yi are the Euler’s method.
The trueerror
h
in the approximation is
given by
f x , y f x , y Et h2
Et i i h2 i i h3
2! 3 ...
! 13
Runge 2nd Order
Method
14
Runge-Kutta 2nd Order Method
Fo dy
dx f (x, y), y(0)
0
r
y
Runge Kutta 2nd order method is
given by
a1k1 a 2 k2
yi 1 yi
h
where
k1 f xi , yi
k2 f xi p1h, yi
q11k1h
15
Heun’s
Method
Heun’s
Slope f xi h, yi
method y
where
k1 f xi , yi
k 2 f xi 2 h, i 2 k 1h
1 1
y 17
Ralston’s Method
Her a2 2 is chosen,
e 3 giving
a1
1 3
p1
3 4
q11 3
4
resulting
in
yi1 yi 1 3 k 2 h
1 2
3
k
where
k1 f xi , yi
k 2 f xi 4 h, yi 4 k1 h
3 3
18
How to write Ordinary Differential
Equation
How does one write a first order differential equation in the
form of
dy
f x,
dx
y
Example
dy
2 y 1.3ex , y0
dx
5
is rewritten as
dy
1.3ex 2 y, y0
dx
5
In this case
f x, y 1.3e x 2
y 19
Example
A ball at 1200K is allowed to cool down in air at an ambient temperature
of 300K. Assuming heat is lost only due to radiation, the differential
equation for the temperature of the ball is given by
d
dt
2.2067 1012 4 81108 ,0 1200K
1 1
1 k1 2 k 2 h
0
2 0.017595
1 1
1200 4.5579 0.017595
2 2
240
1200
2.2702240
655.16K 2
1
Solution
Cont
Step 2: i 1, t1 t 0 h 0 240 240,1
655.16K k 2 f t1 h,1 k1h
k1 f 1t ,1
f 240 240,655.16 0.38869
f
240,655.16
2.2067 10 12
655.16 4
81108
240480,561.87
f
2.2067
1012 561.874
81108
0.38869 0.20206
2 1 1 1k 2 1 k2
2
h 1 1
655.16 0.38869 0.20206
2 2
240
655.16
0.29538240
584.27K 22
Solution
Cont
300
0.92593 ln 1.8519 tan10.0033333 0.22067 103 t 2.9282
300
23
Comparison with exact
results
120
0
Exac h=12
Temperature, θ(K) 80 t 0
0
h=24
40 0
h=48
0
0
0
0 10 20 30 40 50
0 0 0 0 0
-
400 Time, t(sec)
(480) (exact
647.57K )
25
Effects of step size on Heun’s
Method
80
0
Temperature, θ(480)
60
0
40
0
20 0 10 200 40 50
- 0 0 300 0 0
200 Step size, h
0
-400
(480) (exact
647.57K ) 28
Comparison of Euler and Runge-Kutta
2nd Order Methods
120
0
110
01 0 0
Midpoin
Temperature, θ(K
0 t
) Ralston
900
800 Heu
n
700
Analytic
al
600
Eule
r
0 500 100 200 300 400 500 600
Time, t (sec)
30
Runge-Kutta 4th Order Method
Fo dy
dx f (x, y), y(0)
0
r
Runge yKutta 4th order method is
given by1
yi 1 yi 1k 2k
2 2k3 k4
6
hwhere
k1 f xi , yi
k 2 f xi 21 h, yi 21 k1 h
k3 f xi 2 h, yi 2 k2 h
1 1
k4 f xi h, yi
k3 h 31
How to write Ordinary Differential
Equation
How does one write a first order differential equation in the
form of
dy
f x,
dx
y
Example
dy
2 y 1.3ex , y0
dx
5
is rewritten as
dy
1.3ex 2 y, y0
dx
5
In this case
f x, y 1.3e x 2
y 32
Example
A ball at 1200K is allowed to cool down in air at an ambient temperature
of 300K. Assuming heat is lost only due to radiation, the differential
equation for the temperature of the ball is given by
d
dt
2.2067 1012 4 81108 ,0 1200K
240 1 3
675.65K 5
Solution
Cont
Step 2: i 1,t1 240,1
675.65K
k f t , f240,675.65 2.2067 1012 675.65 4 81108 0.44199
1 1 1
1 1 1 1
k 2 f 1t h,1 k1 h f 240 240, 675.65 0.44199
2 2 2 2
240
f 360,622.61 2.2067 1012 622.614 81108
0.31372
1 1 1 1
k3 f 1t h,1 k2 h f 240 240,675.65 0.31372
2 2 2 2
240
f 360, 638.00 2.2067 1012 638.004 81108
0.34775
k4 f t1 h,1 k3h f 240 240,675.65
0.34775240
36
f 480,592.19 2.2067 1012 592.194 81108
Solution
Cont
2 1 k1 2 2k3 k4
1
6
2k h
1
675.65 0.44199 2 0.31372 2 0.34775
6
0.25351240
1
675.65
6
2.0184 240
594.91K
is the approximate
temperature at
480 2 594.91K
37
Solution
Cont
300
0.92593 ln 1.8519 tan1 0.00333 0.22067 103 t 2.9282
300
The solution to this nonlinear equation at t=480
seconds is
(480) 647.57K
38
Comparison with exact
results
160
0
120
Temperature,
0 h=12
800 0 Exac
t h=24
0
θ(K)
400
h=480
0
600
0 200
- 400
400
Time,t(sec)
(480) (exact
647.57K ) 40
Effects of step size on Runge-Kutta
4th Order Method
80
0
Temperature, θ(480)
60
0
40
0
20
0 0 10 20 30 40 50
- 0 0 0 0 0
200
0 Step size, h
θ(K)
120 4th
Temperature, 0 order
80
100 Exac
00
60 t
0 Heu
40 n
20
0 Eule
0 r
0
0 10 200 40 50
0 300 0 0
Time, t(sec)
Figure [Link] of Runge-Kutta methods of 1st, 2nd, and
4th order. 42
Terima Kasih
43