7
Module1: Numerical Solution of Ordinary Differential Equations Lecture 5 Fourth Order Runge Kutta Methods Keywords: fourth order methods, Taylor series, convergence, stability

Lecture 5

Embed Size (px)

Citation preview

Module1: Numerical Solution of Ordinary Differential Equations

Lecture 5

Fourth Order Runge Kutta Methods

Keywords: fourth order methods, Taylor series, convergence, stability

Fourth Order Runge-Kutta Methods (RK4)

All the fourth order Runge Kutta Methods are of the following general form:

( , , )

( , )

( , )

( , )

( , )

k 1 k k k

1 1 2 2 3 3 4 4

1 k k

2 k 1 k 21 1

3 k 2 k 31 1 32 2

4 k 3 k 41 1 42 2 43 3

y y h t y h

w K w K w K w K

K f t y

K f t p h y a K

K f t p h y a K a K

K f t p h y a K a K a K

(1.16)

The thirteen unknowns in the method have to be obtained. The Taylor series expansion

of the solution and Ki, i=1,2,3,4 are obtained and substituted in the first equation of

(1.16). For Fourth order Runge Kutta Method, comparing terms up to h4 on the two

sides gives the following 11 equations:

; ;

/

/

( ) /

/

( ) /

( ) /

1 21 2 31 32 3 41 42 43

1 2 3 4

1 2 2 3 3 4

2 2 21 2 2 3 3 4

1 32 2 1 42 2 43 4

3 3 31 2 2 3 3 4

2 232 1 3 1 42 2 43 4

232 1 2 3 3 1 42 2 43 4

1 32

p a p a a p a a a

w w w w 1

p w p w p w 1 2

p w p w p w 1 3

p a w p a p a w 1 6

p w p w p w 1 4

a p w p a p a w 1 12

a p p w p p a p a w 1 8

p a a /43 4w 1 24

Assuming two additional constraints 1 2 2 3p p and w w gives

, ,

,

,

1 2 3 2 3

1 4 21 32

31 41 42 43

1 1p p p 1 w w

2 31 1

w w a a6 2

a a a 0 a 1

Accordingly the classical fourth order Runge-Kutta method is obtained as

[ ]

( , )

( , )

( , )

( , )

k 1 k 1 2 3 4

1 k k

2 k k 1

3 k k 2

4 k k 3

hy y K 2K 2K K

6K f t y

h hK f t y K

2 2h h

K f t y K2 2

K f t h y hK

(1.16)

It may be observed that RK4 uses four functional evaluations in the interval [ t0, t1].

These points are shown as p0, p1, p2 and p3 in the following figure

Fig1.4 Schematic Diagram for RK4 Method

Example 1.6: find the solution of IVP using classical fourth order Runge-Kutta method

with h=1

; ( )dy 1 y

y 1 0dt 2 t

Solution: The solution of IVP by RK4 classical method is shown in the following table:

h  k  tk  yk  k1  k2  k3  k4  yk+1  exact sol  Abs error 

1  0  1  0  0.5  0.66667 0.72222 0.861111 0.689815 0.693147  0.00333

1  1  2  0.68981  0.84491  0.94491 0.96491 1.051574 1.6425  1.647918  0.00542

1  2  3  1.6425  1.0475  1.11893 1.12913 1.192908 2.765255 2.772589  0.00733

1  3  4  2.76526  1.19131  1.24687 1.25304 1.303659 4.014388 4.023595  0.00921

1  4  5  4.01439  1.30288  1.34833 1.35246 1.394475 5.364212 5.375278  0.01107

1  5  6  5.36421  1.39404  1.4325  1.43546 1.471381 6.797766 6.810686  0.01292

1  6  7  6.79777  1.47111  1.50444 1.50666 1.538054 8.302995 8.317766  0.01477

1  7  8  8.303  1.53787  1.56729 1.56902 1.59689  9.87089  9.887511  0.01662

1  8  9  9.87089  1.59677  1.62308 1.62447 1.649536 11.49446 11.51293  0.01847

1  9  10  11.4945  1.64945  1.67326 1.67439 1.697168 13.16811 13.18842  0.02032

1  10  11  13.1681  1.6971  1.71884 1.71978 1.740658 14.88727 14.90944  0.02217

Table 1.4: Solution by Classical RK4 for example 1.6

[Reference R4_CLASSICAL.xlsx/sheet1]

Various entries of the table in a row are computed by the RK4 classical formula (1.16).

For computations in the table the user is referred to the excel sheet

R4_CLASSICAL.xlsx/sheet1

The solutions are compared with the exact solution and the absolute error is given in the

last column.

The other RK4 formulae are obtained as

[ ]

( , )

( , )

( , )

( , )

k 1 k 1 2 3 4

1 k k

2 k k 1

3 k k 1 2

4 k k 1 2 3

hy y K 3K 3K K

8K f t y

h hK f t y K

3 32h h

K f t y K hK3 3

K f t h y hK hK hK

(1.17)

and

[ ( ) ( ) ]

( , )

( , )

( , ( ) ( ) )

( , ( ) )

k 1 k 1 2 3 4

1 k k

2 k k 1

3 k k 1 2

4 k k 2 3

h 1 1y y K 2 1 K 2 1 K K

6 2 2K f t y

h hK f t y K

2 2h 1 1 1

K f t y hK 1 hK2 2 2 2

1 1K f t h y hK 1 hK

2 2

(1.18)

Example 1.7: find the solution of IVP using classical fourth order Runge-Kutta method

given in (1.17) with h=1

; ( )dy 1 y

y 1 0dt 2 t

Solution: In the following table the computation are shown to solve the IVP using (1.17).

Although both the methods are of same order but (1.17) gives more accurate result as

compared to classical method (1.16)

h  k  tk  yk  k1  k2  k3  k4  yk+1  exact sol Abs error 

1  0  1  0  0.5  0.625 0.775 0.825 0.690625 0.693147  0.00252

1  1  2  0.69063  0.84531  0.91674 0.9971 1.038765 1.643824 1.647918  0.00409

1  2  3  1.64382  1.04794  1.09794 1.15249 1.186578 2.76705 2.772589  0.00554

1  3  4  2.76705  1.19176  1.23022 1.27143 1.300004 4.016642 4.023595  0.00695

1  4  5  4.01664  1.30333  1.33458 1.36767 1.392176 5.366922 5.375278  0.00836

1  5  6  5.36692  1.39449  1.4208 1.44843 1.469863 6.80093 6.810686  0.00976

1  6  7  6.80093  1.47156  1.49429 1.518 1.537026 8.306613 8.317766  0.01115

1  7  8  8.30661  1.53833  1.55833 1.5791 1.59619 9.874961 9.887511  0.01255

1  8  9  9.87496  1.59722  1.61508 1.63355 1.649065 11.49898 11.51293  0.01395

1  9  10  11.499  1.6499  1.66603 1.68266 1.696865 13.17308 13.18842  0.01534

1  10  11  13.1731  1.69755  1.71226 1.72738 1.74048 14.8927 14.90944  0.01674

Table 1.5 Solution By Classical RK4 for example 1.7

[Reference R4_CLASSICAL.xlsx/sheet2]

Let Tk+1(h) be the local truncation error at the( k+1)th step of the one step method with

step size h, assuming that no error was made in the previous step. It is obtained as

( ) ( , , ) k 1 k 1 k k kT h y y h t y h

The method is said to be consistent if

k 1

h 0

T (h)lim 0

h

It is now easy to verify that the Euler, Modified Euler and Runge-Kutta methods are

consistent

It is now easy to verify that the Eulers, Modified Eulers and Runge Kutta methods are

consistent.

A one step method is convergent when the difference between the exact solution and

the solution of difference equation at kth step satisfies the condition

k kh 0 1 k Nlim max y(t ) y 0

Using the bound for Tk=y(tk)-yk proves the convergence of Euler method.

Stability of a numerical method ensures that small changes in the initial conditions

should not lead to large changes in the solution. This is particularly important as the

initial conditions may not be given exactly. The approximate solution computed with

errors in initial condition is further used as the initial condition for computing solution at

the next grid point. This accounts for large deviation in the solution started with small

initial errors. Also round off errors in computations may also affect the accuracy of the

solution at a grid point. Euler method is found to be stable.

According to Lax equivalence theorem Given a properly posed initial value problem and

a finite-difference approximation to it that satisfies the consistency condition, stability is

the necessary and sufficient condition for convergence.