Professional Documents
Culture Documents
EWCE 205: Numerical Methods
EWCE 205: Numerical Methods
1
Euler’s Method
dy
f x, y , y x0 y0 True value
dx
y1, Predicted
Rise
Slope x0,y0 Φ value
Run
y y0
1
x1 x0 Step size, h
f x0 , y 0 x
y1 y 0 f x0 , y 0 x1 x0
Figure 1 Graphical interpretation of the first step of Euler’s method
y0 f x0 , y0 h
2
Euler’s Method
y
yi 1 yi f xi , yi h True Value
Φ
yi
h
Step size
x
xi xi+1
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
dt
2.2067 10 12 4 81 108 , 0 1200 K
Find the temperature at t 480 seconds using Euler’s method. Assume a step size of
h 240 seconds.
5
Solution
Step 1:
d
dt
2.2067 10 12 4 81 10 8
f t , 2.2067 10 12 4 81 108
i 1 i f ti , i h
1 0 f t0 , 0 h
1200 f 0,1200 240
1200 2.2067 10 12 1200 4 81 108 240
1200 4.5579 240
106.09 K
1 is the approximate temperature at t t1 t0 h 0 240 240
240 1 106.09 K
6
Solution Cont
Step 2: For i 1, t1 240, 1 106.09
2 1 f t1 , 1 h
106.09 f 240,106.09 240
106.09 2.2067 10 12 106.09 4 81 108 240
106.09 0.017595 240
110 .32 K
2 is the approximate temperature at t t2 t1 h 240 240 480
480 2 110.32 K
7
Solution Cont
300
0.92593 ln 1.8519 tan 1 0.00333 0.22067 10 3 t 2.9282
300
(480) 647.57 K
8
Comparison of Exact and Numerical Solutions
1400
1200
Temperature, θ(K)
1000
Exact Solution
800
600
400
h=240
200
0
0 100 200 300 400 500
Time, t(sec)
10
Comparison with exact results
1500
500
h=120
h=240
0
0 100 200 300 400 500
-500
Time, t (sec) h=480
-1000
-1500
Figure 4. Comparison of Euler’s method with exact solution for different step sizes
11
Effects of step size on Euler’s Method
800
400
Temperature,θ(K)
0
0 100 200 300 400 500
-400
Step size, h (s)
-800
-1200
It can be seen that Euler’s method has large errors. This can be illustrated using
Taylor series.
dy 1 d2y 1 d3y
y i 1 y i xi 1 xi 2
x i 1 x i 2
3
x i 1 x i 3
...
dx xi , yi 2! dx x , y 3! dx x , y
i i i i
1 1
yi 1 yi f ( xi , yi ) xi 1 xi f ' ( xi , yi ) xi 1 xi f ' ' ( xi , y i ) xi 1 xi ...
2 3
2! 3!
As you can see the first two terms of the Taylor series
14
Runge Kutta Method (Heun’s Method)
y
Slope f xi h, yi k1h
yi+1, predicted
Slope f xi , yi
1
Average Slope f xi h, yi k1h f xi , yi
2
yi
x
xi xi+1
15
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 10 12 4 81 10 8 , 0 1200 K
Find the temperature at t 480 seconds using Heun’s method. Assume a step size of
h 240 seconds.
d
dt
2.2067 10 12 4 81 10 8
f t , 2.2067 10 12 4 81 108
1 1
i 1 i k1 k 2 h
2 2
16
Solution
Step 1: i 0, t0 0, 0 (0) 1200 K
k1 f t0 , o k 2 f t0 h, 0 k1h
f 0,1200 f 0 240,1200 4.5579 240
2.2067 10 12 1200 4 81 108 f 240,106.09
4.5579
2.2067 10 12 106.09 4 81108
0.017595
1 1
1 0 k1 k 2 h
2 2
1 1
1200 4.5579 0.017595 240
2 2
1200 2.2702 240
655.16 K
17
Solution Cont
Step 2: i 1, t1 t 0 h 0 240 240,1 655.16 K
k1 f t1 ,1 k 2 f t1 h, 1 k1h
f 240,655.16 f 240 240,655.16 0.38869 240
f 480,561.87
2.2067 10 12 655.16 4 81108
0.38869
2.2067 10 12 561.87 4 81108
0.20206
1 1
2 1 k1 k 2 h
2 2
1 1
655.16 0.38869 0.20206 240
2 2
655.16 0.29538 240
584.27 K
18
Comparison with exact results
1200
Exact h=120
Temperature, θ(K)
800
h=240
400
h=480
0
0 100 200 300 400 500
-400
Time, t(sec)
19
Effect of step size
20
Runge-Kutta 4th Order Method
For
dy
f ( x, y ), y (0) y0
dx
Runge Kutta 4th order method is given by
1
yi 1 yi k1 2k2 2k3 k4 h
6
where
k1 f xi , yi
1 1
k 2 f xi h, yi k1h
2 2
1 1
k3 f xi h, yi k2 h
2 2
k 4 f xi h, yi k3h
21
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 10 12 4 81 10 8 , 0 1200 K
Find the temperature at t 480 seconds using Runge-Kutta 4th order method.
1
i 1 i k1 2k 2 2k 3 k 4 h
6
22
Solution
Step 1: i 0, t0 0, 0 (0) 1200
1 1 1 1
k 2 f t0 h, 0 k1h f 0 240 ,1200 4.5579 240
2 2 2 2
f 120,653.05 2.2067 10 12 653.054 81 108 0.38347
1 1 1 1
k3 f t0 h, 0 k 2 h f 0 240 ,1200 0.38347 240
2 2 2 2
f 120,1154 .0 2.2067 10 12 1154 .0 4 81 108 3.8954
23
Solution Cont
1
1 0 k1 2k 2 2k3 k 4 h
6
1
1200 4.5579 2 0.38347 2 3.8954 0.069750 240
6
1
1200 2.1848 240
6
675.65 K
t t1 t0 h 0 240 240
240 1 675.65K
24
Comparison with exact results
θ(K ) 1600
1200
Tem perature,
h=120
800 Exact
h=240
400
h=480
0
0 200 400 600
-400
Time,t(sec)
25
Effect of step size
Table 1. Temperature at 480 seconds as a function of step size, h
26
THANKS
27