The Runge-Kutta method

Một phần của tài liệu Ebook Higher engineering mathematics (5th edition) Part 2 (Trang 156 - 162)

The Runge-Kutta method for solving first order dif- ferential equations is widely used and provides a high degree of accuracy. Again, as with the two previous methods, the Runge-Kutta method is a step-by-step process where results are tabulated for a range of values of x. Although several intermediate calculations are needed at each stage, the method is fairly straightforward.

The 7 step procedure for the Runge-Kutta method, without proof, is as follows:

To solve the differential equation dy

dx=f (x, y) given the initial condition y=y0 at x=x0 for a range of values of x=x0(h)xn:

1. Identify x0, y0 and h, and values of x1, x2, x3,. . . .

2. Evaluate k1= f(xn, yn) starting with n=0 3. Evaluate k2= f

xn+h

2, yn+h 2k1

4. Evaluate k3= f

xn+h

2, yn+h 2k2

5. Evaluate k4= f(xn+h, yn+hk3)

6. Use the values determined from steps 2 to 5 to evaluate:

yn+1=yn+ h

6{k1+2k2+2k3+k4} 7. Repeat steps 2 to 6 for n=1, 2, 3,. . .

Thus, step 1 is given, and steps 2 to 5 are intermediate steps leading to step 6. It is usually most convenient to construct a table of values.

The Runge-Kutta method is demonstrated in the following worked problems.

Problem 7. Use the Runge-Kutta method to solve the differential equation:

dy

dx=yx

in the range 0(0.1)0.5, given the initial condi- tions that at x=0, y=2.

Using the above procedure:

1. x0=0, y0=2 and since h=0.1, and the range is from x=0 to x=0.5, then x1=0.1, x2=0.2, x3=0.3, x4=0.4, and x5=0.5

Let n=0 to determine y1: 2. k1= f (x0, y0)=f (0, 2);

since dy

dx=yx, f (0, 2)=2−0=2 3. k2= f

x0+ h

2, y0+h 2k1

= f

0+ 0.1

2 , 2+ 0.1 2 (2)

= f (0.05, 2.1)=2.1−0.05=2.05 4. k3= f

x0+ h

2, y0+h 2k2

= f

0+ 0.1

2 , 2+ 0.1 2 (2.05)

= f (0.05, 2.1025)

=2.1025−0.05=2.0525 5. k4= f (x0+h, y0+hk3)

= f (0+0.1, 2+0.1(2.0525))

= f (0.1, 2.20525)

= 2.20525−0.1=2.10525

470 DIFFERENTIAL EQUATIONS

6. yn+1 = yn+ h

6{k1+2k2+2k3+k4}and when n=0:

y1=y0+ h

6{k1+2k2+2k3+k4}

=2+ 0.1

6 {2+2(2.05)+2(2.0525)

+2.10525}

=2+ 0.1

6 {12.31025} =2.205171

A table of values may be constructed as shown in Table 49.15. The working has been shown for the first two rows.

Let n=1 to determine y2:

2. k1= f (x1, y1)=f (0.1, 2.205171); since dy

dx = yx, f (0.1, 2.205171)

= 2.205171−0.1=2.105171 3. k2= f

x1+ h

2, y1+h 2k1

= f

0.1+0.1

2 , 2.205171+ 0.1

2 (2.105171)

= f (0.15, 2.31042955)

= 2.31042955−0.15=2.160430 4. k3= f

x1+ h

2, y1+h 2k2

= f

0.1+0.1

2 , 2.205171+ 0.1

2 (2.160430)

= f(0.15, 2.3131925)=2.3131925−0.15

= 2.163193

Table 49.15

n xn k1 k2 k3 k4 yn

0 0 2

1 0.1 2.0 2.05 2.0525 2.10525 2.205171

2 0.2 2.105171 2.160430 2.163193 2.221490 2.421403 3 0.3 2.221403 2.282473 2.285527 2.349956 2.649859 4 0.4 2.349859 2.417339 2.420726 2.491932 2.891824 5 0.5 2.491824 2.566415 2.570145 2.648838 3.148720 5. k4 = f (x1+h, y1+hk3)

= f (0.1+0.1, 2.205171+0.1(2.163193))

= f (0.2, 2.421490)

= 2.421490−0.2=2.221490 6. yn+1=yn+h

6{k1+2k2+2k3+k4} and when n=1:

y2=y1+ h

6{k1+2k2+2k3+k4}

=2.205171+0.1

6 {2.105171+2(2.160430) +2(2.163193)+2.221490}

=2.205171+ 0.1

6 {12.973907} =2.421403 This completes the third row of Table 49.15. In a similar manner y3, y4and y5can be calculated and the results are as shown in Table 49.15. Such a table is best produced by using a spreadsheet, such as Microsoft Excel.

This problem is the same as problem 3, page 463 which used Euler’s method, and problem 4, page 465 which used the improved Euler’s method, and a com- parison of results can be made.

The differential equation dy

dx=yx may be solved analytically using the integrating factor method of chapter 48, with the solution:

y=x+1+ex

Substituting values of x of 0, 0.1, 0.2,. . ., 0.5 will give the exact values. A comparison of the results obtained by Euler’s method, the Euler-Cauchy method and the Runga-Kutta method, together with the exact values is shown in Table 49.16 below.

Ch49-H8152.tex 23/6/2006 15: 13 Page 471

NUMERICAL METHODS FOR FIRST ORDER DIFFERENTIAL EQUATIONS 471

I

Table 49.16

Euler’s Euler-Cauchy Runge-Kutta

method method method Exact value

x y y y y=x+1+ex

0 2 2 2 2

0.1 2.2 2.205 2.205171 2.205170918

0.2 2.41 2.421025 2.421403 2.421402758

0.3 2.631 2.649232625 2.649859 2.649858808 0.4 2.8641 2.89090205 2.891824 2.891824698 0.5 3.11051 3.147446765 3.148720 3.148721271

It is seen from Table 49.16 that the Runge-Kutta method is exact, correct to 5 decimal places.

Problem 8. Obtain a numerical solution of the differential equation: dy

dx=3(1+x)−y in the range 1.0(0.2)2.0, using the Runge-Kutta method, given the initial conditions that x=1.0 when y=4.0

Using the above procedure:

1. x0=1.0, y0=4.0 and since h=0.2, and the range is from x=1.0 to x=2.0, then x1=1.2, x2=1.4, x3 =1.6, x4=1.8, and x5=2.0 Let n=0 to determine y1:

2. k1= f (x0, y0)=f (1.0, 4.0); since dy

dx = 3(1+x)−y,

f (1.0, 4.0)= 3(1+1.0)−4.0=2.0 3. k2= f

x0+h

2, y0+ h 2k1

= f

1.0+ 0.2

2 , 4.0+ 0.2 2 (2)

= f (1.1, 4.2)=3(1+1.1)−4.2=2.1

4. k3= f

x0+h

2, y0+ h 2k2

= f

1.0+ 0.2

2 , 4.0+ 0.2 2 (2.1)

= f(1.1, 4.21)

= 3(1+1.1)−4.21=2.09

5. k4= f (x0+h, y0+hk3)

= f (1.0+0.2, 4.1+0.2(2.09))

= f (1.2, 4.418)

= 3(1+1.2)−4.418=2.182 6. yn+1=yn+h

6{k1+2k2+2k3+k4} and when n=0:

y1 =y0+h

6{k1+2k2+2k3+k4}

=4.0+ 0.2

6 {2.0+2(2.1)+2(2.09)+2.182}

=4.0+ 0.2

6 {12.562} =4.418733

A table of values is compiled in Table 49.17. The working has been shown for the first two rows.

Let n=1 to determine y2:

2. k1= f (x1, y1)=f (1.2, 4.418733); since dy

dx = 3(1+x)−y, f (1.2, 4.418733)

= 3(1+1.2)−4.418733=2.181267

3. k2= f

x1+h

2, y1+ h 2k1

= f

1.2+ 0.2

2 , 4.418733+0.2

2 (2.181267)

= f(1.3, 4.636860)

= 3(1+1.3)−4.636860=2.263140

472 DIFFERENTIAL EQUATIONS

Table 49.17

n xn k1 k2 k3 k4 yn

0 1.0 4.0

1 1.2 2.0 2.1 2.09 2.182 4.418733

2 1.4 2.181267 2.263140 2.254953 2.330276 4.870324 3 1.6 2.329676 2.396708 2.390005 2.451675 5.348817 4 1.8 2.451183 2.506065 2.500577 2.551068 5.849335 5 2.0 2.550665 2.595599 2.591105 2.632444 6.367886

4. k3= f

x1+ h

2, y1+h 2k2

= f

1.2+0.2

2 , 4.418733+ 0.2

2 (2.263140)

= f(1.3, 4.645047)=3(1+1.3)−4.645047

= 2.254953

5. k4= f (x1+h, y1+hk3)

= f (1.2+0.2, 4.418733+0.2(2.254953))

= f (1.4, 4.869724)=3(1+1.4)−4.869724

= 2.330276 6. yn+1=yn+h

6{k1+2k2+2k3+k4} and when n=1:

y2=y1+ h

6{k1+2k2+2k3+k4}

=4.418733+0.2

6 {2.181267+2(2.263140) +2(2.254953)+2.330276}

=4.418733+0.2

6 {13.547729} =4.870324 This completes the third row of Table 49.17. In a similar manner y3, y4and y5 can be calculated and the results are as shown in Table 49.17. As in the previous problem such a table is best produced by using a spreadsheet.

This problem is the same as problem 1, page 461 which used Euler’s method, and problem 5, page 467 which used the Euler-Cauchy method, and a compar- ison of results can be made.

The differential equation dy

dx=3(1+x)− y may be solved analytically using the integrating factor method of chapter 48, with the solution:

y=3x+e1x

Substituting values of x of 1.0, 1.2, 1.4,. . ., 2.0 will give the exact values. A comparison of the results obtained by Euler’s method, the Euler-Cauchy method and the Runga-Kutta method, together with the exact values is shown in Table 49.18 on page 473.

It is seen from Table 49.18 that the Runge-Kutta method is exact, correct to 4 decimal places.

The percentage error in the Runge-Kutta method when, say, x=1.6 is:

5.348811636−5.348817 5.348811636

×100%=−0.0001%

From problem 6, page 468, when x=1.6, the per- centage error for the Euler method was 0.688%, and for the Euler-Cauchy method−0.048%. Clearly, the Runge-Kutta method is the most accurate of the three methods.

Now try the following exercise.

Exercise 187 Further problems on the Runge-Kutta method

1. Apply the Runge-Kutta method to solve the differential equation: dy

dx=3−y x for the range 1.0(0.1)1.5, given that the initial con- ditions that x=1 when y=2.

[see Table 49.19]

Ch49-H8152.tex 23/6/2006 15: 13 Page 473

NUMERICAL METHODS FOR FIRST ORDER DIFFERENTIAL EQUATIONS 473

I

Table 49.18

Euler’s Euler-Cauchy Runge-Kutta

method method method Exact value

x y y y y=3x+e1−x

1.0 4 4 4 4

1.2 4.4 4.42 4.418733 4.418730753

1.4 4.84 4.8724 4.870324 4.870320046

1.6 5.312 5.351368 5.348817 5.348811636

1.8 5.8096 5.85212176 5.849335 5.849328964 2.0 6.32768 6.370739847 6.367886 6.367879441 Table 49.19

n xn yn

0 1.0 2.0 1 1.1 2.104545 2 1.2 2.216667 3 1.3 2.334615 4 1.4 2.457143 5 1.5 2.533333

2. Obtain a numerical solution of the differential equation: 1

x dy

dx + 2y=1 using the Runge- Kutta method in the range x=0(0.2)1.0, given the initial conditions that x=0 when

y=1. [see Table 49.20]

Table 49.20

n xn yn

0 0 1.0

1 0.2 0.980395 2 0.4 0.926072 3 0.6 0.848838 4 0.8 0.763649 5 1.0 0.683952

3.(a) The differential equation: dy

dx +1 = −y has the initial conditions that y=1 atx x=2. Produce a numerical solution of the differential equation, correct to 6 decimal places, using the Runge-Kutta method in the range x=2.0(0.1)2.5.

(b) If the solution of the differential equa- tion by an analytical method is given by:

y=4 xx

2 determine the percentage error at x=2.2.

[(a) see Table 49.21 (b) no error]

Table 49.21

n xn yn

0 2.0 1.0 1 2.1 0.854762 2 2.2 0.718182 3 2.3 0.589130 4 2.4 0.466667 5 2.5 0.340000

Differential equations

Assignment 13

This assignment covers the material contained in Chapters 46 to 49.

The marks for each question are shown in brackets at the end of each question.

1. Solve the differential equation: xdy

dx+x2=5 given that y=2.5 when x=1. (4) 2. Determine the equation of the curve which satis-

fies the differential equation 2xydy

dx=x2+1 and which passes through the point (1, 2). (5) 3. A capacitor C is charged by applying a steady voltage E through a resistance R. The p.d.

between the plates, V , is given by the differential equation:

CRdV

dt +V =E

(a) Solve the equation for E given that when time t=0, V=0.

(b) Evaluate voltage V when E=50 V, C=10àF, R=200 kand t=1.2 s. (14) 4. Show that the solution to the differential equa-

tion: 4xdy

dx=x2+y2

y is of the form 3y2=√

x

1−√ x3

given that y=0 when

x=1 (12)

5. Show that the solution to the differential equation x cos xdy

dx +(x sin x+cos x)y=1

is given by: xy= sin x+k cos x where k is a

constant. (11)

6. (a) Use Euler’s method to obtain a numerical solution of the differential equation:

dy dx = y

x +x2−2

given the initial conditions that x=1 when y=3, for the range x=1.0 (0.1) 1.5.

(b) Apply the Euler-Cauchy method to the differ- ential equation given in part (a) over the same range.

(c) Apply the integrating factor method to solve the differential equation in part (a) analytically.

(d) Determine the percentage error, correct to 3 significant figures, in each of the two numerical methods when x=1.2. (30) 7. Use the Runge-Kutta method to solve the differ-

ential equation: dy dx=y

x + x2−2 in the range 1.0(0.1)1.5, given the initial conditions that at x=1, y=3. Work to an accuracy of 6 decimal

places. (24)

Ch50-H8152.tex 19/7/2006 17: 48 Page 475

I

Differential equations

50

Second order differential equations of the form a d 2 y

dx 2 + b dy

dx + cy = 0

Một phần của tài liệu Ebook Higher engineering mathematics (5th edition) Part 2 (Trang 156 - 162)

Tải bản đầy đủ (PDF)

(413 trang)