Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Runge 4th Order Method Civil Engineering Majors Authors: Autar Kaw, Charlie Barker http://numericalmethods.eng.usf.edu Transforming Numerical Methods Education for STEM Undergraduates 1/10/2010 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 polluted lake with an initial concentration of a bacteria is 107 parts/m3, while the acceptable level is only 5x106 parts/m3. The concentration of the bacteria will reduce as fresh water enters the lake. The differential equation that governs the concentration C of the pollutant as a function of time (in weeks) is given by dC + 0.06C = 0, C (0) = 107 dt Find the concentration of the pollutant after 7 weeks. Take a step size of 3.5 weeks. dC = −0.06C dt f (t , C ) = −0.06C C i +1 = C i + 5 1 (k1 + 2k 2 + 2k 3 + k 4 )h 6 http://numericalmethods.eng.usf.edu Solution 7 3 Step 1: i = 0, t0 = 0, C0 = 10 parts / m ( ) ( ) k1 = f (t0 , C0 ) = f 0, 107 = −0.06 107 = −600000 1 1 1 1 k 2 = f t0 + h, C0 + k1h = f 0 + 3.5, 10 7 + (− 600000 )3.5 2 2 2 2 = f (1.75, 8950000 ) = −0.06(8950000 ) = −537000 1 1 1 1 k3 = f t0 + h, C0 + k 2 h = f 0 + 3.5, 10 7 + (− 537000 )3.5 2 2 2 2 = f (1.75, 9060300 ) = −0.06(9060300 ) = −543620 ( k 4 = f (t0 + h, C0 + k3 h ) = f 0 + 3.5, 107 + (− 543620 )3.5 = f (1.75, 8097300 ) = −0.06(8097300 ) = −485840 6 ) http://numericalmethods.eng.usf.edu Solution Cont 1 (k1 + 2k2 + 2k3 + k4 ) 6 1 = 107 + (− 600000 + 2(− 537000 ) + 2(− 543620 ) + (− 485840 ))3.5 6 1 7 = 10 + (− 3247100 )3.5 6 = 8.1059 ×106 C1 = C0 + C1 is the approximate concentration of bacteria at t = t1 = t0 + h = 0 + 3.5 = 3.5 weeks C (3.5) ≈ C1 = 8.1059 ×106 parts/m 3 7 http://numericalmethods.eng.usf.edu Solution Cont Step 2: i = 1, t1 = 3.5, C1 = 8.1059 ×106 ( ) ( ) k1 = f (t1 , C1 ) = f 3.5, 8.1059 × 10 6 = −0.06 8.1059 × 106 = −486350 1 1 1 1 k 2 = f t1 + h, C1 + k1h = f 3.5 + (3.5), 8105900 + (− 486350 )3.5 2 2 2 2 = f (5.25, 7254800 ) = −0.06(7254800 ) = −435290 1 1 1 1 ( ) , 3 . 5 3 . 5 , 8105900 + (− 435290 )3.5 k3 = f t1 + h C1 + k 2 h = f + 2 2 2 2 = f (5.25, 7344100 ) = −0.06(7344100 ) = −440648 k 4 = f (t1 + h, C1 + k3 h ) = f (3.5 + 3.5, 8105900 + (− 440648)3.5) = f (7, 6563600 ) = −0.06(6563600 ) = −393820 8 http://numericalmethods.eng.usf.edu Solution Cont 1 C2 = C1 + (k1 + 2k 2 + 2k3 + k 4 )h 6 1 = 8105900 + (− 484350 + 2(− 435290 ) + 2(− 440648) + (− 39820 ))3.5 6 1 = 8105900 + (− 2632000 )3.5 6 = 6.5705 × 106 parts/m 3 C 2 is the approximate concentration of bacteria at t 2 = t1 + h = 3.5 + 3.5 = 7 weeks C (7 ) ≈ C2 = 6.5705 ×106 parts/m 3 9 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 C (t ) = 1×107 e −3t 50 The solution to this nonlinear equation at t=7 weeks is C (7) = 6.5705 ×106 parts/m 3 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 concentration of bacteria at 3 minutes for different step sizes Step size h 7 3.5 1.75 0.875 0.4375 C (7 ) 6.5715 6.5705 6.5705 6.5705 6.5705 |∈t | % Et 106 106 106 106 106 −1017.2 −53.301 −3.0512 −0.18252 −0.011161 0.015481 8.1121 10−4 4.6438 10−5 2.7779 10−6 1.6986 10−7 C (7) = 6.5705 × 10 6 (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