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

310 CHAPTER 8: Numerical Solution of Ordinary Differential Equations

It can be verified that the estimate for e4 agrees with the actual error in the
value of y(0.04) obtained in Example 8.5.

8.4.2 Modified Euler’s Method


Instead of approximating f ( x, y ) by f ( x0 , y0 ) in Eq. (8.6), we now
approximate the integral given in Eq. (8.6) by means of trapezoidal rule to
obtain
h
y1 = y0 + [ f ( x0 , y0 ) + f ( x1 , y1 )] (8.13)
2
We thus obtain the iteration formula
h
y 1( n +1) = y0 + [ f ( x0 , y0 ) + f ( x1 , y 1( n ) )], n = 0, 1, 2, … (8.14)
2
where y 1( n ) is the nth approximation to y1. The iteration formula (8.14) can
be started by choosing y 1(0) from Euler’s formula:
y 1(0) = y0 + hf ( x0 , y0 ).

Example 8.7 Determine the value of y when x = 0.1 given that


y (0) = 1 and y′ = x 2 + y
We take h = 0.05. With x0 = 0 and y0 =1.0, we have f ( x0 , y0 ) = 1.0. Hence
Euler’s formula gives
y 1(0) = 1 + 0.05(1) = 1.05

Further, x1 = 0.05 and f ( x1 , y 1(0) ) = 1.0525. The average of f ( x0 , y0 ) and


f ( x1 , y 1(0) ) is 1.0262. The value of y 1(1) can therefore be computed by using
Eq. (8.14) and we obtain
y 1(1) = 1.0513.
Repeating the procedure, we obtain y 1(2) =1.0513. Hence we take y1 = 1.0513,
which is correct to four decimal places.
Next, with x1 = 0.05, y1 = 1.0513 and h = 0.05, we continue the procedure
to obtain y2, i.e., the value of y when x = 0.1. The results are
y 2(0) = 1.1040, y 2(1) = 1.1055, y 2(2) = 1.1055.

Hence we conclude that the value of y when x = 0.1 is 1.1055.

8.5 RUNGE–KUTTA METHODS

As already mentioned, Euler’s method is less efficient in practical problems


since it requires h to be small for obtaining reasonable accuracy. The
SECTION 8.5: Runge–Kutta Method 311

Runge–Kutta methods are designed to give greater accuracy and they possess
the advantage of requiring only the function values at some selected points
on the subinterval.
If we substitute y1 = y0 + hf ( x0 , y0 ) on the right side of Eq. (8.13), we
obtain
h
y1 = y0 + [ f 0 + f ( x0 + h, y0 + hf 0 )],
2
where f 0 = f ( x0 , y0 ). If we now set
k1 = hf 0 and k 2 = hf ( x0 + h, y0 + k1 )
then the above equation becomes
1
y1 = y0 + (k1 + k2 ), (8.15)
2
which is the second-order Runge–Kutta formula. The error in this formula
can be shown to be of order h3 by expanding both sides by Taylor’s series.
Thus, the left side gives
h2 h3
y0 hy0b y0bb y0bbb "
2 6
and on the right side
⎡ ∂f ∂f ⎤
k2 = hf ( x0 + h, y0 + hf 0 ) = h ⎢ f 0 + h + hf 0 + O (h 2 ) ⎥ .
⎣ ∂x0 ∂y0 ⎦
Since
df ( x, y ) ∂f ∂f
= +f ,
dx ∂x ∂y
we obtain
k2 = h [ f 0 + hf 0′ + O (h 2 )] = hf 0 + h 2 f 0′ + O (h3 ),

so that the right side of Eq. (8.15) gives


1 1
y0 + [hf0 + hf0 + h2 f0′ + O (h3 )] = y0 + hf 0 + h2 f0′ + O (h3 )
2 2

h2
= y0 + hy0′ + y0′′ + O ( h3 ).
2
It therefore follows that the Taylor series expansions of both sides of Eq. (8.15)
agree up to terms of order h2, which means that the error in this formula
is of order h3.
More generally, if we set
y1 = y0 + W1k1 + W2 k 2 (8.16a)
where
k1 = hf 0 ⎫⎪
⎬ (8.16b)
k2 = hf ( x0 + α 0 h, y0 + β 0 k1 ) ⎪⎭
312 CHAPTER 8: Numerical Solution of Ordinary Differential Equations

then the Taylor series expansions of both sides of the last equation in (8.16a)
gives the identity
h2 ⎛ ∂f ∂f ⎞ 3
y0 + hf0 + ⎜ + f0 ⎟ + O (h ) = y0 + (W1 + W2 ) hf0
2 ⎝ ∂x ∂y ⎠
⎛ ∂f ∂f ⎞
+ W2 h2 ⎜ B 0 + C0 f0 ⎟ + O (h3 ).
⎝ ∂x ∂y ⎠
Equating the coefficients of f (x, y) and its derivatives on both sides, we
obtain the relations
1 1
W1 + W2 = 1, W2B 0 = , W2 C0 = . (8.17)
2 2
Clearly, B 0 = C0 and if B 0 is assigned any value arbitrarily, then the remaining
parameters can be determined uniquely. If we set, for example, B 0 = C0 = 1,
then we immediately obtain W1 = W2 = 1/2, which gives formula (8.15).
It follows, therefore, that there are several second-order Runge–Kutta formulae
and that formulae (8.16) and (8.17) constitute just one of several such
formulae.
Higher-order Runge–Kutta formulae exist, of which we mention only the
fourth-order formula defined by
y1 = y0 + W1k1 + W2 k 2 + W3 k3 + W4 k 4 (8.18a)
where
k1 = hf ( x0 , y0 ) ⎫

k2 = hf ( x0 + B 0 h, y0 + C0 k1 ) ⎪⎪
⎬ (8.18b)
k3 = hf ( x0 + B1h, y0 + C1k1 + O1k2 ) ⎪

k4 = hf ( x0 + B 2 h, y0 + C 2 k1 + O 2 k2 + E1k3 ), ⎪⎭
where the parameters have to be determined by expanding both sides of the
first equation of (8.18a) by Taylor’s series and securing agreement of terms
up to and including those containing h4. The choice of the parameters is,
again, arbitrary and we have therefore several fourth-order Runge–Kutta
formulae. If, for example, we set
1 ⎫
B 0 = C0 = , B1 = 1 , B 2 = 1, ⎪
2 2 ⎪
1 ⎪
C1 = ( 2 − 1), C2 = 0 ⎪
2 ⎪
⎬ (8.19)
1 1 1 ⎪
O1 = 1 − , O = − , E = 1 + ,
2
2
2
1
2 ⎪

1 1⎛ 1 ⎞ 1⎛ 1 ⎞⎪
W1 = W4 = , W2 = ⎜1 − ⎟, W3 = ⎜1 + ⎟,
6 3⎝ 2⎠ 3⎝ 2 ⎠ ⎪⎭
SECTION 8.5: Runge–Kutta Method 313

we obtain the method of Gill, whereas the choice

B 0 = B1 = 1 , 1 ⎫
C0 = O1 =
2 2 ⎪

C1 = C2 = O 2 = 0, ⎪ (8.20)
B 2 = E1 = 1 ⎬

W1 = W4 = ,
1 2 ⎪
W2 = W3 = ⎪
6 6 ⎭
leads to the fourth-order Runge–Kutta formula, the most commonly used
one in practice:
1
y1 = y0 + (k1 + 2k2 + 2k3 + k4 ) (8.21a)
6
where
k1 = hf ( x0 , y0 ) ⎫

⎛ 1 1 ⎞⎪
k2 = hf ⎜ x0 + h, y0 + k1 ⎟ ⎪
⎝ 2 2 ⎠⎪
(8.21b)

⎛ 1 1 ⎞⎪
k3 = hf ⎜ x0 + h, y0 + k2 ⎟ ⎪
⎝ 2 2 ⎠

k4 = hf ( x0 + h, y0 + k3 ) ⎪

in which the error is of order h5. Complete derivation of the formula is
exceedingly complicated, and the interested reader is referred to the book by
Levy and Baggot. We illustrate here the use of the fourth-order formula by
means of examples.
Example 8.8 Given dy/dx = y − x where y (0) = 2, find y (0.1) and y (0.2)
correct to four decimal places.
(i) Runge–Kutta second-order formula: With h = 0.1, we find k1 = 0.2
and k 2 = 0.21. Hence
1
y1 = y (0.1) = 2 + (0.41) = 2.2050.
2
To determine y2 = y (0.2), we note that x0 = 0.1 and y0 = 2.2050. Hence,
k1 = 0.1(2.105) = 0.2105 and k2 = 0.1(2.4155 − 0.2) = 0.22155.
It follows that
1
y2 = 2.2050 + (0.2105 + 0.22155) = 2.4210.
2
Proceeding in a similar way, we obtain
y3 = y (0.3) = 2.6492 and y4 = y (0.4) = 2.8909
314 CHAPTER 8: Numerical Solution of Ordinary Differential Equations

We next choose h = 0.2 and compute y (0.2) and y(0.4) directly. With h = 0.2.
x0 = 0 and y0 = 2, we obtain k1 = 0.4 and k2 = 0.44 and hence y(0.2) =
2.4200. Similarly, we obtain y(0.4) = 2.8880.
From the analytical solution y = x + 1 + ex, the exact values of y(0.2)
and y(0.4) are respectively 2.4214 and 2.8918. To study the order of conver-
gence of this method, we tabulate the values as follows:
x Computed y Exact y Difference Ratio

0.2 h = 0.1: 2.4210 2.4214 0.0004


3.5
h = 0.2 : 2.4200 0.0014

0.4 h = 0.1: 2.8909 2.8918 0.0009


4.2
h = 0.2 : 2.8880 0.0038

It follows that the method has an h2-order of convergence.


(ii) Runge–Kutta fourth-order formula: To determine y(0.1), we have
x0 = 0, y0 = 2 and h = 0.1. We then obtain
k1 = 0.2,
k2 = 0.205
k3 = 0.20525
k4 = 0.21053.
Hence
1
y (0.1) = 2 + ( k1 + 2k2 + 2k3 + k4 ) = 2.2052.
6
Proceeding similarly, we obtain y(0.2) = 2.4214.
Example 8.9 Given dy/dx = 1 + y2, where y = 0 when x = 0, find y(0.2),
y(0.4) and y(0.6).
We take h = 0.2. With x0 = y0 = 0, we obtain from (8.21a) and (8.21b),
k1 = 0.2,
k2 = 0.2 (1.01) = 0.202,
k3 = 0.2 (1 + 0.010201) = 0.20204,
k4 = 0.2 (1 + 0.040820) = 0.20816,
and
1
y (0.2) = 0 +(k1 + 2k2 + 2k3 + k4 ) = 0.2027,
6
which is correct to four decimal places.
To compute y(0.4), we take x0 = 0.2, y0 = 0.2027 and h = 0.2. With
these values, Eqs. (8.21a) and (8.21b) give
SECTION 8.6: Predictor–Corrector Methods 315

k1 = 0.2 [1 + (0.2027)2 ] = 0.2082,

k2 = 0.2 [1 + (0.3068) 2 ] = 0.2188,

k3 = 0.2 [1 + (0.3121)2 ] = 0.2195,

k4 = 0.2 [1 + (0.4222) 2 ] = 0.2356,


and
y (0.4) = 0.2027 + 0.2201 = 0.4228,
correct to four decimal places.
Finally, taking x0 = 0.4, y0 = 0.4228 and h = 0.2, and proceeding as
above, we obtain y(0.6) = 0.6841.

Example 8.10 We consider the initial value problem y ′ = 3x + y/2 with the
condition y(0) = 1.
The following table gives the values of y(0.2) by different methods, the
exact value being 1.16722193. It is seen that the fourth-order Runge–Kutta
method gives the accurate value for h = 0.05.
Method h Computed value

Euler 0.2 1.100 000 00


0.1 1.132 500 00
0.05 1.149 567 58
Modified Euler 0.2 1.100 000 00
0.1 1.150 000 00
0.05 1.162 862 42
Fourth-order Runge–Kutta 0.2 1.167 220 83
0.1 1.167 221 86
0.05 1.167 221 93

8.6 PREDICTOR–CORRECTOR METHODS

In the methods described so far, to solve a differential equation over a single


interval, say from x = xn to x = xn+1, we required information only at the
beginning of the interval, i.e. at x = xn. Predictor–corrector methods are the
ones which require function values at xn, xn–1, xn–2, … for the computation
of the function value at xn+1 A predictor formula is used to predict the
value of y at xn+1 and then a corrector formula is used to improve the value
of yn+1.
In Section 8.6.1 we derive Predictor–corrector formulae which use
backward differences and in Section 8.6.2 we describe Milne’s method
which uses forward differences.
EXERCISES 335

Hence (i) simplifies to


1
1 1
2± t dx ± tx(1  x )dx ± x 2 (1  x )dx  0
0 0
0
1 1
1 © x3 x4 ¸
± B1 x(1  x )dx ±0 B1 x (1  x )
2 2
Þ 2 dx ª  ¹  0
0 ª 3
«
4 º¹
0
5
Þ B1 
= 0.2778, an simplification.
18
Then a first approximation to the solution is
5
y (0.5) =
(0.5)(0.5) = 0.06944.
18
The exact solution to the given boundary value problem is
sin x
y ( x) = − x,
sin1
which means that our solution has an error of 0.0003.
The above approximation can be improved by assuming that
t(x) = a1x(1 – x) + a2 x2(1 – x).
Proceeding as above, we obtain
a1 = 0.1924 and a2 = 0.1707.
It is clear that by adding more terms to t(x), we can obtain the result to the
desired accuracy.

EXERCISES

8.1. Given
dy
= 1 + xy, y (0) = 1,
dx
obtain the Taylor series for y(x) and compute y(0.1), correct to four
decimal places.
8.2 Show that the differential equation

d2y
= – xy, y (0) = 1 and y ′(0) = 0 ,
dx 2
has the series solution

x3 1 t 4 6 1 t 4 t 7 9
y 1 x  x "
3! 6! 9!
336 CHAPTER 8: Numerical Solution of Ordinary Differential Equations

8.3 If
dy 1
= with y (4) = 4,
dx x 2 + y
compute the values of y (4.1) and y (4.2) by Taylor’s series method.
8.4 Use Picard’s method to obtain a series solution of the problem given
in Problem 8.1 above.
8.5 Use Picard’s method to obtain y (0.1) and y (0.2) of the problem defined
by
dy
 x yx 4 , y(0)  3.
dx
8.6 Using Euler’s method, solve the following problems:
dy 3 3 dy
(a)  x y , y(0)  1 (b)  1 y 2 , y(0)  0
dx 5 dx
8.7 Compute the values of y (1.1) and y (1.2) using Taylor’s series method
for the solution of the problem
y ′′ + y 2 y1 = x3 , y (1) = 1 and y ′(1) = 1.
8.8 Find, by Taylor’s series method, the value of y (0.1) given that
y bb – xy b  y  0, y(0)  1 and y b(0)  0.
8.9 Using Picard’s method, find y (0.1), given that
dy y  x
 and y (0)  1.
dx y x
8.10 Using Taylor’s series, find y (0.1), y (0.2) and y (0.3) given that
dy
= xy + y 2 , y (0) = 1.
dx
8.11 Given the differential equation
dy
= x2 + y
dx
with y (0) = 1, compute y (0.02) using Euler’s modified method.

8.12 Solve, by Euler’s modified method, the problem


dy
= x + y , y (0) = 0.
dx
Choose h = 0.2 and compute y (0.2) and y (0.4).
8.13 Given the problem
dy
= f ( x, y ) and y ( x0 ) = y0 ,
dx
EXERCISES 337

an approximate solution at x = x0 + h is given by the third order Runge–


Kutta formula
1
y(x0 + h) = y0 + (k1 + 4k2 + k3) + R4,
6
where
1 1
k1 = hf (x0, y0), k2 = hf (x0 + h, y0 + k)
2 2 1
and k3 = hf(x0 + h, y0 + 2k2 – k1).
Show that R4 is of order h4.
8.14 Write an algorithm to implement Runge–Kutta fourth order formula for
solving an initial value problem.
Find y (0,1), y (0.2) and y (0.3) given that
2 xy
y′ = 1 + , y (0) = 0
1 + x2
8.15 Use Runge–Kutta fourth order formula to find y (0.2) and y (0.4) given
that
y2 − x2
y′ = , y (0) = 1.
y2 + x2
8.16 Solve the initial value problem defined by
dy 3x y
 , y(1)  1
dx x 2 y
and find y (1.2) and y (1.4) by the Runge–Kutta fourth order formula.
8.17 State Adam’s predictor-corrector formulae for the solution of the equation
y¢ = f (x, y), y (x0) = y0.
Given the problem
y¢ + y = 0, y(0) = 1,
find y (0.1), y (0.2), and y (0.3) by Runge–Kutta fourth order formula
and hence obtain y(0.4) by Adam’s formulae.
8.18 Given the initial value problem defined by
dy
= y (1 + x 2 ), y (0) = 1
dx
find the values of y for x = 0.2, 0.4, 0.6, 0.8 and 1.0 using the Euler, the
modified Euler and the fourth order Runge–Kutta methods. Compare
the computed values with the exact values.
8.19 State Milne’s predictor-corrector formulae for the solution of the problem
y¢ = f (x, y), y (x0) = y0.
Given the initial value problem defined by
y¢ = y2 + xy, y(0) = 1,
find, by Taylor’s series, the values of y (0.1), y (0.2) and y (0.3). Use
these values to compute y (0.4) by Milne’s formulae.
338 CHAPTER 8: Numerical Solution of Ordinary Differential Equations

8.20 Using Milne’s formulae, find y (0.8) given that


dy
= x − y 2 , y (0) = 0, y (0.2) = 0.02,
dx
y (0.4) = 0.0795 and y (0.6) = 0.1762.
8.21 Explain what is meant by a fourth order formula. Discuss this with
reference to the solution of the problem
dy y
 3x , y(0)  1
dx 2
by Runge–Kutta fourth order formula.
8.22 Use Taylor’s series method to solve the system of differential equations
dx dy
= y − t, =x+t
dt dt
with x = 1, y = 1 when t = 0, taking Dx = Dt = 0.1.
8.23 Using fourth order Runge–Kutta method, compute the value of y (0.2)
given that
d2y
+ y=0
dx 2
with y (0) = 1 and y¢(0) = 0.
8.24 Given that
y¢¢ – xy¢ + 4y = 0, y (0) = 3, y¢(0) = 0,
compute the value of y (0.2) using Runge–Kutta fourth order formla.
8.25 Solve the boundary value problem defined by
y¢¢ – y = 0, y (0) = 0, y (1) = 1,
by finite difference and cubic spline methods. Compare the solutions obtained
at y(0.5) with the exact value. In each case, take h = 0.5 and
h = 0.25.
8.26 Shooting method This is a popular method for the solution of two-point
boundary value problems. If the problem is defined by
y¢¢ = f (x), y (x0) = 0 and y (x1) = A,
then it is first transformed into the initial value problem
y¢(x) = z, z¢(x) = f(x),
with y (x0) = 0 and z(x0) = m0, where m0 is a guess for the value of y¢ (x0).
Let the solution corresponding to x = x1 be Y0. If Y1 is the value obtained
by another guess m 1 for y¢ (x0), then Y 0 and Y 1 are related linearly.
Thus, linear interpolation can be carried out between the values (m0, y0)
and (m1, y1).
Obviously, the process can be repeated till we obtain a value for y(x1) which
is close to A.
EXERCISES 339

Apply the shooting method to solve the boundary value problem


y¢¢ = y(x), y(0) = 0 and y(1) = 1.
8.27 Fyfe [1969] discussed the solution of the boundary value problem defined
by
4x 2
y ′′ + 2
y′ + y = 0, y (0) = 1 and y (2) = 0.2.
1+ x 1 + x2
Solve this problem by cubic spline method first with h = 1 and then with
h = 1/2 to determine the value of y (1). Compare your results with the exact
values of y (1) obtained from the analytical solution y = 1/(1 + x2).
8.28 Method of Linear Interpolation Let the boundary value problem be
defined by
y¢¢ + f(x)y¢ + g(x)y = p(x),
y (x0) = y0 and y (xn) = yn.
Set up the finite difference approximation of the differential equation and
solve the algebraic equations using the initial value y0 and assuming a
value, say Y0, for y (x1). Again, we assume another value for y(x1), say Y1
and then compute the values of y2, y3, …, yn–1 and yn. We, thus, have two
sets of values of y (x1) and y (xn). Now we use linear interpolation formula
to compute the value of y (x1) for which y (xn) = yn. The process is repeated
until we obtain the value of y(xn) close to the given boundary condition (see
Problem 8.26).
Solve the boundary value problem defined by
y² + xy¢ – 2y = 0, y(0) = 1 and y(1) = 2
using the method of Linear interpolation.
8.29 Using Galerkin’s method, compute the value of y (0.5) given that
y¢¢ + y = x2, 0 < x < 1, y (0) = 0 and y (1) = 0.
8.30 Solve Poisson’s equation

∂ 2u ∂ 2u
+
= 2, 0 ≤ x, y ≤ 1
∂x 2 ∂y 2
with u = 0 on the boundary C of the square region 0 £ x £ 1, 0 £ y £ 1.

Answers to Exercises

8.1 1.1053

x3 1 × 4 6 1 × 4 × 7 9
8.2 1− + x − x +"
3! 6! 9!
8.3 4.005, 4.0098
340 CHAPTER 8: Numerical Solution of Ordinary Differential Equations

x 2 x3 x 4
8.4 1 + x + + + +"
2 3 8
8.5 3.005, 3.0202

8.6 (a) 1.0006, (b) y1 = 1.0000, y2 = 0.201, y3 = 0.3020

8.7 1.1002, 1.2015

8.8 1.005012

8.9 1.0906

8.10 1.11686, 1.27730, 1.5023

8.11 1.0202

8.12 0.0222, 0.0938

8.14 0.1006, 0.2052, 0.3176

8.15 0.19598, 1.3751

8.16 1.2636, 1.532

8.17 y (0.1) = 0.90484, y (0.2) = 0.81873, y (0.3) = 0.7408


y (0.4) = 0.6806 (Exact value = 0.6703).

8.18 x = 0.2 0.024664 (Euler)


0.003014 (Modified Euler)
0.000003 (Runge–Kutta)
x = 1.0 0.776885 (Euler)
0.12157 (Modified Euler)
0.000273 (Runge–Kutta)
8.19 y(0.1) = 1.1169, y(0.2) = 1.2773, y(0.3) = 1.5023,
y(0.4) = 1.8376.

8.20 y p(0.8) = 0.3049, yc(0.8) = 0.30460

8.21 h = 0.2, error = 0.00000110


h = 0.1, error = 0.0000007

8.22 x1 = 1.1003, y(0.1) = y1 = 1.1100

8.23 0.980067 (Exact value = 0.980066)


EXERCISES 341

8.24 y(0.2) = 2.762239 (Exact value = 2.7616)


z(0.2) = –2.360566 (Exact value = –2.368)

8.25 Exact value of y(0.5) = 0.443409


(a) 0.443674, (b) 0.443140

8.26 y¢(0) = 2.8

8.27 (a) h = 1, y1 = 0.4


1
h = , y2 = 0.485714
2
(b) h = 1, y1 = 0.542373
1
h = , y2 = 0.5228
2

8.28 y1 = 1.0828, y2 = 1.2918, y3 = 1.6282, y4 = 1.99997

8.29 y(0.5) = –0.041665 (Exact value = –0.04592)


5
8.30 u(x, y) = – xy(x – 1)(y – 1)
2
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS 233

dy
13. Given the differential equation = x 2 y + x 2 and the data
dx
x 1 1.1 1.2 1.3
y 1 1.233 1.548488 1.978921
determine y(1.1) by Adams-Bashforth formula.
dy
14. Using Adams-Bashforth method, obtain the solution of = x − y 2 at x = 0.8, given
dx
x 9 0.2 0.4 0.6
y 0 0.0200 0.0795 0.1762

Answers

1. y 4′ = 1.583627, = 1.5703
2.
x 0.3 0.4 0.5 0.6
y 0.061493 0.45625 0.29078 0.12566

3. y(0.3) = 0.6148 4. y0.2 = 12428, y0.3 = 1.3997 5. y4 = 2.162, y5 = 2.256


6. y(1.4) = 0949 7. 6.8733
9. y(0.5) = 0.6065, y(0.6) = 0.5490, y(0.7) = 0.4965, y(0.8) = 4495
10. y(0.4) = 0.7785 11. 1.1749

10.8 RUNGE-KUTTA METHOD


The method is very simple. It is named after two German mathematicians Carl Runge (1856–1927)
and Wilhelm Kutta (1867–1944). It was developed to avoid the computation of higher order derivations
which the Taylor’s method may involve. In the place of these derivatives extra values of the given
function f(x, y) are used.
The Runge-Kutta formulas for several types of differential equations are given below.
Fourthorder Runge-Kutta Method:
Let
dy
dx
= f x, ya f
represent any first order differential equation and let h denote the step length. If x0, y0 denote the
initial values, then the first increment ∆y in y is computed from the formulae
b g
k1 = h f x 0 , y0 ,
F h
= h f Gx + , y
k1IJ
k2
H 2
0 0 +
2 K
,
234 NUMERICAL ANALYSIS

FG h , y + k IJ ,
H 2
k3 = h f x0 +
2K
3
0

k = h f b x + h, y + k g,
4 0 0 3

∆y = bk + 2 k + 2 k + k g .
1
and 1 2 3 4
6
Thus we can write
x1 = x 0 + h, y1 = y0 + ∆y .
Similarly the increments for the other intervals are computed. It will be noted that if f(x, y) is
independent of y then the method reduces to Simpson’s formula. Though approximately the same as
Taylor’s polynomial of degree four. Runge-Kutta formulae do not require prior calculations of higher
derivatives of y(x), as the Taylor’s method does. These formulae involve computation of f (x, y) of
various position. This method known as Runge-Kutta fourth order method is very popular and
extensively used but the errors in method are not easy to watch. The error in the Runge-Kutta method
is of the order h5. Runge-Kutta methods agree with Taylor’s series solution up to the term hm where
m differs from the method and is called the order of that method.
First order Runge-Kutta method:
Consider the first order equation
dy
dx
a f b g
= f x , y , y x 0 = y0 L (1)

We have seen that Euler’s method gives


b
y1 = y0 + h f x 0 , y0 = y0 + hy0′ L g (2)
Expanding by Taylor’s series, we get

b g
y1 = y x 0 + h = y0 + hy0′ +
h2
2
y0′′ + L (3)

Comparing (2) and (3), it follows that, Euler’s method agrees with Taylor’s series solution up
to the term in h.
Hence Euler’s method is the Runge-Kutta method of the first order.
Second order Runge-Kutta method:
The modified Euler’s method gives

y1 = y0 +
h
2
b
f x0 , y0 + f x0 + h, y1 g b g (4)

Taking f0 = f (x0, y0) and substituting y1 = y0 + h f0 the RHS of (4), we obtain

b
y1 = y x0 + h g = y0 +
h
2
b
f 0 + f x0 + h, y 0 + h f 0 g (5)

Expanding LHS by Taylor’s series, we get

b g
y1 = y x 0 + h = y0 + hy0′ +
h2
2!
y0′′ +
h3
3!
y0′′′+ L (6)
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS 235

Expanding f (x0 + h, y0 + h f0) by Taylor’s series for a function of the variables, we obtain

b g FGH ∂∂fx IJK FG ∂f IJ


f (x0 + h, y0 + h f0) = f x0 , y0 + h
0
+ h f0
H ∂y K 0

+ terms containing second and other higher powers of h.

FG ∂f IJ FG ∂f IJ d i
f0 + h =
H ∂x K 0
+ h f0
H ∂y K 0
+ O h2

∴ (5) can be written as

1 LM LMFG ∂f IJ FG ∂f IJ OP + O dh iOP
MNH ∂x K H ∂y K PQ
y1 = y0 + hf 0 + hf 0 + h 2 + f0
MN PQ
3
2 0 0

= y0 + hf 0 +
h2
2
f 0′ + O h 3 d i
LMQ df
=
∂f
+ f
∂f
where f = f x , y b gOPQ
N dx ∂x ∂y

= y0 + hy0′ +
h2
2!
y0′′ + O h 3 . d i (7)

Comparing (6) and (7), it follows that the modified Euler’s method agrees with Taylor’s series
solution up to the term in h2.
Hence the modified Euler’s method is the Runge-Kutta method of second order.
The second order Runge-Kutta formula is as follows:

b g
k1 = h f xn , yn

k2 = h f b x + h, y
n n + k1 g
yn + 1 = yn + ∆yn

where ∆yn =
1
2
b
k1 + k 2 g
which gives k1 = h f bx , y g
0 0

k2 = h f b x + h, y + k g
0 0 1

= y + bk + k g = y
1
and y1 0 1 2 0 + ∆y0 .
2
236 NUMERICAL ANALYSIS

Third order Runge-Kutta method


This method agrees with Taylor’s series solution up to the term in h3. The formula is as follows:

y1 = y0 +
1
6
b
k1 + 4 k 2 + k 3 g
where b g
k1 = h f x0 , y0

F h
k = h f Gx + , y + J
k I
H 2 2K
1
2 0 0

k = h f b x + h, y + 2 k − k g
3 0 0 2 1

The general formula is


yn +1 = yn + ∆y

where b g
k1 = h f xn + yn

F 1
k = hf G x + h , y + k J
1 I
2
H 2 2 K
n n 1

k = hf b x + h , y + 2 k − k g
3 n n 2 1

∆y = b k + 4 k + k g
1
and 1 2 3
6
Runge-Kutta methods are one-step methods and are widely used. Fourth order R-K method is
most commonly used and is known as Runge-Kutta method only. We can increase the accuracy of
Runge-Kutta method by taking higher order terms.
Example 10.12 Use Runge–Kutta method to approximate y when x = 0.1, given that y = 1, when
dy
x = 0 and = x + y.
dx
Solution We have
x0 = 0, y0 = 1

b g
f x , y = x + y , and h = 01
..

∴ f bx , y g = x
0 0 0 + y0 = 0 + 1 = 1,

we get k1 = h f x0 , y0b g = 01
. × 1 = 01
. ,

FG h , y + k IJ = b01. g c f b0 + 0.05g, 1 + 0.05h


k 2 = h f x0 +
H 2 2K
1
0

= b01
. g f b0.05, 105
. g = b01
. gb0.05 + 105
. g = 011
. ,
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS 237

FG h , y + k IJ
H 2
k 3 = h f x0 +
2K
2
0

= b01
. g c f b0 + 0.05g, 1 + 0.055h = b01. gb0.05 + 1055. g

= b01
. gb1105
. g = 01105. ,

k4 = f bx + h , y + k g
0 0 3

= b01
. g f b0 + 0.01, 1 + 01105
. g = b01. g f b01. , 11105
. g
= b01
. gb12105
. g = 012105
. ,

∴ ∆y =
1
6
b
k1 + 2 k 2 + 2 k 3 + k 4 g
=
1
6
b
0.1 + 0.22 + 0.2210 + 012105
. g = 011034
. .

We get x1 = x0 + h = 0 + 01
. = 01
.

y1 = y0 + ∆y = 1 + 0.11034 = 111034
. .

dy
Example 10.13 Using Runge–Kutta method, find an approximate value of y for x = 0.2, if = x + y 2 , gives that
dx
y = 1 when x = 0.
Solution Taking step-length h = 0.1, we have

x 0 = 0, y 0 = 1,
dy
dx
b g
= f x, y = x + y 2 .

Now b g b gb g
k1 = h f x0 , y0 = 01
. 0 + 1 − 01
. ,

F h k I
= h f G x + , y + J = b01 . gb0.05 + 11025g
H 2 2K
1
k2 0 0 .

= b01
. gb11525
. g = 011525
. ,

F h k I
= h f G x + , y + J = b01 . gb0.05 + 11185g
H 2 2K
2
k3 0 0 .

= b01
. gb11685
. g = 011685
. ,

k4 = h f bx + h , y + k g
0 0 3

= b01
. gb0.01 + 12474
. g = b01. gb13474
. g = 013474
. ,

∴ ∆y =
1
6
bk1 + 2 k 2 + 2 k 3 + k 4 g
238 NUMERICAL ANALYSIS

=
1
6
c0.1 + 2 011525
. b g b
+ 2 0.11685 + 0.13474 g h
=
1
6
b0.6991 = 0.1165.g
We get y1 = y0 + ∆y = 1 + 01165
.

b g
∴ y 01
. = 11165
. .
For the second step, we have
x0 = 01
. , y0 = 11165
. ,

b gb
k1 = 01 . + 12466
. 01 . g
= 01347
. ,

k = b01
2 . gb015
. + 14014
. g = b01. gb15514
. g = 01551
. ,

k = b01
3 . gb015
. + 14259
. g = b01. gb15759
. g = 01576
. ,

k = b01
4 . gb0.2 + 16233
. g = b01. gb18233
. g = 01823
. ,

∆y = b 0.9424 g = 0.1571 ,
1
6

∴ yb0.2g = 11165
. + 01571
. = 12736
.

∴ yb01 . g = 11165
. and yb0.2g = 12736
. .
Example 10.14 Using Runge-Kutta method of order 4, find y for x = 0.1, 0.2, 0.3, given that
dy
= xy + y 2 , y(0 ) = 1. . Continue the solution at x = 0.4 using Milne’s method.
dx
Solution. We have f(x, y) = xy + y2
x0 = 0, y0 = 1
x1 = 0.1, x2 = 0.2, x3 = 0.3, x4 = 0.4, and h = 0.1
To find y1 = y (0.1):
k 1 = hf (x0, y0) = (0.1) (0 × 1 + 12) = 0.1000

FG x h k IJ
k 2 = hf H 0 +
2
, y0 + 1
2 K = (0.1) f (0.05, 1.05)

= 0.1155

FG h k IJ
k 3 = hf x0 +
H 2 K
, y0 + 2 = ( 0.1) f (0. 05,1. 0577 )
2
= 0.1172
k 4 = hf (x0 + h, y0 + k3) = (0.1) f (0.1, 1.1172)
= 0.13598

and k =
1
6
b
k1 + k2 + 2 k3 + k4 g
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS 239

=
1
6
b
0.1000 + 2 × 0.1155 + 2 × 0.1172 + 0.13598 g
= 0.11687
∴ y1 = y(0.1) = y0 + k = 1 + 0.11687 = 1.11687 ~ 1.1169
⇒ y1 = 1.1169
To find y2 = y(0.2)
Here we have
k 1 = hf (x1, y1) = (0.1) f (1, 1.1169) = 0.1359

FG h k IJ
H
k 2 = hf x1 +
2 K
, y1 + 1 = (0.1) f (0.15, 1.1848)
2
= 0.1581

FG h k IJ = (0.1) f (0.15,1.0959)
k 3 = hf x1 +
H 2
, y1 + 2
2 K
= 0.1609
k 4 = hf ( x1 + h, y1 + k3 ) = ( 0.1) f ( 0. 2, 1. 2778)
= 0.1888

k =
1
6
b
k1 + 2 k2 + 2 k3 + k4 g
=
1
6
b
0.1359 + 2 × 0.1581 + 2 × 0.1609 + 0.1888 g
= 0.1605
y2 = y(0.2) = y1 + k = 1.1169 + 0.1605 = 1.2774
To find y3 = y(0.3)
Here we have k 1 = hf (x2, y2) = (0.1) f (0.2, 1.2774)
= 0.1887

FG h k IJ
k 2 = hf x2 +
H 2 K
, y2 + 1 = (0.1) f (0. 25,1. 3716)
2
= 0.2224

FG h k IJ
k 3 = hf x2 +
H 2 K
, y2 + 2 = (0.1) f ( 0. 25,1.3885)
2
= 0.2275

b g
k 4 = hf x2 + h, y2 + k3 = ( 0.1) f ( 0. 3,1.5048)
= 0.2716

k =
1
6
b
k1 + 2 k2 + 2 k3 + k4 g
=
1
6
b
0.1887 + 2 × 0. 2224 + 2 × 0. 2275 + 0. 2716 g
= 0.2267
240 NUMERICAL ANALYSIS

∴ y3 = y(0.3) = y2 + k = 1.2774 + 0.2267


= 1.5041
we have x0 = 0.0, x1 = 0.1, x2 = 0.2, x3 = 0.3, x4 = 0.4
y0 = 1, y1 = 1.1169, y2 = 1.2774, y3 = 1.5041
y′0 = 1.000, y′1 = 1.3591, y′2 = 1.8869, y′3 = 2.7132
Using Milne’s predictor:

4h
y4 = y0 + 2 y ′1 − y ′ 2 − 2 y ′3
3

4 × 0.1
= 1+ 2 × 1. 3591 − 1.8869 + 2 × 2.7132]
3
= 1.8344
⇒ y′4 = 4.0988

h
and the corrector is y4 = y2 + y ′ 2 + 4 y ′3 + y ′4
3

0.1
= 12773 + 1.8869 + 4 × 2. 7132 + 4. 0988 = 1.8366
3
∴ y(0.4) = 1.8366

Exercise 10.3

bg
1. Solve the equation dy = x − y 2 , y 0 = 1 for x = 0.2 and x = 0.4 to 3 decimal places by Runge-Kutta
dx
fourth order method.

2. Use the Runge-Kutta method to approximate y at x = 0.1 and x = 0.2 for the equation
dy
dx
bg
= x + y , y 0 = 1.

3. For the equation


dy
dx
y
bg
= 3x + , y 0 = 1. Find y at the following points with the given step-length.
2
4. Use Runge-Kutta method to solve y′ = xy for x = 1.4, initially x = 1, y = 2 (by taking step-length
h = 0.2).
dy y 2 − 2 x
5. = 2 , use Runge–Kutta method to find y at x = 0.1, 0.2, 0.3 and 0.4, given that y = 1 when
dx y +x
x = 0.

6. Use Runge-Kutta method to obtain y when x = 1.1 given that y = 1.2 when x = 1 and y satisfies the
dy
equation = 3x + y 2 .
dx
dy 1
7. Solve the differential equation = for x = 2.0 by using Runge-Kutta method. Initial values
dx x + y
x = 0, y = 1, interval length h = 0.5.
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS 241

8. Use Runge-Kutta method to calculate the value of y at x = 0.1, to five decimal places after a single
step of 0.1, if
dy
= 0. 31 + 0.25 y + 0.3x 2
dx
and y = 0.72 when x = 0

dy y2 − x2
9. Using Runge-Kutta method of fourth order solve = 2 , with y(0) = 1 at x = 0.2, 0.4.
dx y + x2

dy
10. Using Runge-Kutta method of order, 4 compute y(0.2) and y(0.4) from 10 = x 2 + y 2 , y (0) = 1, taking
dx
x = 0.1.
11. Find by Runge-Kutta method an approximate value of y for x = 0.8, given that y = 0.41 when x = 0.4
and
dy
= x + y.
dx
12. The unique solution of the problem
dy
dx
bg
= − xy, y 0 = 1

is y = e − x
2
/3
, find approximate value of y(0.2) using one application of R-K method.

Answers

1. 0851, 0.780 2. 1.1103, 1.2428


3.
x h y

0.1 0.1 1.0665242


0.2 0.2 1.1672208
0.4 0.4 1.4782

4. 2.99485866 5. y(0.1) = 1.0874, y(0.2) = 1.1557, y(0.3) = 1.2104, y(0.4) = 1.2544


6. y(1.1) = 1.7271
7.
x 0.5 1.0 1.5 2.0
y 1.3571 1.5837 1.7555 1.8957

8. 0.76972 9. 1.196, 1.3752 10. 1.0207, 1.038


11. 1.1678 12. 0.9802
276 Numerical Methods : Problems and Solutions

yn+1 = yn + h φ (tn+1, tn, yn+1, yn, h), n = 0, 1, 2,... (5.23)


where φ is a function of the arguments tn, tn+1, yn, yn+1, h and also depends on f. We often write
it as φ (t, y, h). This function φ is called the increment function. If yn+1 can be obtained simply by
evaluating the right hand side of (5.23), then the method is called an explicit method. In this
case, the method is of the form
yn+1 = yn + h φ (tn, yn, h).
If the right hand side of (5.23) depends on yn+1 also, then it is called an implicit method.
The general form in this case is as given in (5.23).
The local truncation error Tn+1 at xn+1 is defined by
Tn+1 = y(xn+1) – y(xn) – h φ (tn+1, tn, y (tn+1), y(tn), h). (5.24)
The largest integer p such that
p
| h–1 Tn+1 | = O(h ) (5.25)
is called the order of the single step method.
We now list a few single step methods.

Explicit Methods

Taylor Series Method


If the function y(x) is expanded in the Taylor series in the neighbourhood of x = xn, then
we have
h2 hp
yn+1 = yn + hy′n + yn″ + ... + y (p)
2! p! n
n = 0, 1, 2, ..., N – 1 (5.26)
with remainder
h p+1
Rp+1 = y(p+1) (ξn), xn < ξn < xn+1.
( p + 1) !
The equation (5.26) is called the Taylor series method of order p. The value p is chosen so
that | Rp+1 | is less than some preassigned accuracy. If this error is ε, then
hp+1 | y(p+1) (ξn) | < (p + 1) ! ε
or hp+1 | f (p) (ξn) | < (p + 1) ! ε.
For a given h, this equation will determine p, and if p is specified then it will give an
upper bound on h. Since ξn is not known, | f (p) (ξn) is replaced by its maximum value in [x0, b].
As the exact solution may not be known, a way of determining this value is as follows. Write
one more non-vanishing term in the series than is required and then differentiate this series p
times. The maximum value of this quantity in [x0, b] gives the required bound.
The derivatives yn(p), p = 2, 3, ... are obtained by successively differentiating the differ-
ential equation and then evaluating at x = xn. We have
y′(x) = f (x, y),
y″(x) = fx + f fy
y′″(x) = fxx + 2f fxy + f 2fyy + fy ( fx + ffy).
Substituting p = 1 in (5.26), we get
yn+1 = yn + h fn, n = 0(1)N – 1 (5.27)
which is known as the Euler method.
Numerical Solution of Ordinary Differential Equations 277

Runge-Kutta methods
The general Runge-Kutta method can be written as
v
yn+1 = yn + ∑ w K, i i n = 0, 1, 2, ..., N – 1 (5.28)
i=1

F i−1 I
where Ki = hf GG x + ci h, yn + ∑a Km JJ
H n
m=1
im
K
with c1 = 0.
For v = 1, w1 = 1, the equation (5.28) becomes the Euler method with p = 1. This is the
lowest order Runge-Kutta method. For higher order Runge-Kutta methods, the minimum
number of function evaluations (v) for a given order p is as follows :
p 2 3 4 5 6 ...

v 2 3 4 6 8 ...
We now list a few Runge-Kutta methods.

Second Order Methods


Improved Tangent method :
yn+1 = yn + K2, n = 0(1)N – 1, (5.29)
K1 = hf (xn, yn),
FG
h K IJ
K2 = hf xn +
H
2
, yn + 1 .
2 K
Euler-Cauchy method (Heun method)
1
yn+1 = yn + (K1 + K2), n = 0(1)N – 1, (5.30)
2
K1 = hf (xn, yn),
K2 = hf (xn + h, yn + K1).

Third Order Methods


Nyström method
1
yn+1 = yn + (2K1 + 3K2 + 3K3), n = 0(1)N – 1, (5.31)
8
K1 = hf (xn, yn),
FG 2 2 IJ
H
K2 = hf x n +
3
h , yn + K 1 ,
3 K
F
= hf G x
2 I
+ K J.
2
K3
H n +
3
h , yn
3 K 2

Heun method
1
yn+1 = yn + (K1 + 3K3), n = 0(1)N – 1, (5.32)
4
K1 = hf (xn, yn),
278 Numerical Methods : Problems and Solutions

FG 1 1 IJ
H
K2 = hf x n +
3
h , yn + K 1
3 K
= hf FG x 2
+ K J
2 I
K3
H n +
3
h , yn
3 K 2 .

Classical method
1
yn+1 = yn + (K1 + 4K2 + K3), n = 0(1)N – 1, (5.33)
6
K1 = hf (xn, yn),
FG 1 1 IJ
H
K2 = hf x n +
2
h , yn + K 1 ,
2 K
K3 = hf (xn + h, yn – K1 + 2K2).
Fourth Order Methods
Kutta method
1
yn+1 = yn + (K1 + 3K2 + 3K3 + K4), n = 0(1)N – 1, (5.34)
8
K1 = hf (xn, yn),
FG 1 1 IJ
H
K2 = hf x n +
3
h , yn + K 1 ,
3 K
F
= hf G x
2 1 IJ
K3
H 3
h , yn − K 1 + K 2 ,
n +
3 K
K4 = hf (xn + h, yn + K1 – K2 + K3).
Classical method
1
yn+1 = yn + (K1 + 2K2 + 2K3 + K4), n = 0(1)N – 1, (5.35)
6
K1 = hf (xn, yn),
FG 1 1 IJ
H
K2 = hf x n +
2
h , yn + K 1
2 K
F
= hf G x
1
+ K J
1 I
K3
H 2
n +
h , yn
2 K 2

K4 = hf (xn + h, yn + K3).
Implicit Runge-Kutta Methods
The Runge-Kutta method (5.28) is modified to
v
yn+1 = yn + ∑ wi Ki, n = 0(1)N – 1, (5.36)
i=1

F v I
where GG
Ki = hf x n + ci h, yn + ∑a JJ
Km .
H m=1
im
K
With v function evaluations, implicit Runge-Kutta methods of order 2v can be obtained.
A few methods are listed.
Numerical Solution of Ordinary Differential Equations 279

Second Order Method


yn+1 = yn + K1, n = 0(1)N – 1, (5.37)
FG 1 1 IJ
K1 = hf x n +
H 2
h , yn + K 1 .
2 K
Fourth Order Method
1
yn+1 = yn + (K1 + K2), n = 0(1)N – 1, (538)
2
F F I F I I
GH 1 3
GH 1 1 3
JK
K1 = hf xn + 2 − 6 h, yn + 4 K 1 + 4 − 6 K 2 , GH JK JK
F F1 3I F1 3I I
= hf G x K + K J.
1
+G + J h, y + G + J
K2
H n
H2 6 K
n
H4 6 K
1
4 K 2

5.3 MULTISTEP METHODS


The general k-step or multistep method for the solution of the IVP (5.4) is a related k-th order
difference equation with constant coefficients of the form
yn+1 = a1 yn + a2 yn–1 + ... + ak yn–k+1
+ h (b0 yn+′ 1 + b y′ + ... + b y′
1 n k n–k+1) (5.39)
or symbolically, we write (5.39) as
ρ(E) yn–k+1 – hσ(E) y′n–k+1 = 0
where ρ(ξ) = ξ – a1ξk–1 – a2 ξk–2 ... – ak,
k

σ(ξ) = b0ξk + b1ξk–1 + b2 ξk–2 + ... + bk. (5.40)


The formula (5.39) can be used if we know the solution y(x) and y′(x) at k successive
points. The k-values will be assumed to be known. Further, if b0 = 0, the method (5.39) is
called an explicit or a predictor method. When b0 ≠ 0, it is called an implicit or a corrector
method. The local truncation error of the method (5.39) is given by
k k
Tn+1 = y(xn+1) – ∑ ai y(xn–i+1) – h ∑ bi y′(xn–i+1). (5.41)
i=1 i=0
Expanding the terms on the right hand side of (5.41) in Taylor’s series and rearranging
them we obtain
Tn+1 = C0 y(xn) + C1h y′(xn) + C2h2 y″(xn) + ...
+ Cphp y(p)(xn) + Cp+1 hp+1 y(p + 1)(xn) + ... (5.42)
k
where C0 = 1 – ∑ am
m=1

1 LM k OP
Cq =
q!
1−
m=1
MN ∑
am (1 − m) q
PQ
k
1

(q − 1) !
∑ bm(1 – m)q–1, q = 1(1)p. (5.43)
m=0
Numerical Solution of Ordinary Differential Equations 305

Hence, 0 < µi < 1, for s > 0.


For s < 0, we may also have 1 + 4s < – 1 and hence | µi | < 1.
This condition gives s < – 1 / 2. Hence, the method is stable for s < – 1 / 2 or s > 0.
Initial Value Problems
Taylor Series Method
5.12 The following IVP is given
y′ = 2x + 3y, y(0) = 1.
(a) If the error in y(x) obtained from the first four terms of the Taylor series is to be less
than 5 × 10–5 after rounding, find x.
(b) Determine the number of terms in the Taylor series required to obtain results cor-
rect to 5 × 10–6 for x ≤ 0.4
(c) Use Taylor’s series second order method to get y(0.4) with step length h = 0.1.
Solution
(a) The analytic solution of the IVP is given by
11 3 x 2
y(x) = e − (3x + 1).
9 9
We have from the differential equation and the initial condition
y(0) = 1, y′(0) = 3, y″(0) = 11,
y″′(0) = 33, y iv(0) = 99.
Hence, the Taylor series method with the first four terms becomes
11 2 11 3
y(x) = 1 + 3x + x + x .
2 2
The remainder term is given by
x 4 ( 4)
R4 = y (ξ).
24
Now | R4 | < 5 × 10–5 may be approximated by
x4
99e 3 x < 5 × 10–5,
24
or x4e3x < 0.00001212, or x ≤ 0.056.
(This value of x can be obtained by applying the Newton-Raphson method on
f (x) = x4e3x – 0.00001212 = 0).
Alternately, we may not use the exact solution. Writing one more term in the Taylor
series, we get
11 2 11 3 33 4
y(x) = 1 + 3x + x + x + x.
2 2 8
Differentiating four times, we get y (x) = 99. We approximate max| y(4)(ξ) | = 99.
(4)

Hence, we get
x 4 ( 4) 99 4
| R4 | = y (ξ) ≤ x
24 24
99 4
Now, x < 5 × 10–5, gives x ≤ 0.059.
24
306 Numerical Methods : Problems and Solutions

(b) If we use the first p terms in the Taylor series method then we have
xp
max max | y(p)(ξ)| ≤ 5 × 10–6.
0 ≤ x ≤ 0.4 p! ξ ∈[ 0, 0.4 ]

Substituting from the analytic solution we get


(0.4) p
(11) 3p–2 e1.2 ≤ 5 × 10–6 or p > 10.
p!
Alternately, we may use the procedure as given in (a).
Writing p + 1 terms in the Taylor series, we get
(11) 3 p −2 p
y(x) = 1 + 3x + ... +
x
p!
Differentiating p times, we get y(p)(x) = (11)3p–2. We approximate
max | y(p)(ξ) | = (11)3p–2.
Hence, we get
LM max | x| OP (11)3
p
p–2 ≤ 5 × 10–6
N p! Q
0 ≤ x ≤ 0.4

(0.4) p
or (11)3p–2 ≤ 5 × 10–6, which gives p ≥ 10.
p!
(c) The second order Taylor series method is given by
h2
yn+1 = yn + h yn′ + yn″ , n = 0, 1, 2, 3
2
We have yn′ = 2x + 2y
n n
yn″ = 2 + 3 yn′ = 2 + 3(2xn + 3yn) = 2 + 6xn + 9yn.
With h = 0.1, the solution is obtained as follows :
n = 0, x0 = 0 : y0 = 1
y0′ = 2 × 0 + 3y0 = 3
y0″ = 2 + 6 × 0 + 9 × 1 = 11,
(0.1) 2
y1 = 1 + 0.1(3) + × 11 = 1.355.
2
n = 1, x1 = 0.1 : y1′ = 2 × 0.1 + 3(1.355) = 4.265.
y1″ = 2 + 6 × 0.1 + 9(1.355) = 14.795.
1
y2 = y1 + h y1′ + h 2 y1″
2
(0.1) 2
= 1.355 + 0.1(4.265) + (14.795) = 1.855475.
2
n = 2, x2 = 0.2 : y2′ = 2 × 0.2 + 3(1.855475) = 5.966425.
y2″ = 2 + 6 × 0.2 + 9(1.855475) = 19.899275.
h2
y3 = y2 + h y2′ + y2″
2
(0.1) 2
= 1.855475 + 0.1(5.966425) + (19.899275) = 2.5516138.
2
Numerical Solution of Ordinary Differential Equations 307

n = 3, x3 = 0.3 : y3′ = 2 × 0.3 + 3(2.5516138) = 8.2548414


y3″ = 26.764524
(0.1) 2
y4 = 2.5516138 + 0.1(8.2548414) + (26.764524)
2
= 3.5109205.
Hence, the solution values are
y(0.1) ≈ 1.355, y(0.2) ≈ 1.85548,
y(0.3) ≈ 2.55161, y(0.4) ≈ 3.51092.
5.13 Compute an approximation to y(1), y′(1) and y″(1) with Taylor’s algorithm of order two
and steplength h = 1 when y(x) is the solution to the initial value problem
y′″ + 2y″ + y′ – y = cos x, 0 ≤ x ≤ 1, y(0) = 0, y′(0) = 1, y″(0) = 2.
(Uppsala Univ., Sweden, BIT 27(1987), 628)
Solution
The Taylor series method of order two is given by
h2
y(x0 + h) = y(x0) + hy′(x0) + y″(x0).
2
2
h
y′(x0 + h) = y′(x0) + hy″(x0) + y″′(x0).
2
h 2 (4)
y″(x0 + h) = y″(x0) + hy″′(x0) + y (x0).
2
We have y(0) = 0, y′(0) = 1, y″(0) = 2,
y″′(0) = – 2 y″(0) – y′(0) + y(0) + 1 = – 4,
y(4)(0) = – 2 y″′(0) – y″(0) + y′(0) = 7.
For h = 1, x0 = 0, we obtain
y(1) ≈ 2, y′(1) ≈ 1, y″(1) ≈ 3 / 2.
Alternately, we can use the vector form of the Taylor series method. Setting y = v1, we
write the given IVP as
LM
v1

OP LM v2 v1 OP 0 LM OP LM OP
MN
v2 =
v3 PQ MN v3
cos x + v1 − v2 − 2v3 PQ
, v2 (0) = 1 ,
v3 2 MN PQ MN PQ
or v′ = f (x, v), v(0) = [0 1 2]T.
where v = [v1 v2 v3]T.
The Taylor series method of second order gives
h2
v(1) = v(0) + h v′(0) + v″(0) = v(0) + v′(0) + 0.5 v″(0)
2
We have v(0) = [0 1 2]T
LM v 2 OP LM 1OP
v′(0) = M P
Q MN− 4PQ
v 3 (0) = 2
Ncos x + v1 − v − 2v 2 3

L v ′ OP LM 2OP
v″(0) = M
2

MN− sin x + v ′ − v ′ − 2v ′PQ (0) = MN− 47PQ


v ′
1
3
2 3
308 Numerical Methods : Problems and Solutions

Hence, we obtain
LMv (1)OP LM y(1) OP LM0OP LM 1OP LM 2OP LM 2 OP
1

MNvv ((11))PQ = MN yy″′ ((11))PQ = MN21PQ + MN− 42PQ + 0.5 MN− 47PQ = MN1.15PQ
2
3

5.14 Apply Taylor series method of order p to the problem y′ = y, y(0) = 1 to show that
hp x
| yn – y(xn) | ≤ xn e n .
( p + 1) !
Solution
The p-th order Taylor series method for y′ = y is given by
F h2 hp I
GH
yn+1 = 1 + h +
2!
+ ... + JK
y = A yn, n = 0, 1, 2, ...
p! n
h2 hp
where A=1+h+ + ... + .
2! p!
Setting n = 0, 1, 2, ..., we obtain the solution of this first order difference equation which
satisfies the initial condition, y(0) = y0 = 1, as
F
= G1 + h +
h 2
h I p n

p ! JK
An + ... +
yn =
H 2!
.

The analytic solution of the initial value problem gives


y(xn) = e xn .
Hence, we have
F h2 hp I n
h p+1
y(xn) – yn = enh – 1 + h + GH 2
+ ... +
p! JK ≤n
( p + 1) !
eθh e(n–1)h.

Since, nh = xn and 0 < θ < 1, we get


hp x
| yn – y(xn) | ≤ xn e n .
( p + 1) !
Runge-Kutta Methods
5.15 Given the equation
y′ = x + sin y
with y(0) = 1, show that it is sufficient to use Euler’s method with the step h = 0.2 to
compute y(0.2) with an error less than 0.05.
(Uppsala Univ., Sweden, BIT 11(1971), 125)
Solution
The value y(0.2) with step length h = 0.2 is the first value to be computed with the help
of the Euler method and so there is no question of propagation error contributing to the
numerical solution. The error involved will only be the local truncation error given by
1
| T1 | = h2 | y″(ξ) |, 0 < ξ < h.
2
Using the differential equation, we find
y″(ξ) = 1 + cos(y(ξ)) y′(ξ) = 1 + cos(y(ξ)) [ξ + sin (y(ξ))].
Numerical Solution of Ordinary Differential Equations 309

We obtain max | y″(ξ) | ≤ 2.2.


ξ ∈[ 0, 0.2 ]
Hence, we have
1
| T1 | ≤ (0.2)2 2.2 = 0.044 < 0.05.
2
5.16 Consider the initial value problem
y′ = x(y + x) – 2, y(0) = 2.
(a) Use Euler’s method with step sizes h = 0.3, h = 0.2 and h = 0.15 to compute ap-
proximations to y(0.6) (5 decimals).
(b) Improve the approximation in (a) to O(h3) by Richardson extrapolation.
(Linköping Inst. Tech., Sweden, BIT 27(1987), 438)
Solution
(a) The Euler method applied to the given problem gives
yn+1 = yn + h[xn(yn + xn) – 2], n = 0, 1, 2, ...
We have the following results.
h = 0.3 :
n = 0, x0 = 0 : y1 = y0 + 0.3[– 2] = 2 – 0.6 = 1.4.
n = 1, x1 = 0.3 : y2 = y1 + 0.3[0.3(y1 + 0.3) – 2] = 1.4 – 0.447 = 0.953.
h = 0.2 :
n = 0, x0 = 0 : y1 = y0 + 0.2[– 2] = 2 – 0.4 = 1.6.
n = 1, x1 = 0.2 : y2 = y1 + 0.2[0.2(y1 + 0.2) – 2] = 1.6 + 0.04(1.6 + 0.2) – 0.4 = 1.272.
n = 2, x2 = 0.4 : y3 = y2 + 0.2[0.4(y2 + 0.4) – 2]
= 1.272 + 0.08(1.272 + 0.4) – 0.4 = 1.00576.
h = 0.15 :
n = 0, x0 = 0 : y1 = y0 + 0.15[– 2] = 2 – 0.3 = 1.7.
n = 1, x1 = 0.15 : y2 = y1 + 0.15[0.15(y1 + 0.15) – 2]
= 1.7 + 0.0225(1.7 + 0.15) – 0.3 = 1.441625.
n = 2, x2 = 0.30 : y3 = y2 + 0.15[0.3(y2 + 0.3) – 2]
= 1.441625 + 0.045(1.441625 + 0.3) – 0.3 = 1.219998.
n = 3, x3 = 0.45 : y4 = y3 + 0.15[0.45(y3 + 0.45) – 2]
= 1.2199981 + 0.0675(1.6699988) – 0.3 = 1.032723.
(b) Since the Euler method is of first order, we may write the error expression in the
form
y(x, h) = y(x) + c1h + c2h2 + c3h3 + ...
We now have
y(0.6, 0.3) = y(0.6) + 0.3c1 + 0.09c2 + O(h3).
y(0.6, 0.2) = y(0.6) + 0.2c1 + 0.04c2 + O(h3).
y(0.6, 0.15) = y(0.6) + 0.15c1 + 0.0225c2 + O(h3).
Eliminating c1, we get
p = 0.2y(0.6, 0.3) – 0.3y(0.6, 0.2)
= – 0.1y(0.6) + 0.006c2 + O(h3).
q = 0.15y(0.6, 0.2) – 0.2y(0.6, 0.15)
= – 0.05y(0.6) + 0.0015c2 + O(h3).
310 Numerical Methods : Problems and Solutions

Eliminating c2, we have


0.0015 p – 0.006 q = 0.00015y(0.6) + O(h3).
Hence, the O(h3) result is obtained from
0.0015 p − 0.006 q
y(0.6) ≈ = 10 p – 40 q.
0.00015
From (a) we have
y(0.6, 0.3) = 0.953 ; y(0.6, 0.2) = 1.00576 ; and y(0.6, 0.15) = 1.03272.
Substituting these values, we get
p = – 0.111128, q = – 0.05568, and
y(0.6) = 1.11592.
5.17 (a) Show that Euler’s method applied to y′ = λ y, y(0) = 1, λ < 0 is stable for step-sizes
– 2 < λ h < 0 (stability means that yn → 0 as n → ∞).
(b) Consider the following Euler method for y′ = f (x, y),
yn+1 = yn + p1hf (xn, yn)
yn+2 = yn+1 + p2hf (xn+1, yn+1), n = 0, 2, 4, ...
where p1, p2 > 0 and p1 + p2 = 2. Apply this method to the problem given in (a) and show
that this method is stable for
2 1 1
– < λh < 0, if 1 – < p1, p2 < 1 + .
p1 p2 2 2
(Linköping Univ., Sweden, BIT 14(1974), 366)
Solution
(a) Applying the Euler method on y′ = λ y, we obtain
yn+1 = (1 + λh) yn, n = 0, 1, 2, ...
Setting n = 0, 1, 2, ..., we get
yn = (1 + λh) n y0.
The solution which satisfies the initial condition y0 = 1, is given by
yn = (1 + λh) n, n = 0, 1, 2, ...
The Euler method will be stable (in the sense yn → 0 as n → ∞) if
| 1 + λh | < 1, λ < 0, or – 2 < λh < 0.
(b) The application of Euler’s method gives
yn+1 = (1 + p1hλ)yn
yn+2 = (1 + p2hλ)yn+1
or yn+2 = (1 + p1hλ)(1 + p2hλ)yn.
The characteristic equation of this difference equation is
ξ2 = (1 + p1hλ)(1 + p2hλ).
The stability condition | ξ | < 1 is satisfied if (using the Routh-Hurwitz criterion)
(i) 1 – (1 + p1hλ)(1 + p2hλ) > 0,
and (ii) 1 + (1 + p1hλ)(1 + p2hλ) > 0.
The condition (i) is satisfied if
– 2hλ – p1 p2h2 λ2 > 0,
FG 2 IJ 2
or – hλ p1 p2
Hp p
1 2 K
+ hλ > 0, or –
p1 p2
< hλ < 0.
Numerical Solution of Ordinary Differential Equations 311

The condition (ii) is satisfied if


F I 2

2 + 2hλ + p1 p2 h2λ2 >0 or GH p1 p2 hλ +


1
p1 p2
JK +2−
1
p1 p2
>0

A sufficient condition is
1
> 0,
2– or 2p1 p2 – 1 > 0.
p1 p2
Substituting p2 = 2 – p1, we have
1
2 p12 – 4p1 + 1 < 0, or (p1 – 1)2 – < 0.
2
Similarly, we obtain
1
(p2 – 1)2 – < 0.
2
Hence, if follows
1 1
1–
< p1, p2 < 1 + .
2 2
5.18 (a) Give the exact solution of the IVP y′ = xy, y(0) = 1.
(b) Estimate the error at x = 1, when Euler’s method is used, with step size h = 0.01. Use
the error formula
hM
| y(xn) – y(xn ; h) | ≤ [exp (xn – a) L – 1]
2L
when Euler’s method is applied to the problem y′ = f (x, y); y(x) = A, in a ≤ x ≤ b and
h = (b – a) / N, xn = a + nh and | ∂f / ∂y | ≤ L ; | y″(x) | ≤ M.
(Uppsala Univ., Sweden, BIT 25(1985), 428)
Solution
(a) Integrating the differential equation
1 dy
=x
y dx
2
we obtain y = c e x /2
.
The initial condition gives y(0) = c = 1.
2
The exact solution becomes y(x) = e x / 2 .
(b) We have at x = 1,
∂f
= | x | ≤ L = 1,
∂y
2
| y″(x) | = (1 + x2) e x / 2 ≤ M = 3.297442,
1
| y(xn) – y(xn; h) | ≤ [(0.01) 3.297442] (e – 1) = 0.0283297.
2
Hence, we obtain
| y(xn) – y(xn; h) | ≤ 0.03.
5.19 Apply the Euler-Cauchy method with step length h to the problem
y′ = – y, y(0) = 1.
(a) Determine an explicit expression for yn.
312 Numerical Methods : Problems and Solutions

(b) For which values of h is the sequence { yn }0∞ bounded ?


(c) Compute lim {(y(x ; h) – e–x) / h2}.
h→0
Solution
Applying the Euler-Cauchy method
K1 = hf (xn, yn),
K2 = hf (xn + h, yn + K1),
1
yn + 1 = yn + (K1 + K2),
2
to y′ = – y, we obtain
K1 = – hyn,
K2 = – h(yn – hyn) = – h(1 – h)yn,
FG 1 2 IJ
H
yn + 1 = 1 − h +
2
h yn.
K
(a) The solution of the first order difference equation satisfying the initial condition
y(0) = 1 is given by
FG 1 2 IJ n

H
yn = 1 − h +
2
h
K
, n = 0, 1, 2, ......

(b) The sequence { yn }0∞ will remain bounded if and only if


1 2
1− h + h ≤ 1, or 0 < h ≤ 2.
2
− xn
(c) The analytic solution of the IVP gives y(xn) = e .
We also have
h2 h 3 – θh
e–h = 1 – h + – e , 0 < θ < 1.
2 6
The solution in (a) can be written as
F L F h + O(h )I OP
I n n

= Me G 1 +
3
h3
yn = Ge
H
−h
+
6
+ O( h 4 ) JK
MN H 6
−h
JK PQ 4

F 1 + nh 3 I
= e–nh GH 6 + O(h )J 4 1
K = e + 6 x e h + O(h ).
–nh
n
–nh 2 4

Hence, at a fixed point xn = x, and h → 0, we obtain


−x
lim ( y( x ; h) − e ) = 1 x e–x.
h→0 2
h 6
5.20 Heun’s method with step size h for solving the differential equation
y′ = f (x, y), y(0) = c
can be written as
K1 = h f (xn, yn),
K2 = h f (xn + h, yn + K1),
1
yn+ 1 = yn + (K1 + K2).
2
Numerical Solution of Ordinary Differential Equations 313

(a) Apply Heun’s method to the differential equation y′ = λ y, y(0) = 1. Show that
yn = [H(λh)]n
and state the function H. Give the asymptotic expression for yn – y(xn) when h → 0.
(b) Apply Heun’s method to the differential equation y′ = f (x), y(0) = 0 and find yn.
(Royal Inst. Tech., Stockholm, Sweden, BIT 26(1986), 540)
Solution
(a) We have K1 = λh yn,
K2 = λh (yn + λh yn) = λh(1 + λh) yn ,
1
yn + 1 = yn + [λhyn + λh (1 + λh) yn]
2
FG1 IJ
H K
2
= 1 + λh + (λh) yn.
2
This is a first order difference equation. The general solution satisfying the initial con-
dition, y(0) = 1, is given by
FG 1 IJ n

H
yn = 1 + λh +
2
(λh) 2
K .
Therefore, we have
1
(λh)2.
H(λh) = 1 + λh +
2
The analytic solution of the test equation gives
y(xn) = (eλh)n .
Hence, we may write yn in the form
L
= Me
λh 1
(λh) 3 + O(h 4 )
OP n
LM 1
n(λh) 3 + O(h 4 )
OP
yn
N −
6 Q N
= eλ nh 1 −
6 Q
1
x λ3 h2 e λ xn + O(h4)
= y(xn) –
6 n
Therefore, the asymptotic expression for yn – y(xn) is given by
LMFG y − y( xn ) IJ OP = – 1 x λ
NH KQ 6
lim n 3 λ xn .
e
h→0 2 n
h
(b) The Heun method for y′ = f (x), becomes

yn = z xn

0
f ( x) dx = T(h).
where T(h) is the expression for the trapezoidal rule of integration.
5.21 Consider the following Runge-Kutta method for the differential equation y′ = f (x, y)
1
yn + 1 = yn + (K1 + 4K2 + K3),
6
K1 = hf (xn, yn),
h FG K IJ
K2 = hf xn +
2 H
, yn + 1 ,
2 K
K3 = hf (xn + h, yn – K1 + 2K2).
314 Numerical Methods : Problems and Solutions

(a) Compute y(0.4) when


y+ x
y′ = , y(0) = 1
y− x
and h = 0.2. Round to five decimals.
(b) What is the result after one step of length h when y′ = – y, y (0) = 1.
(Lund Univ., Sweden, BIT 27(1987), 285)
Solution
(a) Using y0 = 1, h = 0.2, we obtain
LM y
0 + x0 OP
K1 = 0.2
Ny0 − x0 Q = 0.2.
= 0.2 M
Ly0 + 0.1 + 0.1 O
P = 0.24.
K2
Ny0 + 0.1 − 0.1 Q

K3 = 0.2 M
Ly0 − 0.2 + 0.48 + 0.2 O
P = 0.27407.
Ny0 − 0.2 + 0.48 − 0.2 Q
1
y1 = 1 + (0.2 + 0.96 + 0.27407) = 1.23901.
6
Now, using y1 = 1.23901, x1 = 0.2, we obtain
FG y 1 + 0.2IJ = 0.277.
K1 = 0.2
Hy 1 − 0.2 K
= 0.2 G
Fy 1 + 0.13850 + 0.3 I
J = 0.31137.
K2
Hy 1 + 0.13850 − 0.3 K

= 0.2 G
Fy 1 − 0.277 + 0.62274 + 0.4 I
J = 0.33505.
K3
Hy 1 − 0.277 + 0.62274 − 0.4 K
1
y2 = y1 + (0.277 + 4 × 0.31137 + 0.33505) = 1.54860.
6
(b) For f (x, y) = – y, we get
K1 = – hy0,
FG IJ = FG − h + 1 h IJ y ,
1
K H 2 K
2
H
K2 = – h y0 −
2
hy0 0

F
= – h Gy
F 1 I I
+ hy + 2 G − h + h J y J = (– h + h – h ) y ,
H H 2 K K
2 2 3
K3 0 0 0 0

y1 =y +
0 G − hy + 4 FGH − h + 21 h IJK y + (− h + h − h ) y IJK
1 F
6 H 0
2
0
2 3
0

F 1 1 I
= GH 1 − h + h − h JK y .
2 3
0
2 6
F
= G1 − h + h − h J .
1 1 I
H 6 K
2 3
Therefore, y1
2
Numerical Solution of Ordinary Differential Equations 315

5.22 Use the classical Runge-Kutta formula of fourth order to find the numerical solution at
x = 0.8 for
dy
= x + y , y(0.4) = 0.41.
dx
Assume the step length h = 0.2.
Solution
For n = 0 and h = 0.2, we have
x0 = 0.4, y0 = 0.41,
K1 = hf (x0, y0) = 0.2 (0.4 + 0.41)1/2 = 0.18,
FG h 1IJ L 1 OP 1/ 2

H
K2 = hf x0 +
2 2 K MN
, y0 + K 1 = 0.2 0.4 + 0.1 + 0.41 + (0.18)
2 Q = 0.2,

F
= hf G x
h I L O
+ K J = 0.2 M0.4 + 0.1 + 0.41 + (0.2)P
1 1
1/ 2
K3
H 0 +
2
, y0
2 K 2
N 2 Q
= 0.2009975,
K4 = hf (x0 + h, y0 + K3) = 0.2 [0.4 + 0.2 + 0.41 + 0.2009975]1/2
= 0.2200907.
1
y1 = y0 + (K1 + 2K2 + 2K3 + K4)
6
= 0.41 + 0.2003476 = 0.6103476.
For n = 1, x1 = 0.6, and y1 = 0.6103476, we obtain
K1 = 0.2200316, K2 = 0.2383580, K3 = 0.2391256, K4 = 0.2568636,
y2 = 0.6103476 + 0.2386436 = 0.8489913.
Hence, we have y(0.6) ≈ 0.61035, y(0.8) ≈ 0.84899.
5.23 Find the implicit Runge-Kutta method of the form
yn + 1 = yn + W1 K1 + W2 K2,
K1 = hf (yn),
K2 = hf (yn + a(K1 + K2)),
for the initial value problem y′ = f (y), y(t0) = y0.
Obtain the interval of absolute stability for y′ = λ y, λ < 0.
Solution
Expanding K2 in Taylor series, we get
1
K2 = hfn + ha(K1 + K2) fy + ha2 (K1 + K2)2 fyy
2
1
+ ha3 (K1 + K2)3 fyyy + ......
6
where fy = ∂f (xn) / ∂y.
We assume the expression for K2 in the form
K2 = hA1 + h2A2 + h3A3 + ....
Substituting for K2 and equating coefficients of like powers of h, we obtain
A1 = fn,
A2 = 2a fn fy ,
316 Numerical Methods : Problems and Solutions

A3 = aA2 fy + 2a2 fyy f n2 = 2a2 fn f y2 + 2a2 f n2 fyy ,


We also have
h2 h3
y(xn + 1) = y(xn) + hy′(xn) + y″ (xn) + y′″ (xn) + .......
2 6
where y′ = f,
y″ = fy f,
y′″ = fyy f 2 + f y2 f, ......
The truncation error in the Runge-Kutta method is given by
Tn + 1 = yn + 1 – y(xn + 1)
= yn + W1h fn + W2 [h fn + h2 2afnfy
+ h3 (2a2fn f y2 + 2a2 f n2 fyy)] – [y(xn) + hfn

h2 h3
+fy fn + (f f 2 + fn f y2 )] + O(h4).
2 6 yy n
To determine the three arbitrary constants a, W1 and W2, the necessary equations are
W1 + W2 = 1,
2W2 a = 1 / 2,
2W2 a2 = 1 / 6,
whose solution is a = 1 / 3, W2 = 3 / 4, W1 = 1 / 4.
The implicit Runge-Kutta method becomes
K1 = hf (yn),
FG 1 IJ
K2 = hf yn +H 3 K
(K 1 + K2 ) ,

1
yn + 1 = yn +
(K1 + 3K2).
4
The truncation error is of the form O(h4) and hence, the order of the method is three.
Applying the method to y′ = λ y, λ < 0, we get

K1 = λh yn = h yn,
FG 1 IJ FG y 1 1 IJ
K2 = hλ yn +H 3
(K1 + K2 )
K =h H n +
3 K
h yn + K 2 .
3
Solving for K2, we get

h [1 + (h / 3)]
K2 = yn
1 − (h / 3)
where h = hλ.

Therefore, yn + 1 = yn +
1
h yn +
3h LM 1 + (h / 3) OP y = LM 1 + (2h / 3) + (h 2
/ 6) OP y
4 4 N 1 − (h / 3) Q N 1 − (h / 3)
n
Q n

The characteristic equation is


1 + (2 h / 3) + (h 2 / 6)
ξ= .
1 − (h / 3)
Numerical Solution of Ordinary Differential Equations 317

For absolute stability we require | ξ | < 1. Hence, we have


F h I
GH JK < 1 + 23 h + h6
2
h
– 1− <1– .
3 3
The right inequality gives
h2 h
h + <0, or (6 + h ) < 0.
6 6
Since, h < 0, we require 6 + h > 0, which gives h > – 6.
The left inequality gives
h h2
2+ + >0
3 6
which is always satisfied for h > – 6.
Hence, the interval of absolute stability is h ∈(– 6, 0).
5.24 Determine the interval of absolute stability of the implicit Runge-Kutta method
1
yn + 1 = yn +
(3K1 + K2),
4
h FG 1 IJ
H
K1 = hf xn + , yn + K 1
3 3 K
K2 = hf (xn + h, yn + K1),
when applied to the test equation y′ = λ y, λ < 0.
Solution
Applying the method to the test equation we have
FG 1 IJ
K1 = hλ yn +H 3
K1 ,
K
or K1 =
LM h OP y , where h = λh.
N 1 − (h / 3) Q n

K2 = hλ (y + K ) = h M y +
L h O L h + (2h / 3) OP y
y P=M
2

n 1
N 1 − (h / 3) Q N 1 − (h / 3) Q
n n n

Therefore, yn + 1 =M
L 1 + (2h / 3) + (h / 6) OP y .
2

N 1 − (h / 3) Q n

The characteristic equation of themethod is same as in example 5.23. The interval of


absolute stability is (– 6, 0).
5.25 Using the implicit method
yn + 1 = yn + K1,
FG h 1 IJ
K1 = hf tn + H 2
, yn + K 1 ,
2 K
find the solution of the initial value problem
y′ = t2 + y2, y(1) = 2, 1 ≤ t ≤ 1.2 with h = 0.1.
318 Numerical Methods : Problems and Solutions

Solution
We have f (t, y) = t2 + y2. Therefore,
LMFG t h IJ + FG y
2
K1 IJ OP .
2

MNH K H K PQ
K1 = n + n +
2 2
We obtain the following results.
n=0: h = 0.1, t0 = 1, y0 = 2.
K1 = 0.1 [(1.05)2 + (2 + 0.5 K1)2] = 0.51025 + 0.2 K1 + 0.025 K12.
This is an implicit equation in K1 and can be solved by using the Newton-Raphson method.
We have
F (K1) = 0.51025 – 0.8 K1 + 0.025 K12 ,
F′ (K1) = – 0.8 + 0.05K1.
(0 )
We assume K 1 = h f (t0, y0) = 0.5. Using the Newton-Raphson method
F ( K 1( s) )
K 1( s + 1) = K1(s) – , s = 0, 1, ......
F ′ ( K 1( s) )
We obtain K 1( 1) = 0.650322, K 1(2) = 0.651059, K 1(3) = 0.651059.
Therefore, K1 ≈ K 1(3) = 0.651059 and y(1.1) ≈ y1 = 2.651059.
n=1: h = 0.1, t1 = 1.1, y1 = 2.65106
K1 = 0.1[(1.15)2 + (2.65106 + 0.5 K1)2]
= 0.835062 + 0.265106 K1 + 0.025 K 12

F (K1) = 0.835062 – 0.734894 K1 + 0.025 K 12


F ′ (K1) = – 0.734894 + 0.05 K1.
We assume K 1(0) = hf (t1, y1) = 0.823811. Using the Newton-Raphson method, we get
K 1( 1) = 1.17932, K 1(2) = 1.18399, K 1(3) = 1.18399.
Therefore, K1 ≈ K 1(3) = 1.18399 and y(1.2) ≈ y2 = 3.83505.
5.26 Solve the initial value problem
u′ = – 2tu2, u(0) = 1
with h = 0.2 on the interval [0, 0.4]. Use the second order implicit Runge-Kutta method.
Solution
The second order implicit Runge-Kutta method is given by
uj + 1 = uj + K1, j = 0, 1
FG h 1 IJ
K1 = hf t j + H 2
, u j + K1
2 K
1 FG IJ 2
which gives K1 = – h (2tj + h) u j +
2
K1 .
H K
This is an implicit equation in K1 and can be solved by using an iterative method. We
generally use the Newton-Raphson method. We write
FG 1 IJ 2
FG 1 IJ 2
F (K1) = K1 + h(2tj + h) u j +
H 2
K1
K H
= K1 + 0.2 (2tj + 0.2) u j +
2
K1
K
Numerical Solution of Ordinary Differential Equations 319

1 1
We have F ′(K1) = 1 + h (2tj + h) (uj + K ) = 1 + 0.2 (2tj + 0.2) (uj + K1).
2 1 2
The Newton-Raphson method gives
( s)
K 1( s + 1) = K 1(s) – F ( K 1 ) , s = 0, 1, ......
F ′ ( K 1( s) )

We assume K 1(0) = hf (tj , uj), j = 0, 1.


We obtain the following results.
2
j=0; t0 = 0, u0 = 1, K 1(0) = – h(2t0 u0 ) = 0,
(0 )
F ( K 1(0) ) = 0.04, F′( K 1 ) = 1.04, K 1( 1) = – 0.03846150,
( 2)
F ( K 1( 1) ) = 0.00001483, F′( K 1(1) ) = 1.03923077, K 1 = – 0.03847567

F ( K 1( 2) ) = 0.30 × 10–8.

Therefore, K1 ≈ K 1(2) = – 0.03847567,


and u(0.2) ≈ u1 = u0 + K1 = 0.96152433.
(0 ) 2
j=1; t1 = 0.2, u1 = 0.96152433, K 1 = – h(2t1 u1 ) = – 0.07396231,
(0 ) (0 ) (1)
F ( K 1 ) = 0.02861128, F ′( K 1 ) = 1.11094517, K 1 = – 0.09971631,
( 2)
F ( K 1(1) ) = 0.00001989, F ′( K 1( 1) ) = 1.10939993, K 1 = – 0.09973423,

F ( K 1( 2) ) = 0.35 × 10–7, F ′( K 1(2) ) = 1.10939885, K 1(3) = – 0.099773420.


Therefore, K1 ≈ K 1(3) = – 0.09973420,
and u(0.4) ≈ u2 = u1 + K1 = 0.86179013.

Multistep Methods
5.27 Find the solution at x = 0.3 for the differential equation
y′ = x – y2 , y(0) = 1
by the Adams-Bashforth method of order two with h = 0.1. Determine the starting val-
ues using a second order Runge-Kutta method.
Solution
The second order Adams-Bashforth method is
h
yn + 1 = yn + ( 3 yn′ – yn′ − 1 ), n = 1, 2, .....
2
We need the value of y(x) at x = x1 for starting the computation. This value is deter-
mined with the help of the second order Runge-Kutta method
1
yn + 1 = yn + (K + K2),
2 1
......................................................................................

One of the most useful tools of applied mathematics is differential equation, it may
be ordinary differential equation (ODE) or partial differential equation (PDE). Both
ODE and PDE are widely used to model lots of mathematical and engineering problems.
Unfortunately, it is not possible to find analytical solution of all ODEs or PDEs. Finding
of analytic solution of an ODE or a PDE is a very difficult task. But, several numerical
techniques are available to solve ODEs and PDEs.
Let us consider the following first order differential equation

dy
= f (x, y) (1.1)
dx
with initial condition

y(x0 ) = y0 . (1.2)

If the analytic solution of an ODE is not available then we will go for numerical
solution. The numerical solution of a differential equation can be determined in one of
the following two forms:

(i) A power series solution for y in terms of x. Then the values of y can be obtained
by substituting x = x0 , x1 , . . . , xn .

(ii) A set of tabulated values of y for x = x0 , x1 , . . . , xn with spacing h.

The general solution of an ODE of order n contains n arbitrary constants. To find


such constants, n conditions are required. The problems in which all the conditions are
specified at the initial point only, are called initial value problems (IVPs). The
ODEs of order two or more and for which the conditions are specified at two or more
points are called boundary value problems (BVPs).
There may not exist a solution of an ordinary differential equation always. The
sufficient condition for existence of unique solution is provided by Lipschitz.
The methods to find approximate solution of an initial value problem are called finite
difference methods or discrete variable methods. The solutions are determined
at a set of discrete points called a grid or mesh of points. That is, a given differential
equation is converted to a discrete algebraic equation. By solving such equation, we get
an approximate solution of the given differential equation.
1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Runge-Kutta Methods

A finite difference method is convergent if the solution of the finite difference equa-
tion approaches to a limit as the size of the grid spacing tends to zero. But, in general,
there is no guarantee, that this limit corresponds to the exact solution of the differential
equation.
Mainly, two types of numerical methods are used, viz. explicit method and implicit
method. If the value of yi+1 depends only on the values of yi , h and f (xi , yi ) then the
method is called explicit method, otherwise the method is called implicit method.
In this chapter, we discuss some useful methods to solve ODEs.

1.1 Euler’s method


Euler’s method is the most simple but crude method to solve the differential equation
of the form
dy
= f (x, y), y(x0 ) = y0 . (1.3)
dx
Let x1 = x0 + h, where h is small. Then by Taylor’s series
 dy  h2  d2 y 
y1 = y(x0 + h) = y0 + h + ,
dx x0 2 dx2 c1
where c1 lies between x0 and x
h2
= y0 + hf (x0 , y0 ) + y 00 (c1 ) (1.4)
2
Thus, by neglecting second order term, we get

y1 = y0 + hf (x0 , y0 ). (1.5)

In general,
yn+1 = yn + hf (xn , yn ), n = 0, 1, 2, . . . (1.6)

This is a very slow method. To find a reasonable accurate solution, the value of
h must be taken as small. The Euler’s method is less efficient in practical problems
because if h is not sufficiently small then this method gives inaccurate result.
This method is modified to get more better result as follows:
The value of y1 obtained by Euler’s method is repeatedly modified to get a more
accurate result. For this purpose, the term f (x0 , y0 ) is replaced by the average of
(0) (0)
f (x0 , y0 ) and f (x0 + h, y1 ), where y1 = y0 + hf (x0 , y0 ).
2
1.1. Euler’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

That is, the modified Euler’s method is

(1) h (0)
y1 = y0 + [f (x0 , y0 ) + f (x1 , y1 )] (1.7)
2
(0)
where y1 = y0 + hf (x0 , y0 ).
Note that the value of y1 depends on the value of y1 obtained in previous iteration.
So this method is known as implicit method, whereas Euler method is explicit method.
Other simple methods, viz. Taylor’s series, Picard, Runge-Kutta, etc. are also avail-
able to solve the differential equation of the form (1.1).
Now, we describe Runge-Kutta method. In this method, several function evaluations
are required at each step and it avoids the computation of higher order derivatives.
There are several types of Runge-Kutta methods, such as second, third, fourth, fifth,
etc. order. The fourth-order Runge-Kutta method is more popular. These are single-
step explicit methods.

1.2 Second-order Runge-Kutta method

First we deduce second order Runge-Kutta method from modified Euler’s method.
The modified Euler’s method is
h (0)
y1 = y0 + [f (x0 , y0 ) + f (x1 , y1 )] (1.8)
2
(0)
where y1 = y0 + hf (x0 , y0 ).
(0)
Now, we substitute the value of y1 to the equation (1.8). Then

h
y1 = y0 + [f (x0 , y0 ) + f (x0 + h, y0 + hf (x0 , y0 ))].
2
Let

k1 = hf (x0 , y0 ) and
k2 = hf (x0 + h, y0 + hf (x0 , y0 )) = hf (x0 + h, y0 + k1 ). (1.9)

Using this notation the equation (1.8) becomes

1
y1 = y0 + (k1 + k2 ). (1.10)
2
3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Runge-Kutta Methods

This method is known as second-order Runge-Kutta method. Note that this is


an explicit formula, whereas modified Euler’s method is an implicit method.
The local truncation error of this method is O(h3 ).
This formula can also be derived independently.
Independent derivation of second-order Runge-Kutta method

Suppose the solution of the equation

dy
= f (x, y), y(x0 ) = y0 (1.11)
dx
is of the following form:

y1 = y0 + ak1 + bk2 , (1.12)

where

k1 = hf (x0 , y0 ) and
k2 = hf (x0 + αh, y0 + βk1 ), a, b, α and β are constants.

By Taylor’s theorem

h2 h3
y1 = y(x0 + h) = y0 + hy00 + y000 + y0000 + · · ·
2 6
h 2 h ∂f   ∂f  i
= y0 + hf (x0 , y0 ) + + f (x0 , y0 ) + O(h3 )
2 ∂x (x0 ,y0 ) ∂y (x0 ,y0 )
 
df ∂f ∂f
since = + f (x, y)
dx ∂x ∂y
k2 = hf (x0 + αh, y0 + βk1 )
h  ∂f   ∂f  i
= h f (x0 , y0 ) + αh + βk1 + O(h2 )
∂x (x0 ,y0 ) ∂y (x0 ,y0 )
 ∂f   ∂f 
= hf (x0 , y0 ) + αh2 + βh2 f (x0 , y0 ) + O(h3 ).
∂x (x0 ,y0 ) ∂y (x0 ,y0 )

Substituting these values to the equation (1.12), we get

h2
y0 + hf (x0 , y0 ) + [fx (x0 , y0 ) + f (x0 , y0 )fy (x0 , y0 )] + O(h3 )
2
= y0 + (a + b)hf (x0 , y0 ) + bh2 [αfx (x0 , y0 ) + βf (x0 , y0 )fy (x0 , y0 )] + O(h3 ).
4
1.1. Euler’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Equating the coefficients of f , fx and fy both sides we get the following equations.
1 1
a + b = 1, bα = and bβ = . (1.13)
2 2
Obviously, α = β. Here, number of equations is three and variables is four. Therefore,
the system of equations has many solutions. However, usually the parameters are chosen
1
as α = β = 1, then a = b = .
2
For this set of parameters, the equation (1.12) becomes
1
y1 = y0 + (k1 + k2 ) + O(h3 ), (1.14)
2
where k1 = hf (x0 , y0 ) and k2 = hf (x0 + h, y0 + k1 ). (1.15)

1.3 Fourth-order Runge-Kutta method

The fourth-order Runge-Kutta formula to calculate y1 is


1
y1 = y0 + (k1 + 2k2 + 2k3 + k4 ) (1.16)
6
where

k1 = hf (x0 , y0 )
k2 = hf (x0 + h/2, y0 + k1 /2)
k3 = hf (x0 + h/2, y0 + k2 /2)
k4 = hf (x0 + h, y0 + k3 ).

Using the value of y1 one can find the value of y2 as


1
y2 = y1 + (k1 + 2k2 + 2k3 + k4 ) (1.17)
6
where

k1 = hf (x1 , y1 )
k2 = hf (x1 + h/2, y1 + k1 /2)
k3 = hf (x1 + h/2, y1 + k2 /2)
k4 = hf (x1 + h, y1 + k3 ).
5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Runge-Kutta Methods

In general, 1 (i) (i) (i) (i)


yi+1 = yi + (k1 + 2k2 + 2k3 + k4 ) (1.18)
6
where
(i)
k1 = hf (xi , yi )
(i) (i)
k2 = hf (xi + h/2, yi + k1 /2)
(i) (i)
k3 = hf (xi + h/2, yi + k2 /2)
(i) (i)
k4 = hf (xi + h, yi + k3 ),

for i = 0, 1, 2, . . ..
Example 1.1 Given y 0 = x − y 2 with x = 0, y = 1. Find y(0.2) by second and fourth-
order Runge-Kutta methods.

Solution. Here, x0 = 0, y0 = 1, f (x, y) = x − y 2 .


By Second order Runge-Kutta method
Let h = 0.1.

k1 = hf (x0 , y0 ) = 0.1 × (0 − 12 ) = −0.10000.


k2 = hf (x0 + h, y0 + k1 ) = 0.1 × f (0.1, 0.9)
= −0.07100.

Now, we calculate,
1
y1 = y(0.1) = y(0) + (k1 + k2 )
2
= 1 + 0.5 × (−0.1 − 0.071) = 0.91450.

To determine y2 = y(0.2), x1 = 0.1 and y1 = 0.91450.

k1 = hf (x1 , y1 ) = 0.1 × {0.1 − (0.91450)2 } = −0.073633.


k2 = hf (x1 + h, y1 + k1 )
= 0.1 × [0.2 − (0.9145 − 0.07363)2 ] = −0.05071.

Therefore,
1
y2 = y(0.2) = y(0.1) + (k1 + k2 )
2
= 0.91450 + 0.5 × (−0.07363 − 0.05071) = 0.85233.
6
1.1. Euler’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

By fourth-order Runge-Kutta methods:


Here h = 0.1, x0 = 0, y0 = 1, f (x, y) = x − y 2 .
Then,

k1 = hf (x0 , y0 ) = 0.1 × (0 − (1)2 ) = −0.1.


k2 = hf (x0 + h/2, y0 + k1 /2)
0.1 0.1 2
= 0.1 × {( ) − (1 − ) } = −0.08525.
2 2
k3 = hf (x0 + h/2, y0 + k2 /2)
0.1 0.08525 2
= 0.1 × {( ) − (1 − ) } = −0.08666.
2 2
0.1 0.08666 2
k4 = 0.1 × {( ) − (1 − ) } = −0.07342.
2 2
Therefore,
1
y1 = y(0.1) = y0 + (k1 + 2k2 + 2k3 + k4 )
6
1
= 1 + [−0.1000 + 2 × {(−0.08525) + (−0.08666)} − 0.07342] = 0.91379.
6
To find, y2 = y(0.2), h = 0.1, x1 = 0.1, y1 = 0.91379.
Then,

k1 = hf (x1 , y1 ) = 0.1 × {0.1 − (0.91379)2 } = −0.07350.


k2 = hf (x1 + h/2, y1 + k1 /2)
0.1 0.07350 2
= 0.1 × {(0.1 + ) − (0.91379 − ) } = −0.06192.
2 2
k3 = hf (x1 + h/2, y1 + k2 /2)
0.1 0.06192 2
= 0.1 × {(0.1 + ) − (0.91379 − ) } = −0.06294.
2 2
k4 = hf (x1 + h, y1 + k3 )
= 0.1 × {(0.1 + 0.1) − (0.91379 − 0.06294)2 } = −0.05239.

Therefore,
1
y2 = y(0.2) = y(0) + (k1 + 2k2 + 2k3 + k4 )
6
1
= 0.91379 + [−0.07350 + 2 × {(−0.06192) + (−0.06294)} − 0.05239]
6
= 0.85119.
7
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Runge-Kutta Methods

Note 1.1 The fourth order Runge-Kutta method gives better result, though, this method
has some disadvantages. In this method, a lot of function calculations are required.
Thus, if the function f (x, y) is complicated, then the Runge-Kutta method is very labo-
rious.

Error in fourth-order Runge-Kutta method

The fourth-order Runge-Kutta formula can be written as

(h/2) h 4(k2 + k3 ) i
y1 = y0 + k1 + + k4 .
3 2
This form is similar to the Simpson’s 1/3 formula with step size h/2. Thus, the local
h5 iv
truncation error of this formula is − y (c1 ), i.e. of O(h5 ). After n steps, the
2880
accumulated error is
n
X h5 iv xn − x0 iv
− y (ci ) = − y (c)h4 = O(h4 ).
2880 5760
i=1

1.4 Runge-Kutta method for a pair of equations

The second and fourth-order Runge-Kutta methods can also used to solve a pair of
first order differential equations.
Let us consider a pair of first-order differential equations
dy
= f (x, y, z)
dx
(1.19)
dz
= g(x, y, z)
dx
with initial conditions

x = x0 , y(x0 ) = y0 , z(x0 ) = z0 . (1.20)

Here, x is the independent variable and y, z are the dependent variables. So, in this
problem we have to determine the values of y, z for different values of x.
8
1.1. Euler’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The fourth-order Runge-Kutta method to find the values of yi and zi for x = xi from
a pair of equations is
1 (i) (i) (i) (i)
yi+1 = yi + [k1 + 2k2 + 2k3 + k4 ],
6
1 (i) (i) (i) (i)
zi+1 = zi + [l1 + 2l2 + 2l3 + l4 ], (1.21)
6

(i)
where k1 = hf (xi , yi , zi )
(i)
l1 = hg(xi , yi , zi )
(i) (i) (i)
k2 = hf (xi + h/2, yi + k1 /2, zi + l1 /2)
(i) (i) (i)
l2 = hg(xi + h/2, yi + k1 /2, zi + l1 /2)
(i) (i) (i) (1.22)
k3 = hf (xi + h/2, yi + k2 /2, zi + l2 /2)
(i) (i) (i)
l3 = hg(xi + h/2, yi + k2 /2, zi + l2 /2)
(i) (i) (i)
k4 = hf (xi + h, yi + k3 , zi + l3 )
(i) (i) (i)
l4 = hg(xi + h, yi + k3 , zi + l3 ).

Example 1.2 Solve the following pair of differential equations


dy dz
= z and = y + xz at x = 0.2 given y(0) = 1, z(0) = 0 .
dx dx
Solution. Let h = 0.2. Here f (x, y, z) = z, g(x, y, z) = y + xz.
We calculate the values of k1 , k2 , k3 , k4 ; l1 , l2 , l3 , l4 as follows.
k1 = hf (x0 , y0 , z0 ) = 0.2 × 0 = 0
l1 = hg(x0 , y0 , z0 ) = 0.2 × (1 + 0) = 0.2
0.2
k2 = hf (x0 + h/2, y0 + k1 /2, z0 + l1 /2) = 0.2 × = 0.02
2
0.2 0.2
l2 = hg(x0 + h/2, y0 + k1 /2, z0 + l1 /2) = 0.2 × [(1 + 0) + (0 + 2 ) × (0 + 2 )]
= 0.2 × (1 + 0.1 + 0.1)
= 0.2020
0.202
k3 = hf (x0 + h/2, y0 + k2 /2, z0 + l2 /2) = 0.2 × = 0.02020
2
0.02 0.2 0.2020
l3 = hg(x0 + h/2, y0 + k2 /2, z0 + l2 /2) = 0.2 × [(1 + 2 ) + (0 + 2 ) × (0 + 2 )]
= 0.20402
k4 = hf (x0 + h, y0 + k3 , z0 + l3 ) = 0.2 × 0.20402 = 0.04080
l4 = hg(x0 + h, y0 + k3 , z0 + l3 ) = 0.2 × [(1 + 0.02020) + (0 + 0.2) × (0 + 0.20402)]
= 0.21220.
9
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Runge-Kutta Methods

Hence,
1
y(0.2) = y1 = y(0) + [k1 + 2(k2 + k3 ) + k4 ]
6
1
= 1 + [0 + 2(0.02 + 0.0202) + 0.0408] = 1.0202.
6
1
z(0.2) = z1 = z(0) + [l1 + 2(l2 + l3 ) + l4 ]
6
1
= 0 + [0.2 + 2(0.2020 + 0.20402) + 0.21220] = 0.20404.
6

1.5 Runge-Kutta method for a system of equations

The above method can be extended to solve a system of first order differential equa-
tions. Let us consider the following system of first order differential equations
dy1
= f1 (x, y1 , y2 , . . . , yn )
dx
dy2
= f2 (x, y1 , y2 , . . . , yn ) (1.23)
dx
··· ··················
dyn
= fn (x, y1 , y2 , . . . , yn )
dx
with initial conditions

y1 (x0 ) = y10 , y2 (x0 ) = y20 , . . . , yn (x0 ) = yn0 . (1.24)

In this problem, x is the independent variable and y1 , y2 , . . . , yn are n dependent


variables.
The above system of equations can be written as a vector notation as follows:
dy
= f (x, y1 , y2 , . . . , yn ) with y(x0 ) = y0 . (1.25)
dx
The fourth-order Runge-Kutta method for the equation (1.25) is
1
yj+1 = yj + [k1 + 2k2 + 2k3 + k4 ] (1.26)
6
where
       
k11 k12 k13 k14
       
 k21   k22   k23   k24 
k1 =  .  , k2 =  .  , k3 =  .  , k4 =  .  (1.27)
       
 ..   ..   ..   .. 
       
kn1 kn2 kn3 kn4
10
1.1. Euler’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

and

ki1 = hfi (xj , y1j , y2j , . . . , ynj )


ki2 = hfi (xj + h/2, y1j + k11 /2, y2j + k21 /2, . . . , ynj + kn1 /2)
ki3 = hfi (xj + h/2, y1j + k12 /2, y2j + k22 /2, . . . , ynj + kn2 /2)
ki4 = hfi (xj + h, y1j + k13 , y2j + k23 , . . . , ynj + kn3 )

for i = 1, 2, . . . , n.
Here, ykj is the value of the variable yk evaluated at xj .

1.6 Runge-Kutta method for second order IVP

The Runge-Kutta methods can be used to solve second order IVP by converting the
IVP to a pair of first order differential equations.
Let the second order differential equation be

a(x)y 00 + b(x)y 0 + c(x)y = f (x) (1.28)

and the initial conditions be

x = x0 , y(x0 ) = y0 , y 0 (x0 ) = z0 . (1.29)

To convert it to first order equation, let

y 0 (x) = z(x). (1.30)

Then y 00 (x) = z 0 (x). Therefore, the equation (1.29) reduces to


dy
=z
dx
dz 1
= [f (x) − b(x)z − c(x)y] = g(x, y, z) (1.31)
dx a(x)
with initial conditions

x = x0 , y(x0 ) = y0 , z(x0 ) = z0 . (1.32)

This is a pair of first order differential equations. Now, Runge-Kutta methods may
be used to solve this pair of equations (1.31) with initial conditions (1.32). The value
of y is the solution of the given IVP and z is the first order derivatives.
11
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Runge-Kutta Methods

Example 1.3 Find the value of y(0.1) for the following second order differential equa-
tion by fourth-order Runge-Kutta method.

y 00 (x) − 2y 0 (x) + y(x) = x + 1 with y(0) = 1, y 0 (0) = 0.

Solution. Substituting y 0 = z. Then the given equation reduces to z 0 − 2z + y = x + 1,


or z 0 = 2z − y + x + 1 = g(x, y, z) (say).
Therefore, y 0 = z and z 0 = (2z − y + x + 1).
Here, x0 = 0, y0 = 1, z0 = 0, h = 0.1.

k1 = h × z0 = 0.1 × 0 = 0
l1 = hg(x0 , y0 , z0 ) = 0.1 × [(2 × 0) − 1 + 0 + 1] = 0
k2 = h × (z0 + l1 /2) = 0.1 × 0 = 0
0 0.1
l2 = hg(x0 + h/2, y0 + k1 /2, z0 + l1 /2) = 0.1 × [(2 × 0) − (1 + ) + (0 + ) + 1]
2 2
= 0.1 × [−1 + 0.05 + 1] = 0.005
0.005
k3 = h × (z0 + l2 /2) = 0.1 × = 0.00025
2
l3 = hg(x0 + h/2, y0 + k2 /2, z0 + l2 /2)
= 0.1 × [0.005 − 1 + 0.05 + 1] = 0.0055
k4 = h × (z0 + l3 ) = 0.1 × 0.0055 = 0.00055
l4 = hg(x0 + h, y0 + k3 , z0 + l3 )
= 0.1 × [{2 × (0 + 0.0055)} − (1 + 0.00025) + (0 + 0.1) + 1] = 0.011075.

Therefore,

y(0.1) = y1
1
= y0 + [k1 + 2(k2 + k3 ) + k4 ]
6
1
= 1 + [0 + 2(0 + 0.00025) + 0.00055] = 1.000175
6
0 1
z(0) = y (0.1) = z(0) + [l1 + 2(l2 + l3 ) + l4 ]
6
1
= 0 + [0 + 2(0.005 + 0.0055) + 0.011075] = 0.005346.
6
The required value of y(0.1) is 1.000175. In addition, y 0 (0.1) is 0.005346.
12

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