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

Solutions of Ordinary Differential Equations−I

Dr. Sukanta Deb and Dr. Subhash Kumar


1

Learning Objectives:

• First Order Ordinary Differential Equations (ODEs): Initial Value Problems

• Solutions of Initial Value Problems

– Euler Method
– Modified Euler Method
– Runge-Kutta Second Order Method
– Runge-Kutta Fourth Order Method
2

Solution of Ordinary Differential Equations


Differential equations arise in many areas of science and engineering when dealing with the modeling of problems which
involve the change of some variable with respect to another. Most of these problems require the solution of an initial value
problem. The Initial value problem refers to the solution to a given differential equation that satisfies a given initial condition.
There exist many siuations where the differential equations that models the problem is difficult to solve exactly. For the
solutions of those differential equations one has to resort to the methods for approximating the solution to the original problem
[1].

Initail Value Problem for ODE

Let us consider the problem of solving a first order ODE of the form

dy
= f (x, y), x0 ≤ x ≤ xn , y(x0 ) = y0
dx
Such a problem is called the initial value problem because the initial value of the solution y(x0 ) = y0 is given. Since there
are many infinitely many values between x0 and xn , we will be concerned here to find approximations of the solution y(x) at
several specfified values of x in [x0 , xn ] [1]. Let us denote yi ≈ y(xi ). Divide [xi , xn ] into n intervals of length h (step size),
where h = xn −xn
0
.

The initial value problem can be formulated as follows:


Given
dy
1. dx = f (x, y), x0 ≤ x ≤ xn

2. The initial value y(x0 ) = y0


xn −x0
3. The step size h = n

Find yi , i = 1, 2, . . . , n. Here yi is the approximate value of y(xi ).

In this section the following well-known numerical methods for solving the initial value problem will be described:

• Euler Method

• Modified Euler Method

• Runge-Kutta Second Order Method

• Runge-Kutta Fourth Order Method

Euler’s Method
The Euler method is one of the simplest methods for solving the initial value problem. The method is derived from the Taylor
Series expansion of the function y(x). Taylor series expansion of y(x) of order n at x = xi+1 is given by

(xi+1 − xi )2 ′′ (xi+1 − xi )n n (xi+1 − xi )n+1 n+1


y(xi+1 ) = yxi + (xi+1 − xi )y ′ (xi ) + y (xi ) + · · · + y (xi ) + y (ξi ),
2! n! (n + 1)!

where xi ∈ [xi , xi+1 ]. Substituting h = xi+1 − xi , we get

h2 ′′ hn n hn+1 n+1
y(xi+1 ) = yxi + hy ′ (xi ) + y (xi ) + · · · + y (xi ) + y (ξi ),
2! n! (n + 1)!
3

Figure 2: Numerical integration of an ODE using the Euler’s method.

For n = 1, the above formula reduces to


h2 ′′
y(xi+1 ) = yxi + hy ′ (xi ) + y (ξ).
2
h2 ′′
The term 2 y (ξ) is called the remainder term. Neglecting the remainder term, we have

yi+1 = yi + hy ′ (xi )
⇒ yi+1 = yi + hf (xi , yi ), i = 0, 1, 2, . . . , n − 1.

This formula is known as the Euler method and can be used to approximate yi+1 . The implementation of the Euler method is
quite simple as it requires terms upto first order derivative in the Taylor series expansion. However, because of using only two
terms in the expansion the results obtained using the Euler’s method is not as accurate as the Taylor series expansion using
higher orders. Even for a reasonable accuaracy in the case of Euler’s method, the step size h needs to be very small [1, 2].

The Euler method was named after the pioneering Swiss mathematician and physicist Leon-
hard Euler (1707 − 1783). He has remarkable constributions in diverse areas such as infinites-
imal calculus, graph theory, mechanics, optics, fluid mechanics, astronomy and music theory.
The Euler method is the simplest explicit method for numerical integration of ordinary dif-
ferential equations with a given initial value. The Euler method is a first order method which
means that the local truncation error is h2 and the global error is h, where h is the step size.
A statement attributed to Pierre-Simon Laplace expresses Euler’s influence on mathematics:
"Read Euler, read Euler, he is the master of us all" (Source: Wikipedia). Leonhard Euler

Geometrical interpretation of the Euler’s method


The geometrical interpretation of the Euler’s method is shown in Fig. (2). Let us consider the ODE of the follwoing form:
dy
= f (x, y), y(x0 ) = y0 .
dx
Let y = g(x) be the exact analytical solution of the above equation. Let x0 , x1 , . . . , xn be equidistant values of x. The method
is based on the principle that that in a small interval a curve approximates nearly a straight line [1, 3]. To approximate the
4

curve at the point (x0 , y0 ), a tangent is drawn at the point (x0 , y0 ). The equation of the tangent at the point (x0 , y0 ) is given
by
 
dy
y − y0 = (x − x0 )
dx (x0 ,y0 )
⇒ y − y0 =f (x0 , y0 )(x − x0 )
⇒ y =y0 + (x − x0 )f (x0 , y0 )

This gives the y coordinate of any point on the tanget. Since the curve in the interval [x0 , x1 ] is approximated by the tangent,
the value of y on the curve corresponding to the value of x = x1 is given by the above equation. Substituting the value of
x = x1 , we get

y1 = y0 + (x1 − x0 )f (x0 , y0 )
⇒ y1 = y0 + hf (x0 , y0 )

Similarly, approximating the curve in the interval by a line [x1 , y1 ] through (x1 , y1 ) with slope f (x1 , y1 ), we can show that

y2 = y1 + hf (x1 , y1 )

In general, it can be shown that

yi+1 = yi + hf (xi , yi ), i = 0, 1, 2, . . . , n − 1

This is the formula for the Euler’s method.

Rules for generating yi+1 from yi in Euler’s Method

yi+1 =yi + hy ′ (xi )


⇒ yi+1 =yi + hf (xi , yi ), i = 0, 1, . . . , n − 1.

Example 1. Solve the following initial value problem to obtain approximations for y(0.01), y(0.02), y(0.03) and y(0.04)
using h = 0.01:
dy
= −y, y(0) = 1.
dx
Solution 1. Comparing
dy
= −y
dx
with
dy
= f (x, y),
dx
we have
f (x, y) = −y.

From the Euler’s method, we know that

yi+1 = yi + hf (xi , yi ), i = 0, 1, 2, . . .
5

where yi+1 = y(xi+1 ) = y(xi + h). Given y(0) = 1, i.e., at x0 = 0, y0 = y(x0 ) = y(0) = 1. We have to find the values of
y(0.01), y(0.02), y(0.03) and y(0.04), i.e, y1 , y2 , y3 and y4 .

When i = 0 :x1 = x0 + h = 0 + 0.01 = 0.01


y1 =y0 + hf (x0 , y0 )
⇒ y1 =1.0 + 0.01(−1) = 0.99
When i = 1 :x2 = x1 + h = 0.01 + 0.01 = 0.02
y2 =y1 + hf (x1 , y1 )
⇒ y2 =0.99 + 0.01(−0.99) = 0.9801

When i = 2 :x3 = x2 + h = 0.02 + 0.01 = 0.03


y3 =y2 + hf (x2 , y2 )
⇒ y3 =0.9801 + 0.01(−0.9801) = 0.9703
When i = 3 :x4 = x3 + h = 0.03 + 0.01 = 0.03
y4 =y3 + hf (x3 , y3 )
⇒ y3 =0.9703 + 0.01(−0.9703) = 0.9606

The exact analytic solution to the given differential equation can be obtained as follows:
dy
=−y
dx
dy
⇒ = − dx [Separting the variables]
y
Z Z
dy
⇒ = − dx
y
⇒ ln y = − x + c,

where c is a constant of integration to be determined from the given initial condition.


Given y(0) = 1, i.e., at x = 0, y = 1. Substituting these values into the above equation, we get

c = 0.

Therefore, the given equation reduces to

ln y = − x
⇒ y =e−x .

This is the required exact analytic solution. The plot of this solution is shown in Fig. (3) for x in the range [0, 1]. Also shown
in the figure are the overplotted exact and approximate values of y for x in the range [0.01, 0.04]. It can be seen from the figure
that the approximated values are quite closer to those obtained from the analytic solutions because of using smaller value of
h. This is remarkable. The approximated values can be made more accurate by choosing more and more smaller values of h
but this requirement causes hardship to the computer requiring extra compuational cost in solving the problem.
Example 2. Solve the following initial value problem with the help of Euler’s method to obtain the approximations for
y(0.25), y(0.50), y(0.75) and y(1.0) using h = 0.25:
dy
= x2 + 5, y(0) = 0.
dx
Compare the approximated values with those obtained from exact analytic solutions.
6

Solution of dy/dx=-y, y(0)=1


1.00

0.98
Exact value
Approx. value

0.96

y 0.94

0.92

0.90
0.00 0.02 0.04 0.06 0.08 0.10
x

dy
Figure 3: Plot of the solutions of the equation dx = −y, y(0) = 1 for x ∈ [0, 0.1]. The exact analytic soltion y = e−x is
shown here as a black solid line, whereas, the black and the red open circles denote the exact and the approximate values of y
at x = 0.01, 0.02, 0.03, 0.04, respectively.

Solution 2. Comparing
dy
= x2 + 5
dx
with
dy
= f (x, y),
dx
we have
f (x, y) = x2 + 5.

From the Euler’s method, we know that

yi+1 = yi + hf (xi , yi ), i = 0, 1, 2, . . .

where yi+1 = y(xi+1 ) = y(xi + h). Given y(0) = 0, i.e., at x0 = 0, y0 = y(x0 ) = y(0) = 0. We have to find the values of
y(0.25), y(0.50),y(0.75) and y(1), i.e, y1 ,y2 , y3 and y4 .

When i = 0 :x1 = x0 + h = 0 + 0.25 = 0.25


y1 =y0 + hf (x0 , y0 )
⇒ y1 =y0 + h x20 + 5


⇒ y1 =0.0 + 0.25 02 + 5 = 1.2500




When i = 1 :x2 = x1 + h = 0.25 + 0.25 = 0.50


y2 =y1 + hf (x1 , y1 )
⇒ y2 =y1 + h x21 + 5


⇒ y2 =1.2500 + 0.25(0.252 + 5) = 2.5156


7

When i = 2 :x3 = x2 + h = 0.50 + 0.25 = 0.75


y3 =y2 + hf (x2 , y2 )
⇒ y3 =y2 + h x22 + 5


⇒ y3 =2.5156 + 0.25(0.502 + 5) = 3.8281


When i = 3 :x4 = x3 + h = 0.75 + 0.25 = 1.0
y4 =y3 + hf (x3 , y3 )
⇒ y4 =y3 + h x23 + 5


⇒ y3 =3.8281 + 0.25(0.752 + 5) = 5.2188

The exact solution to the given differential equation can be obtained as follows:

dy
=x2 + 5
dx
⇒ dy = x2 + 5 dx

Z Z
x2 + 5 dx

⇒ dy =

x3
⇒y= + 5x + c,
3
where c is a constant of integration to be determined from the given initial condition.
Given y(0) = 0, i.e., at x = 0, y = 0. Substituting these values into the above equation, we get

c = 0.

Therefore, the given equation reduces to

x3
y= + 5x.
3
This is the required exact analytic solution. The plot of this solution is shown in Fig. (4) for x in the range [0, 1]. Also shown
in the figure are the overplotted exact and approximate values of y for x in the range [0.25, 1.0]. It can be seen from the figure
that the succesive approximated values for y start deviating more and more from the analytic solutions because of using larger
value of h.

Local and global truncation errors


In the solution of initial value problem, the approximations obtained by a numerical method are subjected to two types of
errors [4]. The first type of error is the local truncation error which is generated at every step due to the truncation of the
series to solve the problem. The local truncation error generated in the first step is carried forward to the next step and thereby
propagates through the numerical solution to the final step. As each step produces a new local truncation error, these errors
accumulate as the numerical calculation progresses from one iteration to the next. The total error at any step, which is the sum
of the local truncation error and the propagated errors, is called the global truncation error[4].

The Errors in Euler’s Method


Let us now estimate the magnitude of the truncation error associated with the Euler’s method. We have learnt from the above
that the Euler series method was obtained by truncating the Taylor series

h2 ′′
yi+1 = y(xi+1 ) = y(xi + h) = y(xi ) + hy ′ (xi ) + y (xi ) + . . .
2
8

Solution of dy/dx=x2+5, y(0)=0


6

Exact value
Approx. value
4

y 2

0
0.00 0.25 0.50 0.75 1.00
x

3
dy
Figure 4: Plot of the solutions of the equation dx = x2 + 5, y(0) = 0 for x ∈ [0, 0.1]. The exact analytic soltion y = x3 + 5x
is shown here as a black solid line, whereas, the black and the red open circles denote the exact and the approximate values of
y at x = 0.25, 0.50, 0.75, 1.0, respectively.

2
after two terms. Therefore, in obtaining the Euler’s method, the first term neglected is h2 y ′′ (xi ). So the local truncation
2
error is el = h2 y ′′ (ξ), where ξ ∈ [xi , xi+1 ]. In this case we say that the local truncation error is of the order of h2 , usually,
written as O(h2 ). On the other hand, the global error is defined as the difference between the true solution at y(xi ) and the
approximate solution yi at x = xi . The global error is denoted as eg = |y(xi ) − yi |. The following theorem shows that the
global error eg is of the order of h in the case of Euler’s method.

Theorem: (Global Error bound for the Euler method)


Let y(x) be the unique solution of the initial value problem given by

dy
= f (x, y), y(x0 ) = α
dx
x0 ≤ x ≤ xn , − ∞ < y < ∞

Let L and M be two numbers such that [1]



∂f (x, y) ′′
∂y ≤ L, and, |y (x) ≤ M | in [x0 , xn ].

Then the global error eg satisfies [5]

hM  L(xi −x0 ) 
|eg | = |y(xi ) − yi | ≤ e − 1 ∼ O(h).
2L
Knowing the equalities L and M , the step size h needed to achieve a certain accuracy can be determined.

Thus we have found from the above analysis that the global error bound for the Euler’s method depends on h, whereas,
the local error bound depends on h2 .

Example 3. In solving the following initial value problem, determine how small the step size h should be chosen so that the
9

error does not exceed 10−4 .


dy x2 + y 2
= , y(0) = 0
dx 2
0 ≤ x ≤ 1, − 1 ≤ y(x) ≤ 1.

Solution 3. • Computation of L: Comparing


dy x2 + y 2
=
dx 2
with
dy
= f (x, y),
dx
we get
x2 + y 2
f (x, y) =
2
∂f
⇒ =y
∂y

∂f
⇒ ≤ 1, ∀y
∂y
which implies that
L =1.

• Computation of M :

dy
y′ = = f (x, y) (Given).
dx
By implicit differentiation, we have
∂f ∂f
y ′′ = +f
∂x ∂y
2
(x + y2)
⇒ y ′′ =x + y
2
y 2
x + y2

⇒ y ′′ =x +
2
Therefore,
y 2 
⇒ |y ′′ | = x + x + y 2 ≤ 2, for − 1 ≤ x ≤ 1

2
⇒ M = 2.

Hence, the global error bound at x = xi is given by


hM  L(xi −x0 ) 
|eg | ≤ e −1
2L
2h  (xi −0) 
⇒ |eg | ≤ e −1
2
⇒ |eg | ≤h(e − 1)

So for the error not to exceed 10−4 , we must have

h(e − 1) <10−4
10−4
h<
e−1
h <5.8198 × 10−5 .
10

Modified Euler method


On of the important disadvantages with the Euler’s method is the its accuracy and requires an exteremly small step size. This
problem is overcome in the modified Euler’s method by considering one more extra term of the Taylor series expansion and
expressing the second order derivative y ′′ by the forward-difference apprximation as
yn+1 − yn
y ′′ = ,
h
which has an error of O(h) and the error term of the Taylor series expansion is written as O(h3 ). Therefore

h2 yn+1
 ′
− yn′

yn+1 = yn + hyn′ + + O(h) + O(h3 )
2! h
 ′ ′
y + yn+1

⇒ yn+1 = yn + h n + O(h3 )
2

This show that the error of one step, i.e., local error of the modified Euler method is O(h3 ). Hence the global error of the
modfied Euler method is O(h2 ). It can be shown that for any numerical ODE integration technique, the global truncation
error is one order of magnitude less than the local truncation error for that method [1].

Geometrical interpretation of the modified Euler’s method


The geometrical interpretation of the modified Euler’s method is depicted in Fig. (5). In the modified Euler’s method, better
estimate of the solution is obtained by taking average slope in the interval [x0 , x1 ] instead of slope at a point. In order to
approximate the curve in the interval [x0 , x1 ], a line through the point (x0 , y0 ) is drawn whose slope is the average of the
slopes at (x0 , y0 ) and (x1 , y11 ), where y1 = y0 + hf (x0 , y0 ). Let L1 be the at (x0 , y0 ) with slope f (x0 , y0 ) and L2 be the line
at (x1 , y1 ) with a slope f (x1 , y11 ). Let L̄ be the line whose slope is equal to the average of the slopes f (x0 , y0 ) and f (x1 , y11 )
[3]. Then the line L through (x0 , y0 ) and parallel to L̄ is used to approximate the curve in the interval [x0 , x1 ]. Threfore, the
ordinate of the point B will be given by the value y1 . Now the equation of the line AL is given by
 ¯ 
dy
y1 − y0 = (x1 − x0 )
dx x0 ,y0
1
f (x0 , y0 ) + f (x1 , y11 ) (x1 − x0 )

⇒ y1 − y0 =
2
h
f (x0 , y0 ) + f (x1 , y11 )

⇒ y1 = y0 +
2
A generalised form of the Euler’s modified formula is

(n+1) h
y1 = y0 + [f (x0 , y0 ) + f (x1 , y1n ); n = 0, 1, . . . ]
2
where y1n is the nth approximation to y1 . The above iteration formula can be started by choosing from Eulers’s formula

y11 = y0 + hf (x0 , y0 ).

Since this formula attempts to correct the values of yn+1 using the predicted value of yn+1 by Euler’s method, it is classified
as a one-step predictor-corrector method.
11

Figure 5: Numerical integration of ODE using the modified Euler’s method.

Rules for generating yi+1 from yi in Modified Euler’s Method

1
yi+1 = yi + [k1 + k2 ] , (1)
2
where

k1 =hf (xi , yi )
k2 =hf (xi + h, yi + k1 )

Therefore, equation (1) can be written as

h
yi+1 = yi + [f (xi , yi ) + f (xi + h, yi + hf (xi , yi ))]
2

Local error in the modified Euler method


Since in deriving the modifed Euler method, we have neglected the terms involving h3 and higher powers of h, the local error
for this method is O(h3 ). Thus with the modified Euler method, larger step-size h can be used than the Euler method to obtain
the same accuracy.

Example 4. Solve the following initial value problem for x ∈ [0, 1] with h = 0.5 using the Euler’s modified method:

dy
= ex , y(0) = 1.
dx
Solution 4. Comparing
dy
= ex
dx
with
dy
= f (x, y),
dx
12

we have
f (x, y) = ex .
From the Modified Euler’s method, we know that
1
yi+1 = yi + [k1 + k2 ] , (2)
2
where

k1 =hf (xi , yi )
k2 =hf (xi + h, yi + k1 )

Given y(0) = 1, i.e., at x0 = 0, y0 = y(x0 ) = y(0) = 1.0 We have to find the values of y(0.5), y(1), i.e., y1 , y2 .

When i = 0 :x1 = x0 + h = 0 + 0.5 = 0.5


k1 = hf (x0 , y0 ) = 0.5ex0 = 0.5
k2 = hf (x0 + h, y0 + k1 ) = 0.5 ex0 +h


⇒ k2 = 0.5e0.5 = 0.8244
1
y1 = y0 + (k1 + k2 )
2
⇒ y1 = 1 + 0.5 (0.5 + 0.8244)
⇒ y1 = 1.6622
When i = 1 :x2 = x1 + h = 0.5 + 0.5 = 1.0
k1 = hf (x1 , y1 ) = 0.5ex1 = 0.5e0.5 = 0.8244
k2 = hf (x1 + h, y1 + k1 ) = 0.5 ex1 +h


⇒ k2 = 0.5e0.5+0.5 = 1.3591
1
y2 = y1 + (k1 + k2 )
2
⇒ y2 = 1.6622 + 0.5 (0.8244 + 1.3591)
⇒ y2 = 2.7539

Therefore,
y1 = y(0.5) = 1.6622, y2 = y(1.0) = 2.7539

Example 5. Solve the following initial value problem for approximations to y(0.01) and y(0.02) with h = 0.01 using the
modified Euler’s method:
dy
= x + y, y(0) = 1.
dx
Solution 5. Comparing
dy
=x+y
dx
with
dy
= f (x, y),
dx
we have
f (x, y) = x + y.
From the modified Euler’s method, we know that
1
yi+1 = yi + [k1 + k2 ] , (3)
2
13

where

k1 =hf (xi , yi )
k2 =hf (xi + h, yi + k1 )

Given y(0) = 1, i.e., at x0 = 0, y0 = y(x0 ) = y(0) = 1.0 We have to find the values of y(0.01), y(0.02), i.e., y1 , y2 .

When i = 0 :x1 = x0 + h = 0 + 0.01 = 0.01


k1 = hf (x0 , y0 ) = 0.01(0 + 1) = 0.01
k2 = hf (x0 + h, y0 + k1 ) = 0.01f (0.01, 1 + 0.01)
⇒ k2 = 0.01 × (0.01 + 1.01) = 0.0102
1
y1 = y0 + (k1 + k2 )
2
⇒ y1 = 1 + 0.5 (0.01 + 0.0102)
⇒ y1 = 1.0101

When i = 1 :x2 = x1 + h = 0.01 + 0.01 = 0.02


k1 = hf (x1 , y1 ) = h (x1 + y1 ) = 0.01(0.01 + 1.0101) = 0.0102
k2 = hf (x1 + h, y1 + k1 ) = 0.01f (0.02, 1.0101 + 0.0102)
⇒ k2 = 0.01(0.02 + 1.0203) = 0.0104
1
y2 = y1 + (k1 + k2 )
2
⇒ y2 = 1.0101 + 0.5 (0.0102 + 0.0104)
⇒ y2 = 1.0204

Therefore,
y1 = y(0.01) = 1.0101, y2 = y(1.0) = 1.0204

Runge Kutta method

The Runge-Kutta methods were named after two German mathematicians Carl David
Tolmé Runge (1856 − 1927) and Martin Wilhelm Kutta (1867 − 1944) who developed
these methods aroud 1900. The basic principle of the Runge-Kutta methods is to find
yi+1 by evaluating the derivative of y not only at the initial point (xi , yi ) but also at
the end point and some intermediate points. The increment ∆yi is some kind of an
average of all these derivatives. In the case of Runge-Kutta second order method, the
derivatives are evaluated at two points, one at the initial point (xi , yi ) and the other at
Runge and Kutta
the midpoint of the interval [xi , xi+1 ], i.e., at xi + h2 . In the case of Runge-Kutta fourth
order method, the derivative is evaluated at four points, once at the initial point, twice
at the trial midpoint and once at the trial end point. These four derivatives consitute one Runge-Kutta step resulting in
the final value for yi+1 = yi + 61 (k1 + 2k2 + 2k3 + k4 ). (Photo credit: Wikipedia.)

The Euler’s method is the simples to implement. However even for a reasonable accuracy the step size h needs to be very
small. However, the difficulties with the higher order Taylor series methods are that the derivatives of higher orders of f (x, y)
14

need to be computed, which are very often difficult to compute. The Runge-Kutta method aim at achieving the accuracy of
higer order Taylor series methods without computing the higher order derivatives. Let us take

yi+1 = yi + α1 k1 + α2 k2 .

k1 and k2 are given by

k1 =hf (xi , yi )
k2 =hf (xi + αh, yi + βk1 ).

The constants α1 , α2 and α, β are to chosen in such a way that the formula is as accurate as the Taylor’s series method of as
high as possible. Now let us evaluate f (xi + αh, yi + βk1 ) using the Taylor series expansion given by
∂f ∂f
f (xi + αh, yi + βk1 ) =f (xi , yi ) + αh + βk1 [Neglecting higher order terms]
∂x ∂y
∂f ∂f
⇒ f (xi + αh, yi + βk1 ) =f (xi , yi ) + αh + βhf (xi , yi )
∂x ∂y
Therefore,

yi+1 =yi + α1 hf (xi , yi ) + α2 hf (xi + αh, yi + βk1 )


 
2 ∂f ∂f
⇒ yi+1 =yi + hf (xi , yi )(α1 + α2 ) + α2 h α + βf (x, y) (4)
∂x ∂y
Now we know that the Taylor series expansion of yi+1 = y(xi+1 ) = y(xi + h) is given by

yi+1 =y(xi + h)
h2 ′′
⇒ yi+1 =y(xi ) + hy ′ (xi ) + y (xi ) + . . .
2! 
h2 d ′

⇒ yi+1 =y(xi ) + hf (xi , yi ) + (y (xi ))
2 dx
2
 
h d
⇒ yi+1 =yi + hf (xi , yi ) + (f (xi , yi )) [∵ y ′ (xi ) = f (xi , yi )] (5)
2 dx
Also, we know that
∂f (xi , yi ) ∂f (xi , yi )
df (xi , yi ) = dx + dy
∂x ∂y
df (xi , yi ) ∂f (xi , yi ) ∂f (xi , yi ) ′
⇒ = + yi (x)
dx ∂x ∂y
df (xi , yi ) ∂f (xi , yi ) ∂f (xi , yi )
⇒ = + f (xi , yi )
dx ∂x ∂y
df (xi ,yi )
Substituting this value of dx into the equation (5), we have

h2 ∂f (xi , yi ) ∂f (xi , yi )
 
yi+1 =yi + hf (xi , yi ) + + f (xi , yi ) (6)
2 ∂x ∂y
Comparing equations (4) and (5), we get

α1 + α2 =1
1
α2 α =
2
1
α2 β = .
2
15

Here, the number of variables (α1 , α2 , α, β, viz. 4 in number) exceed the number of equations (viz., 3 in number). Therefore,
the equations have inifnitely many solutions. It is quite clear from the above three equations that if we set α = β =
arbitrary value, then the remaining parameters (α1 , α2 ) can be determined uniquely.

• Runge-Kutta second order method:


Let us put
1
α1 = 0, α=β=
2
α2 = 1

Then we have

yi+1 =yi + α1 k1 + α2 k2
⇒ yi+1 =yi + α2 k2
⇒ yi+1 =yi + α2 hf (xi + αh, yi + βk1 )
h k1
⇒ yi+1 =yi + hf (xi + , yi + )
2 2
This is the required formula for the Runge-Kutta second order method. It should be noted that several Runge-Kutta
second order formulas can be constructed considering various arbitrary values of α and β.

• Modified Euler method:


Let us put
1
α1 = α2 =
2
α = β = 1.

Then we have

yi+1 =yi + α1 k1 + α2 k2
⇒ yi+1 =yi + α1 hf (xi , yi ) + α2 hf (xi + αh, yi + βk1 )
h h
⇒ yi+1 =yi + f (xi , yi ) + f (xi + h, yi + k1 )
2 2
h h
⇒ yi+1 =yi + f (xi , yi ) + f (xi + h, yi + hf (xi , yi ))
2 2
h
⇒ yi+1 =yi + [f (xi , yi ) + f (xi + h, yi + hf (xi , yi ))]
2
This is the required formula for the modified Euler method.

Second Order Runge-Kutta (Midpoint) Method


Let us consider the differential equation
y ′ = f (x, y), y(x0 ) = y0 .
Let h be the stepsize the in the range x0 ≤ x ≤ xn . The solution to the above differential equation is given by the following
formula:

yi+1 = yxi +1 = y(xi + h) = yi + ∆yi .

The increment ∆yi is given by


∆yi = k2 .
16

k1 and k2 are given by

k1 = hf (xi , yi )
h k1
k2 = hf (xi + , yi + ).
2 2
k1 and k2 are known as the stages of the Runge-Kutta method. This method is also called the midpoint method as it uses the
slope at the midpoint of the interval, i.e., xi + h2 to calculate the approximation to y(xi+1 ). The local truncation error in the
case of Runge-Kutta second order method is O(h3 ).
In the Runge-Kutta methods, one finds yi+1 by evaluating the derivatives of y not only at the initial points (xi , yi ), as
was done in Euler’s method, but also at the end point and some other intermediate points. The increment ∆y is the weighted
average of all these derivatives in each subinterval.

Rules for generating yi+1 from yi in Runge-Kutta second order (Midpoint method):

yi+1 =yi + k2 , (7)

where

k1 =hf (xi , yi )
h k1
k2 =hf (xi + , yi + ).
2 2
Therefore, equation (7) can be written as

h k1
yi+1 = yi + hf (xi + , yi + )
2 2
 
h h
⇒ yi+1 = yi + hf xi + , yi + f (xi , yi ) , i = 0, 1, . . . , n − 1.
2 2

Example 6. Solve the following initial value problem for approximations to y(0.5) and y(1.0) with h = 0.05 using the
Runge-Kutta second order method:
dy
= ex , y(0) = 1.
dx
Solution 6. Comparing
dy
= ex
dx
with
dy
= f (x, y),
dx
we have
f (x, y) = ex .

From the Runge-Kutta second order method, we know that

yi+1 = yi + k2

where

k1 =hf (xi , yi )
h k1
k2 =hf (xi + , yi + )
2 2
17

Given y(0) = 1, i.e., at x0 = 0, y0 = y(x0 ) = y(0) = 1.0 We have to find the values of y(0.5), y(1.0), i.e., y1 , y2 .

When i = 0 :x1 = x0 + h = 0 + 0.5 = 0.5


k1 = hf (x0 , y0 ) = 0.5ex0 = 0.5e0 = 0.5
h k1
k2 = hf (x0 + , y0 + ) = 0.5e0.5/2 = 0.6420
2 2
y1 = y0 + k2
⇒ y1 = 1 + 0.6420
⇒ y1 = 1.6420

When i = 1 :x2 = x1 + h = 0.5 + 0.5 = 1.0


k1 = hf (x1 , y1 ) = h (x1 + y1 ) = 0.5e0.5 = 0.8244
h k1
k2 = hf (x1 + , y1 + ) = 0.5e0.75 = 1.0585
2 2
y2 = y1 + k2
⇒ y2 = 1.6420 + 1.0585
⇒ y2 = 2.7005

Therefore,
y1 = y(0.5) = 1.6420, y2 = y(1.0) = 2.7005

Runge-Kutta fourth order method


The Runge-Kutta fourth order method is the widely used method because of its high accuracy in obtaining the approximated
values as compared to the Euler’s method, modified Euler’s method and Runge-Kutta second order methods. The method is
obtained from the Taylor series expansion of order 4 by approximating the second, third and fourth derivatives. The local
truncation error in this case is O(h5 ). Let us consider a differential equation of the form

y ′ = f (x, y), y(x0 ) = y0 .

The solution to the above differential equation is obtained from the following formula:

yi+1 = y(xi+1 ) = y(xi + h) = yi + ∆yi ,

where the increment ∆yi is given by


1
∆yi = (k1 + 2k2 + 2k3 + k3 ),
6
where

k1 = hf (xi , yi )
h k1
k2 = hf (xi + , yi + )
2 2
h k2
k3 = hf (xi + , yi + )
2 2
k4 = hf (xi + h, yi + k3 ).

Geometrically, for the interval [xi , xi+1 ], k1 represents aprroximation for slope of the left end of the interval, k2 and k3
describe two approximations of the slope in the middle of the interval, whereas k4 corresponds to the slope at the right.
18

Rules for generating yi+1 from yi in Runge-Kutta fourth order method:

yi+1 = yi + ∆yi (8)

where ∆yi is given by


1
∆yi = [k1 + 2k2 + 2k3 + k3 ] ,
6
where k1 , k2 , k3 and k4 are given by

k1 = hf (xi , yi )
h k1
k2 = hf (xi + , yi + )
2 2
h k2
k3 = hf (xi + , yi + )
2 2
k4 = hf (xi + h, yi + k3 ).

Therefore, equation (8) can be written as

1
yi+1 = yi + [k1 + 2k2 + 2k3 + k3 ] , i = 0, 1, 2, . . . , n − 1.
6

Example 7. Solve the initial value problem to obtain approximations for y(0.01) using the Runge-Kutta fourth order method
with h = 0.01:
dy
= x + y, y(0) = 1.
dx
Solution 7. Comparing
dy
=x+y
dx
with
dy
= f (x, y),
dx
we have
f (x, y) = x + y.

From the Runge-Kutta fourth order method, we know that


1
yi+1 = yi + [k1 + 2k2 + 2k3 + k3 ] ,
6
where k1 , k2 , k3 and k4 are given by

k1 = hf (xi , yi )
h k1
k2 = hf (xi + , yi + )
2 2
h k2
k3 = hf (xi + , yi + )
2 2
k4 = hf (xi + h, yi + k3 ).
19

Given y(0) = 1, i.e., at x0 = 0, y0 = y(x0 ) = y(0) = 1.0. We have to find the values of y(0.01), i.e., y1 .

When i = 0 :x1 = x0 + h = 0 + 0.5 = 0.5


k1 = hf (x0 , y0 ) = 0.01f (0, 1) = 0.01 × 1 = 0.01
 
h k1 0.01 0.01 0.01 (1 + 0.01)
k2 = hf (x0 + , y0 + ) = 0.01f ( ,1+ ) = 0.01 + = 0.0101
2 2 2 2 2 2
h k2 h k2
k3 = hf (x0 + , y0 + ) = h((x0 + + y0 + ) = 0.0101005
2 2 2 2
k4 = hf (x0 + h, y0 + k3 ) = h(x0 + h + y0 + k3 ) = 0.01020100
Therefore,
1
y1 =y0 + (k1 + 2k2 + 2k3 + k4 )
6
⇒ y1 =1.0101100334

Therefore
y1 = y(0.01) = 1.010100334.

Example 8. Solve the initial value problem to obtain approximations for y(0.1) using the Runge-Kutta fourth order method
with h = 0.1:
dy
= y − x, y(0) = 2.
dx
Solution 8. Comparing
dy
=y−x
dx
with
dy
= f (x, y),
dx
we have
f (x, y) = y − x.

From the Runge-Kutta fourth order method, we know that


1
yi+1 = yi + [k1 + 2k2 + 2k3 + k3 ] ,
6
where k1 , k2 , k3 and k4 are given by

k1 = hf (xi , yi )
h k1
k2 = hf (xi + , yi + )
2 2
h k2
k3 = hf (xi + , yi + )
2 2
k4 = hf (xi + h, yi + k3 ).
20

Given y(0) = 2, i.e., at x0 = 0, y0 = y(x0 ) = y(0) = 2.0. We have to find the values of y(0.1), i.e., y1 .

When i = 0 :x1 = x0 + h = 0 + 0.2 = 0.2


k1 = hf (x0 , y0 ) = 0.1f (0, 2) = 0.1(2 − 0) = 0.2
h k1 0.2
k2 = hf (x0 + , y0 + ) = 0.1f (0.05, 2 + ) = 0.2050
2 2 2
h k2 h k2
k3 = hf (x0 + , y0 + ) = h((x0 + + y0 + ) = 0.20525
2 2 2 2
k4 = hf (x0 + h, y0 + k3 ) = h(x0 + h + y0 + k3 ) = 0.21503
Therefore,
1
y1 =y0 + (k1 + 2k2 + 2k3 + k4 )
6
1
⇒=2.0 + (0.2 + 2(0.2050) + 2(0.20525) + 0.21503)
6
⇒ y(0.1) =2.2052

Therefore
y1 = y(0.1) = 2.2052.

Exercise
1. Problems based on Euler’s Method:

Exercise 1. Solve the folllowing the inigtial value problems to obtain y(0.1), y(0.2) and y(0.3):
dy
(a) + 2y = 0, y(0) = 1
dx
dy
(b) − 1 = y2, y(0) = 0.
dx
Exercise 2. Solve the following inittial value problems in the range 0 ≤ x ≤ 0.8 with h = 0.2 and compare the results
with the exact solution at x = 0.8.
yy ′ = x, y(0) = 1.

Exercise 3. Solve the following initial value problem for y(0.2) with h = 0.1:

y ′ = x(y + 1), y(0) = 1

Find the estimates of the error for y(0.2) if the exact solution is given by
2
y = ex /2
− 1.

Exercise 4. Solve the following initial value problem for y(0.2) with h = 0.2:

y ′ = 2x + cos y, y(0) = 1.

Exercise 5. Solve the following initial value problem for y(0.2), y(0.4) with h = 0.2:

y ′ = x + y, y(0) = 0.

2. Problems based on Euler Modified Method:


21

Exercise 6. Solve the following initial value problem for y(0.02), y(0.04), y(0.06) using h = 0.02:
dy
= x2 + y, y(0) = 1.
dx
Exercise 7. Solve the following initial value problem for x ∈ [0, 0.3] using h = 0.1:
dy
= x + y, y(0) = 1.
dx
Compare with the exact solution
y(x) = 2ex − x − 1.

Exercise 8. Solve the following initial value problem to obtain approximations to y(0.2) and y(0.4) using h = 0.2:
dy
= −2xy 2 , y(0) = 1.
dx
Compare the numerical approximations with the exact solution
1
y(x) = .
1 + x2
Exercise 9. Solve the following initial value problem for y(0.2) using h = 0.1:
dy
= y − x2 + 1, y(0) = 0.5.
dx
Exercise 10. Solve the following initial value problem for y(0.5) using h = 0.1:
dy
= y 2 − x2 + 1, y(0) = 1.
dx
3. Problems based on Runge-Kutta second order method

Exercise 11. Solve the following initial value problem to obtain approximations to y(0.1), y(0.2) using h = 0.1:
dy
= y − x, y(0) = 2.
dx
Compare the numerical solutions with the exact analytic solution given by

y = x + 1 + ex .

Exercise 12. Solve the following initial value problem to obtain approximations to y(0.2), y(0.4) and y(0.6) using
h = 0.2:
dy
= 1 + y 2 , y(0) = 0.
dx
Exercise 13. Solve the following initial value problem to obtain approximations to y(0.2), y(0.4) and y(0.6) using
h = 0.2:
dy
= x3 + y, y(0) = 2.
dx
Exercise 14. Solve the following initial value problem to obtain the approximations for y in the range x ∈ [0.5, 1.0]
using h = 0.1:
dy
10 = x2 + y 2 , y(0) = 1.
dx
Exercise 15. Solve the following initial value problem to obtain approximations to y(0.5) using h = 0.25:
dy
= 3 sin xy, y(0) = −1.
dx
Compare the result with that obtained from the exact analytical solution.
22

4. Problems based on Runge-Kutta fourth order Method

Exercise 16. Solve the following initial value problem to obtain approximations to y in the interval [1, 1.5] using
h = 0.1:
dy
= x3 + y, y(0) = 2.
dx
Exercise 17. Obtain the solution at x = 0.8 for the following ODE:
dy √
= x + y, y(0.4) = 0.41
dx
assuming h = 0.2.

Exercise 18. Obtain the approximate value of y at x = 1 for the following initial value problem using h = 0.2:
dy y−x
= , y(0) = 1.
dx y+x
Exercise 19. Obtain the approximations to y having x ∈ [0.1, 0.4] for the following initial value problem with h = 0.1:
dy
= x cos 2y, y(0) = 1.
dx
Exercise 20. Solve the following initial value problem to find the approximations for y(0.25) and y(0.5) using h =
0.25:
dy
= 3x2 y − 4y, y(0) = −1.
dx
Compare the results with those obtained from the exact analytical solutions.

Summary
In this chapter, various methods for solving initial value problems using the methods such as Euler’s method, modified Euler’s
method, Runge-Kutta second order and Runge-Kutta fourth order methods have been discussed. Simple derivations of Euler’s
method, modified Euler’s method and Runge-Kutta second order methods have been provided along with their geometrical
interpretations. The derivation of Runge-Kutta fourth order method was not attempted here because of it’s being exceedingly
complicated. However, the geometrical interpretation of Runge-Kutta fourth order method has been elaborated. A number of
worked out examples have been provided in order to have a clear understanding of these methods in the numerical integration
of ordinary differential equations. Since ordinary differential equations arise almost in all branches of science and engineering,
these methods will prove to be useful in the modeling of an underlying physical phenomenon involving ordinary differential
equations.

References
[1] Richard L. Burden and J. Douglas Faires. Numerical Analysis: 4th Ed. PWS Publishing Co., Boston, MA, USA, 1989.

[2] S.S. Sastry. Introductory Methods of Numerical Analysis. Prentice-Hall of India Private Limited, 2005.

[3] M. Goyal. Computer Based Numerical & Statistical Techniques. Laxmi Publications Pvt Limited, 2006.

[4] Michael R. King and Nipa A. Mody. Numerical and Statistical Methods for Bioengineering: Applications in MATLAB.
Cambridge University Press, New York, NY, USA, 1st edition, 2010.

[5] C. William Gear. Numerical Initial Value Problems in Ordinary Differential Equations. Prentice Hall PTR, Upper Saddle
River, NJ, USA, 1971.

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