Runge-Kutta 2nd Order Method for Solving Ordinary

Download Report

Transcript Runge-Kutta 2nd Order Method for Solving Ordinary

Runge 2nd Order Method
Major: All Engineering Majors
Authors: Autar Kaw, Charlie Barker
http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates
7/17/2015
http://numericalmethods.eng.usf.edu
1
Runge-Kutta 2nd Order Method
http://numericalmethods.eng.usf.edu
Runge-Kutta 2nd Order Method
For
dy
 f ( x, y ), y (0)  y0
dx
Runge Kutta 2nd order method is given by
yi 1  yi  a1k1  a2 k2 h
where
k1  f xi , yi 
k2  f xi  p1h, yi  q11k1h
3
http://numericalmethods.eng.usf.edu
Heun’s Method
Heun’s method
Slope f xi  h, yi  k1h 
y
Here a2=1/2 is chosen
1
a1 
2
yi+1, predicted
Slope f xi , yi 
p1  1
q11  1
resulting in
1 
1
yi 1  yi   k1  k2 h
2 
2
where
k1  f xi , yi 
Average Slope 
yi
xi
1
 f xi  h, yi  k1h   f xi , yi 
2
xi+1
x
Figure 1 Runge-Kutta 2nd order method (Heun’s method)
k 2  f xi  h, yi  k1h
4
http://numericalmethods.eng.usf.edu
Midpoint Method
Here a2  1 is chosen, giving
a1  0
p1 
1
2
q11 
1
2
resulting in
yi 1  yi  k2h
where
k1  f xi , yi 
1
1


k 2  f  xi  h, yi  k1h 
2
2


5
http://numericalmethods.eng.usf.edu
Ralston’s Method
Here a 2  2 is chosen, giving
3
1
3
3
p1 
4
3
q11 
4
resulting in
a1 
2 
1
yi 1  yi   k1  k2 h
3 
3
where
k1  f xi , yi 
3
3


k 2  f  xi  h, yi  k1h 
4
4


6
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
7
http://numericalmethods.eng.usf.edu
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  10 8 , 0  1200 K
dt

Find the temperature at

t  480 seconds using Heun’s method. Assume a step size of
h  240 seconds.
d
 2.2067  10 12  4  81  10 8
dt



f t,   2.20671012 4  81108
1
2
1
2



i 1  i   k1  k 2 h
8
http://numericalmethods.eng.usf.edu
Solution
i  0, t0  0,0   (0)  1200K
Step 1:
k1  f t0 , o 
 f 0,1200
k 2  f t0  h, 0  k1h 

 2.20671012 12004  81108
 4.5579
1
2
1
2

 f 0  240,1200  4.5579240
 f 240,106.09

 2.20671012 106.094  81108
 0.017595



1   0   k1  k2 h
1
1

 1200   4.5579  0.017595240
2
2

 1200  2.2702240
 655.16K
9
http://numericalmethods.eng.usf.edu
Solution Cont
Step 2: i  1, t1  t0  h  0  240  240,1  655.16K
k 2 f t1  h,1  k1h 
k1  f t1 ,1 
 f 240,655.16
 f 240 240,655.16   0.38869240

 2.20671012 655.164  81108
 0.38869
1
2
1
2

 f 480,561.87

 2.20671012 561.874  81108
 0.20206



 2  1   k1  k 2 h
1
1

 655.16    0.38869   0.20206240
2
2

 655.16   0.29538240
 584.27K
10
http://numericalmethods.eng.usf.edu
Solution Cont
The exact solution of the ordinary differential equation is given by the
solution of a non-linear equation as
0.92593 ln
  300
 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
11
http://numericalmethods.eng.usf.edu
Comparison with exact results
Temperature, θ(K)
1200
h=120
Exact
800
h=240
400
h=480
0
0
100
200
300
400
500
-400
Time, t(sec)
Figure 2. Heun’s method results for different step sizes
12
http://numericalmethods.eng.usf.edu
Effect of step size
Table 1. Temperature at 480 seconds as a function of step size, h
Step size, h
(480)
Et
|єt|%
480
240
120
60
30
−393.87
584.27
651.35
649.91
648.21
1041.4
63.304
−3.7762
−2.3406
−0.63219
160.82
9.7756
0.58313
0.36145
0.097625
 (480)  647.57K
13
(exact)
http://numericalmethods.eng.usf.edu
Effects of step size on Heun’s
Method
Temperature, θ(480)
800
600
400
200
0
0
-200
100
200
300
Step size, h
400
500
-400
Figure 3. Effect of step size in Heun’s method
14
http://numericalmethods.eng.usf.edu
Comparison of Euler and RungeKutta 2nd Order Methods
Table 2. Comparison of Euler and the Runge-Kutta methods
Step size,
h
480
240
120
60
30
(480)
Euler
Heun
Midpoint
Ralston
−987.84
110.32
546.77
614.97
632.77
−393.87
584.27
651.35
649.91
648.21
1208.4
976.87
690.20
654.85
649.02
449.78
690.01
667.71
652.25
648.61
 (480)  647.57K
15
(exact)
http://numericalmethods.eng.usf.edu
Comparison of Euler and RungeKutta 2nd Order Methods
Table 2. Comparison of Euler and the Runge-Kutta methods
Step size,
h
480
240
120
60
30
t %
Euler
Heun
252.54
82.964
15.566
5.0352
2.2864
160.82
9.7756
0.58313
0.36145
0.097625
Midpoint Ralston
86.612
50.851
6.5823
1.1239
0.22353
30.544
6.5537
3.1092
0.72299
0.15940
 (480)  647.57K (exact)
16
http://numericalmethods.eng.usf.edu
Comparison of Euler and RungeKutta 2nd Order Methods
1200
Temperature, θ(K)
1100
Midpoint
1000
900
Ralston
800
Heun
700
Analytical
600
Euler
500
0
100
200
300
400
500
600
Time, t (sec)
Figure 4. Comparison of Euler and Runge Kutta 2nd order methods with
exact results.
17
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/runge_kutt
a_2nd_method.html
THE END
http://numericalmethods.eng.usf.edu