Runge-Kutta 4th Order Method for Solving

advertisement
Runge 4th Order Method
Mechanical Engineering Majors
Authors: Autar Kaw, Charlie Barker
http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates
3/12/2016
http://numericalmethods.eng.usf.edu
1
Runge-Kutta 4th Order Method
http://numericalmethods.eng.usf.edu
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


k2  f  xi  h, yi  k1h 
2
2


1
1


k3  f  xi  h, yi  k2 h 
2
2


k4  f xi  h, yi  k3h
3
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
4
http://numericalmethods.eng.usf.edu
Example
A solid steel shaft at room temperature of 27°C is needed to be contracted so
that it can be shrunk-fit into a hollow hub. It is placed in a refrigerated chamber
that is maintained at −33°C. The rate of change of temperature of the solid
shaft q is given by
6 4

θ  2.33  10 5 θ 3  1.35  10 3 θ 2 
dθ
 6  3.69  10
θ  33
 5.33  10 
2

dt
  5.42  10 θ  5.588

θ 0  27 C
Find the temperature of the steel shaft after 24 hours. Take a step size of
h=43200 seconds.
6 4

θ  2.33  10 5 θ 3  1.35  10 3 θ 2 
dθ
 6  3.69  10
θ  33
 5.33  10 
2

dt
  5.42  10 θ  5.588

  3.69  10 6 θ 4  2.33  10 5 θ 3  1.35  10 3 θ 2 
θ  33
f t,θ   5.33  10 
2

  5.42  10 θ  5.588

1
q i 1  q i  k1  2k 2  2k3  k 4 h
6
http://numericalmethods.eng.usf.edu
6
5
Step 1: i  0, t0  0, q 0  27C
Solution


  3.69 106 27 4  2.33 105 27 3


6




k1  f t0 ,q 0   f 0, 27    5.33 10
27  33  0.0020893
2

3

2
  1.35 10 27   5.42 10 27   5.588 






1
1
1
1




k2  f  t0  h,q 0  k1h   f  0  43200, 27   0.002089343200   f 21600,18.129
2
2
2
2




4
3
6
5









3
.
69

10

18
.
129

2
.
33

10

18
.
129
 18.129  33  0.00035761
   5.33 10 6 
  1.35 10 3  18.1292  5.42 10 2  18.129  5.588 






1
1
1
1




k3  f  t0  h, q 0  k 2 h   f  0  43200, 27   0.0003576143200   f 21600, 19.276
2
2
2
2




4
3
6
5









3
.
69

10
19
.
276

2
.
33

10
19
.
276
19.276  33  0.0018924
   5.33 10 6 
  1.35 10 3 19.2762  5.42 10  2 19.276  5.588 






6
1


k4  f t0  h, q 0  k3h   f  0  43200, 27   0.0018924 43200   f 43200,54.751
2




  3.69 10 6  54.7514  2.33 10 5  54.7513


6



 54.751  33  0.0035147
  5.33 10
  1.35 10 3  54.7512  5.42 10  2  54.751  5.588 





http://numericalmethods.eng.usf.edu
Solution Cont
1
6
1
 27   0.0020893  2 0.00035761  2 0.0018924    0.0035147 43200
6
1
 27   0.010104 43200
6
 45.749C
q1  q 0  (k1  2k 2  2k3  k 4 )h
q1 is the approximate temperature at
t  t1  t0  h  0  43200  43200s
q 43200  q1  45.749C
7
http://numericalmethods.eng.usf.edu
Solution Cont
Step 2: i  1, t1  43200,q1  45.749
6




 45.7494  2.33 105  45.7493
 6   3.69  10

 45.749  33
k1  f t1 ,q1   f 43200,  45.749   5.33 10
  1.35 10 3  45.7492  5.42 10 2  45.749  5.588 






 0.00084673
1
1
1
1




k2  f  t1  h,q1  k1h   f  43200  43200,  45.749   0.0008467343200   f 64800,64.038
2
2
2
2






  3.69 10 6  64.0384  2.33 10 5  64.0383


6




  5.33 10
 64.038  33  0.010012
2

3

2




  1.35 10  64.038  5.42 10  64.038  5.588 


1
1
1
1




k3  f  t1  h,q1  k 2 h   f  43200  43200,  45.749   0.01001243200   f 64800,262.01
2
2
2
2




6




 262.014  2.33 105  262.013
 6   3.69  10

 22.588  33  21.636
  5.33 10
  1.35 10 3  262.012  5.42 10  2  262.01  5.588 







k 4  f t1  h, q1  k3h   f 43200  43200,  45.749   21.63643200  f 86400,9.3474 105


8









  3.69 10 6  9.3474 105 4  2.33 10 5  9.3474 105 3


6
5

  1.4035 1019


  5.33 10

9
.
3474

10

33


  1.35 10 3  9.3474 105 2  5.42 10  2  9.3474 105  5.588 




http://numericalmethods.eng.usf.edu


Solution Cont
1
k1  2k2  2k3  k4 h
6
1
 45.749   0.00084673  2 0.010012   2 21.636    1.4035 1019 43200
6
1
 45.749   1.4035  1019 43200
6
 1.0105 10 23C
q 2  q1 





q2 is the approximate temperature at
t2  t1  h  43200  43200  86400
q 86400  q 2  1.1015 1023C
9
http://numericalmethods.eng.usf.edu
Solution Cont
The solution to this nonlinear equation at t=86400s is
q (86400)  26.099C
10
http://numericalmethods.eng.usf.edu
Comparison with exact results
Figure 1. Comparison of Runge-Kutta 4th order method with exact solution
11
http://numericalmethods.eng.usf.edu
Effect of step size
Table 1. Value of temperature at 86400 seconds for different
step sizes
Step Size,
86400
43200
21600
10800
5400
h
q 86400
−5.3468×1028
−1.0105×1023
−26.061
−26.094
−26.097
|t | %
Et
−5.2468×1028
−0.034808×1023
−0.038680
−0.0050630
−0.0015763
2.0487×1029
3.8718×1023
0.14820
0.019400
0.0060402
q 86400  26.099C (exact)
12
http://numericalmethods.eng.usf.edu
Effects of step size on RungeKutta 4th Order Method
Figure 2. Effect of step size in Runge-Kutta 4th order method
13
http://numericalmethods.eng.usf.edu
Comparison of Euler and RungeKutta Methods
Figure 3. Comparison of Runge-Kutta methods of 1st, 2nd, and 4th order.
14
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_4th_method.html
THE END
http://numericalmethods.eng.usf.edu
Download