Вы находитесь на странице: 1из 10

3

Runge-Kutta Methods

In contrast to the multistep methods of the previous section, Runge-Kutta methods are single-step methods however, with multiple stages per step. They are motivated by the dependence of the Taylor methods on the specic IVP. These new methods do not require derivatives of the right-hand side function f in the code, and are therefore general-purpose initial value problem solvers. Runge-Kutta methods are among the most popular ODE solvers. They were rst studied by Carle Runge and Martin Kutta around 1900. Modern developments are mostly due to John Butcher in the 1960s.

3.1

Second-Order Runge-Kutta Methods

As always we consider the general rst-order ODE system y (t) = f (t, y(t)). (42)

Since we want to construct a second-order method, we start with the Taylor expansion y(t + h) = y(t) + hy (t) + h2 y (t) + O(h3 ). 2

The rst derivative can be replaced by the right-hand side of the dierential equation (42), and the second derivative is obtained by dierentiating (42), i.e., y (t) = f t (t, y) + f y (t, y)y (t) = f t (t, y) + f y (t, y)f (t, y), with Jacobian f y . We will from now on neglect the dependence of y on t when it appears as an argument to f . Therefore, the Taylor expansion becomes y(t + h) = y(t) + hf (t, y) + h2 [f t (t, y) + f y (t, y)f (t, y)] + O(h3 ) 2 h h = y(t) + f (t, y) + [f (t, y) + hf t (t, y) + hf y (t, y)f (t, y)] + O(h3(43) ). 2 2

Recalling the multivariate Taylor expansion f (t + h, y + k) = f (t, y) + hf t (t, y) + f y (t, y)k + . . . we see that the expression in brackets in (43) can be interpreted as f (t + h, y + hf (t, y)) = f (t, y) + hf t (t, y) + hf y (t, y)f (t, y) + O(h2 ). Therefore, we get y(t + h) = y(t) + or the numerical method y n+1 = y n + h 56 1 1 k1 + k2 , 2 2 (44) h h f (t, y) + f (t + h, y + hf (t, y)) + O(h3 ) 2 2

with k1 = f (tn , y n ), k2 = f (tn + h, y n + hk1 ). This is the classical second-order Runge-Kutta method. It is also known as Heuns method or the improved Euler method. Remark 1. The k1 and k2 are known as stages of the Runge-Kutta method. They correspond to dierent estimates for the slope of the solution. Note that y n + hk1 corresponds to an Euler step with stepsize h starting from (tn , y n ). Therefore, k2 corresponds to the slope of the solution one would get by taking one Euler step with stepsize h starting from (tn , y n ). The numerical method (44) now consists of a single step with the average of the slopes k1 and k2 . 2. The notation used here diers slightly from that used in the Iserles book. There the stages are dened dierently. I nd the interpretation in terms of slopes more intuitive. 3. We also saw earlier that the classical second-order Runge-Kutta method can be interpreted as a predictor-corrector method where Eulers method is used as the predictor for the (implicit) trapezoidal rule.

Chapter 08.04 Runge-Kutta 4th Order Method for Ordinary Differential Equations

After reading this chapter, you should be able to 1. develop Runge-Kutta 4th order method for solving ordinary differential equations, 2. find the effect size of step size has on the solution, 3. know the formulas for other versions of the Runge-Kutta 4th order method What is the Runge-Kutta 4th order method? Runge-Kutta 4th order method is a numerical technique used to solve ordinary differential equation of the form dy = f (x, y ), y (0) = y 0 dx So only first order ordinary differential equations can be solved by using the Runge-Kutta 4th order method. In other sections, we have discussed how Euler and Runge-Kutta methods are used to solve higher order ordinary differential equations or coupled (simultaneous) differential equations. How does one write a first order differential equation in the above form? Example 1 Rewrite dy + 2 y = 1.3e x , y (0 ) = 5 dx in dy = f ( x, y ), y (0) = y 0 dx form. Solution

08.04.1

08.04.2 dy + 2 y = 1.3e x , y (0 ) = 5 dx dy = 1.3e x 2 y, y (0 ) = 5 dx In this case f (x, y ) = 1.3e x 2 y Example 2 Rewrite ey in dy = f ( x, y ), y (0) = y 0 dx form. Solution dy + x 2 y 2 = 2 sin(3 x), y (0 ) = 5 dx dy 2 sin(3 x) x 2 y 2 = , y (0 ) = 5 dx ey In this case 2 sin(3 x) x 2 y 2 f (x, y ) = ey The Runge-Kutta 4th order method is based on the following yi +1 = yi + (a1k1 + a2 k 2 + a3 k 3 + a4 k 4 )h ey dy + x 2 y 2 = 2 sin(3 x), y (0 ) = 5 dx

Chapter 08.04

(1)

where knowing the value of y = y i at xi , we can find the value of y = yi +1 at xi +1 , and h = xi +1 xi Equation (1) is equated to the first five terms of Taylor series 2 3 3 dy (xi +1 xi )+ 1 d y xi , yi (xi +1 xi )2 + 1 d y xi , yi (xi +1 xi ) yi +1 = yi + xi , yi 2 3 dx 2! dx 3! dx 4 1d y (xi +1 xi )4 + 4 xi , yi 4! dx dy xi +1 xi = h = f (x, y ) Knowing that dx and 1 1 1 y i +1 = y i + f (xi , y i )h + f ' (xi , y i )h 2 + f '' (xi , y i )h 3 + f ''' (xi , y i )h 4 2! 3! 4! Based on equating Equation (2) and Equation (3), one of the popular solutions used is 1 y i +1 = y i + (k1 + 2k 2 + 2k 3 + k 4 )h 6

(2)

(3)

(4)

Runge-Kutta 4th Order Method k1 = f (xi , y i ) 1 1 k2 = f xi + h, yi + k1h 2 2 1 1 k 3 = f xi + h, y i + k 2 h 2 2 k 4 = f (xi + h, y i + k 3 h )

08.04.3

(5a) (5b) (5c) (5d)

Example 3 A ball at 1200 K is allowed to cool down in air at an ambient temperature of 300 K. 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 81108 , (0 ) = 1200 K dt where is in K and t in seconds. Find the temperature at t = 480 seconds using Runge-

Kutta 4th order method. Assume a step size of h = 240 seconds. Solution d = 2.2067 10 12 4 81 10 8 dt f (t , ) = 2.2067 10 12 4 81 10 8 1 i +1 = i + (k1 + 2k 2 + 2k 3 + k 4 )h 6 i = 0 t 0 = 0 0 = 1200K For , ,

k1 = f (t0 , 0 ) = f (0,1200 ) = 2.2067 10 12 1200 4 81 10 8 = 4.5579 1 1 k 2 = f t0 + h, 0 + k1h 2 2 1 1 = f 0 + (240 ),1200 + ( 4.5579 ) 240 2 2 = f ( ,653.05) 120 = 2.2067 10 12 653.05 4 81 10 8 = 0.38347 1 1 k 3 = f t 0 + h, 0 + k 2 h 2 2

08.04.4 1 1 = f 0 + (240 ),1200 + ( 0.38347 ) 240 2 2 = f ( ,1154.0 ) 120 = 2.2067 10 12 1154.0 4 81108 = 3.8954 k 4 = f (t0 + h, 0 + k3 h ) = f (0 + 240,1200 + ( 3.894 ) 240 ) = f (240,265.10) = 2.2067 10 12 265.10 4 81108 = 0.0069750 1 1 = 0 + ( k1 + 2 k 2 + 2 k 3 + k 4 ) h 6 1 = 1200 + ( 4.5579 + 2( 0.38347 )+ 2( 3.8954 )+ (0.069750 ))240 6 = 1200 + ( 2.1848) 240 = 675.65 K

Chapter 08.04

1 is the approximate temperature at t = t1 = t0 + h


= 0 + 240 = 240 1 = (240 ) 675.65 K

For i = 1, t1 = 240, 1 = 675.65 K k1 = f (t1 , 1 ) = f (240,675.65) = 2.2067 10 12 675.65 4 81 10 8 = 0.44199

1 1 k 2 = f t1 + h, 1 + k1h 2 2 1 1 = f 240 + (240),675.65 + ( 0.44199)240 2 2 = f (360,622.61) = 2.2067 1012 622.614 81 108 = 0.31372

Runge-Kutta 4th Order Method 1 1 k3 = f t1 + h, 1 + k 2 h 2 2 1 1 = f 240 + (240 ),675.65 + ( 0.31372 ) 240 2 2 (360,638.00) = f = 2.2067 10 12 638.00 4 81 10 8 = 0.34775 k 4 = f (t1 + h, 1 + k3 h )

08.04.5

= f (240 + 240,675.65 + ( 0.34775) 240) = f (480,592.19) = 0.25351 = 2.2067 10 12 592.19 4 81 10 8

1 2 = 1 + ( k1 + 2 k 2 + 2 k 3 + k 4 ) h 6 1 = 675.65 + ( 0.44199 + 2( 0.31372 )+ 2( 0.34775)+ ( 0.25351)) 240 6 1 = 675.65 + ( 2.0184 ) 240 6 = 594.91 K

2 is the approximate temperature at t = t2 = t1 + h


= 240 + 240 = 480

2 = (480) 594.91 K Figure 1 compares the exact solution with the numerical solution using the Runge-Kutta 4th order method with different step sizes.

08.04.6

Chapter 08.04

1600
Temperature, (K)

1200 h=120 800 400 0 0 -400


Time,t(sec)

Exact h=240

h=480 200 400 600

Figure 1 Comparison of Runge-Kutta 4th order method with exact solution for different step sizes. Table 1 and Figure 2 show the effect of step size on the value of the calculated temperature at t = 480 seconds. Table 1 Value of temperature at time, t = 480 s for different step sizes Step size, h 480 240 120 60 30

(480) 90.278 594.91 646.16 647.54 647.57

Et 737.85 52.660 1.4122 0.033626 0.00086900

| t | % 113.94 8.1319 0.21807 0.0051926 0.00013419

Runge-Kutta 4th Order Method

08.04.7

800
Temperature, (480)

600 400 200 0 0 -200


Step size, h

100

200

300

400

500

Figure 2 Effect of step size in Runge-Kutta 4th order method. In Figure 3, we are comparing the exact results with Eulers method (Runge-Kutta 1st order method), Heuns method (Runge-Kutta 2nd order method), and Runge-Kutta 4th order method. The formula described in this chapter was developed by Runge. This formula is same as x Simpsons 1/3 rule, if f (x, y ) were only a function of . There are other versions of the 4th order method just like there are several versions of the second order methods. The formula developed by Kutta is 1 y i +1 = y i + (k1 + 3k 2 + 3k 3 + k 4 )h 8 (6) where k1 = f (xi , y i ) (7a) 1 1 k 2 = f xi + h, yi + hk1 3 3 (7b) 2 1 k 3 = f xi + h, yi hk1 + hk 2 3 3 (7c) (7d) x .

k 4 = f (xi + h, y i + hk1 hk 2 + hk 3 ) This formula is the same as the Simpsons 3/8 rule, if f (x, y ) is only a function of

08.04.8

Chapter 08.04

1400

(K)

1200 1000 800 600 400 200 0

4th order Exact Heun Euler

Temperature,

100

200

300

400

500

Time, t(sec)

Figure 3 Comparison of Runge-Kutta methods of 1st (Euler), 2nd, and 4th order. ORDINARY DIFFERENTIAL EQUATIONS Topic Runge-Kutta 4th order method Summary Textbook notes on the Runge-Kutta 4th order method for solving ordinary differential equations. Major General Engineering Authors Autar Kaw Last Revised October 13, 2010 Web Site http://numericalmethods.eng.usf.edu

Вам также может понравиться