0% found this document useful (0 votes)
15 views43 pages

Euler's Method for Differential Equations

Uploaded by

Mumtaza Harez
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views43 pages

Euler's Method for Differential Equations

Uploaded by

Mumtaza Harez
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

ODE : Euler

Method
Analisis Numerik

1
Euler’s
Method y

dy
 f x, y, y0  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
yi1  yi Value

h
h  xi1  xi yi+1, Predicted
value
Φ
yi
h
St
ep
x
xi siz
e xi+1

Figure 2. General graphical interpretation of Euler’s


method 3
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.3ex , y0 
dx
5
is rewritten as
dy
 1.3ex  2 y, y0 
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 1012  4  81108 , 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:

 2.2067 1012 4  81108


d
dt
f t,   2.2067 10 
12 4


81108  f ti ,i
i1  i
h f  t0 ,  0  h
1  0
 1200  f 0,1200 240
 1200   2.2067 1012 1200 4  24
81108 0
 1200   4.5579 240

1 approximate temperature at t  t1  t0  h  0  240 
is the 106.09K
 240  1 240
106.09K 6
Solution
Cont
Step 2: For i t1  240, 1
1, 106.09
 2  1  f t1,1 h
 106.09  f 240,106.09240
 106.09   2.2067 10 12  8110 8

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

The exact solution of the ordinary differential equation is


given by the solution of a non-linear equation as

  300
0.92593 ln 1.8519 tan10.00333   0.22067 103 t  2.9282
  300

The solution to this nonlinear equation at t=480


seconds is
 (480) 
647.57K

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)

Figure [Link] exact and Euler’s


method
9
Effect of step
size
Table 1. Temperature at 480 seconds as a function of step
size, h
Step, h (480) Et |єt|%
480 −987.81 1635.4 252.54
240 110.32 537.26 82.964
120 546.77 100.80 15.566
60 614.97 32.607 5.0352
30 632.77 14.806 2.2864

 (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

Figure [Link] of Euler’s method with exact solution for different


step sizes
11
Effects of step size on Euler’s
Method
80
0

Temperature,θ(K) 40
0

0 100 200 300 400 500


0
-
400
Step size, h (s)
-800

-
1200

Figure [Link] of step size in Euler’s


method. 12
Errors in Euler’s
Method
It can be seen that Euler’s method has large This can be illustrated
errors. Taylor series. using
dy 1 d 2y 1 d 3y

yi1  yi dx
x  x x  x 2  x  x 3 ...
i1 i 2! dx x , y i1 i
2
3! dx x , y i1 i
3
x ,y
i
i i i i i

1 2 1 3
yi1  yi  f (xi , yi )xi1  x i   f ' (xi , i i1  x i  f ' ' (xi , yi )i1x xi  ..

2! 3 .
x you can see the first two terms of the Taylor !
y )As
series
 f xi , yi
yi1  yi are the Euler’s method.
The trueerror
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

Here a2=1/2 is k1h


chosen yi+1,
a  1 Slope  f xi , yi predicted
1 2
p1  
q1 
11 Average Slope 
1
 f ix  h, iy  1k h  f ix i, y
2
1 yi

resulting
in
1 1
yi1  yi   1k 2 k2 x
2 xi
xi+1

h wher
Figure 1 Runge-Kutta 2nd order method
k1 e
 f xi , yi 
(Heun’s method)
k 2  f xi  h, yi 
k1h 16
Midpoint
Method
Here a2  is chosen, giving
1
a1 
0 1
p1  2
1
q11  2
resulting in
yi1  yi  k2h

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
yi1  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.3ex , y0 
dx
5
is rewritten as
dy
 1.3ex  2 y, y0 
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 1012 4  81108 ,0  1200K

Find the temperature at


t  480 seconds using Heun’s method. Assume a step size of
h seconds.
240
d
dt

 2.2067 1012 4  81108
f t,   2.2067 10  12 4

81108 
 i1  i   1 k1  21 k 2h
2 20
Solution
Step 1: i  0, t0  0,0   (0)  1200K

k1  f t0 ,o k2  f t0  h,0 


f  f 0  240,1200  
k1h
0,1200 10
2.2067 12
1200
4
 81108 4.5579240
 f 240,106.09

 4.5579

 2.2067 1012 106.094  81108

1 1 

1    k1  2 k 2 h
0
2  0.017595
1 1
 1200    4.5579 0.017595 
2 2 

240
1200  
2.2702240
 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
 81108
240480,561.87

f 
 2.2067 
1012 561.874 
 81108
 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.29538240
 584.27K 22
Solution
Cont

The exact solution of the ordinary differential equation is


given by the solution of a non-linear equation as

  300
0.92593 ln 1.8519 tan10.0033333   0.22067 103 t  2.9282
  300

The solution to this nonlinear equation at t=480


seconds is
 (480) 
647.57K

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)

Figure [Link]’s method results for different


step sizes
24
Effect of step
size
Table 1. Temperature at 480 seconds as a function of step
size, h
Step size, h (480) Et |єt|%
480 −393.87 1041.4 160.82
240 584.27 63.304 9.7756
120 651.35 −3.7762 0.58313
60 649.91 −2.3406 0.36145
30 648.21 −0.63219 0.097625

 (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

Figure [Link] of step size in Heun’s


method
26
Comparison of Euler and Runge-Kutta
2nd Order Methods
Table 2. Comparison of Euler and the Runge-Kutta
methods
Step size, (480)
h
Euler Heun Midpoint Ralston

480 −987.84 −393.87 1208.4 449.78


240 110.32 584.27 976.87 690.01
120 546.77 651.35 690.20 667.71
60 614.97 649.91 654.85 652.25
30 632.77 648.21 649.02 648.61
 (480)  (exact
647.57K )
27
Comparison of Euler and Runge-Kutta
2nd Order Methods

Table 2. Comparison of Euler and the Runge-Kutta


methods
Step size, t %
h
Euler Heun Midpoint Ralston

480 252.54 160.82 86.612 30.544


240 82.964 9.7756 50.851 6.5537
120 15.566 0.58313 6.5823 3.1092
60 5.0352 0.36145 1.1239 0.72299
30 2.2864 0.097625 0.22353 0.15940

 (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)

Figure 4. Comparison of Euler and Runge Kutta 2nd order


methods with exact results.
29
Runge 4th Order Method

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.3ex , y0 
dx
5
is rewritten as
dy
 1.3ex  2 y, y0 
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 1012 4  81108 ,0  1200K

Find the temperature at


t  480 seconds using Runge-Kutta 4th order method.
Assume a step size of h  seconds.
240
d
dt

 2.2067 1012 4  81108
f t,   2.2067 10  12 4

81108 
i 1  i  1 1k  2k
2 2k3  k4
6 33
h
Solution
Step 1: i  0, t0  0,0   (0) 
1200
k1  f t0 ,o   f 0,1200 2.2067 1012 12004  81108  4.5579
 
1 1 1 1
k 2  f 0t  h,0  k1 h   f  0  240,1200  
 2 2   2 2 

 f 240
4.5579 
120,653.05  2.2067 1012 653.054  81108  
0.38347
1 1 1 1
k3  f  t0  h,0  k2 h  f 0  240,1200   0.38347 
 2 2   2 2 

240 
 f 120,1154.0  2.2067 1012 1154.04  81108  3.8954 
k4  f t0  h,0  k3h  f 0  240,1200   3.984240
 f 240,265.10  2.2067 1012 265.104  81108 
0.0069750 34
Solution
Cont 1
    k  2k  2k  k
1 0 1 2
h 6
3 4
1
 1200   4.5579  2 0.38347  2 3.8954 0.069750
6
240 1
 1200  
6
2.1848240

675.65K
1 is the approximate
temperature at
t  t1  t0  h  0  240 
240

 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 1012 675.65 4  81108  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 1012 622.614  81108 
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 1012 638.004  81108  
0.34775
k4  f t1  h,1  k3h  f 240  240,675.65  
0.34775240
36
 f 480,592.19  2.2067 1012 592.194  81108 
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.25351240
1
 675.65  
6
2.0184 240
 594.91K
 is the approximate
temperature at

t2  t1  h  240  240  480

 480  2  594.91K
37
Solution
Cont

The exact solution of the ordinary differential equation is


given by the solution of a non-linear equation as

  300
0.92593 ln 1.8519 tan1 0.00333  0.22067 103 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)

Figure 1. Comparison of Runge-Kutta 4th order method with


exact solution 39
Effect of step
size
Table 1. Temperature at 480 seconds as a function of step
size, h

Step size,  (480) Et |єt|%


h
480 −90.278 737.85 113.94
240 594.91 52.660 8.1319
120 646.16 1.4122 0.21807
60 647.54 0.033626 0.0051926
30 647.57 0.00086900 0.00013419

 (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

Figure [Link] of step size in Runge-Kutta 4th order


method 41
Comparison of Euler and Runge-Kutta
Methods
140
0

θ(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

You might also like