Runge-Kutta 4th Order Method for Solving Ordinary

Download Report

Transcript Runge-Kutta 4th Order Method for Solving Ordinary

Runge 4th Order Method
Industrial 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 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  k2h 
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
The open loop response, that is, the speed of the motor to a
voltage input of 20 V, assuming a system without damping is
20  0.02 
dw
 0.06 w
dt
If the initial speed is zero w0  0 , and using the RungeKutta 4th order method, what is the speed at t = 0.8 s?
Assume a step size of h = 0.4 s.
dw
 1000  3w
dt
f t , w  1000 3w
wi 1  wi 
5
1
k1  2k2  2k3  k4 h
6
http://numericalmethods.eng.usf.edu
Solution
Step 1: For i  0, t0  0 w0  0
k1  f t0 , w0   f 0, 0  1000 30  1000
1
1
1
1




k2  f  t0  h, w0  k1h   f  0  0.4, 0  10000.4   f 0.2, 200  1000 3200  400
2
2
2
2




1
1
1
1




k3  f  t0  h, w0  k2 h   f  0  0.4, 0  4000.4   f 0.2, 80  1000 380  760
2
2
2
2




k4  f t0  h, w0  k3h  f 0  0.4, 0  7600.4  f 0.4, 304  1000 3304  88
6
http://numericalmethods.eng.usf.edu
Solution Cont
1
w1  w0  (k1  2k 2  2k3  k 4 )h
6
1
 0  1000 2400  2760  880.4
6
1
 0  34080.4
6
 227.2 rad/s
w1 is the approximate speed of the motor at
t  t1  t0  h  0  0.4  0.4 s
w0.4  w1  227.2 rad/s
7
http://numericalmethods.eng.usf.edu
Solution Cont
Step 2:
i  1, t1  0.8, w1  227.2
k1  f t1 , w1   f 0.4, 227.2  1000 3227.2  318.4
1
1
1
1




k2  f  t1  h, w1  k1h   f  0.4  0.4, 227.2  318.40.4 
2
2
2
2




 f 0.6, 290.88  1000 3290.88  127.36
1
1
1
1




k3  f  t1  h, w1  k2 h   f  0.4  0.4, 227.2  127.360.4 
2
2
2
2




 f 0.6, 252.67  1000 3252.67  241.98
k4  f t1  h, w1  k3h  f 0.4  0.4, 227.2  241.980.4
 f 0.8, 323.99  1000 3323.99  28.019
8
http://numericalmethods.eng.usf.edu
Solution Cont
1
w2  w1  (k1  2k 2  2k3  k 4 )h
6
1
 227.2  318.4  2127.36  2241.98  28.0190.4
6
1
 227.2  1085.10.4
6
 299.54 rad/s
w2 is the approximate speed of the motor at
t  t2  t1  h  0.4  0.4  0.8 s
w0.8  w2  299.54 rad/s
9
http://numericalmethods.eng.usf.edu
Solution Cont
The exact solution of the ordinary differential equation is
given by
 1000  1000 3t
w(t )  

e
 3   3 
The solution to this nonlinear equation at t=0.8 seconds is
w0.8  303.09 rad/s
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 Values of speed of the motor at 0.8 seconds for different step sizes
Step size, h
0.8
0.4
0.2
0.1
0.05
w0.8
147.20
155.89
51.434
299.54
3.5535
1.1724
302.96
0.12988
0.042852
303.09 0.0062962 0.0020773
303.09 0.00034702 0.00011449
w0.8  303.09
12
|t | %
Et
(exact)
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