0% found this document useful (0 votes)
120 views158 pages

Chapter 11-15

1) Numerical differentiation is needed when the function is unknown and only discrete function values are known, or when the function is too complicated to differentiate analytically. 2) The forward difference quotient approximates the derivative using two points, while the central difference quotient uses three points for a more accurate approximation with less truncation error. 3) Higher-order formulas using more points provide even more accurate approximations but are more complex to derive. The tradeoff between truncation error and round-off error must be considered when choosing the step size h.

Uploaded by

Farida Nusrat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views158 pages

Chapter 11-15

1) Numerical differentiation is needed when the function is unknown and only discrete function values are known, or when the function is too complicated to differentiate analytically. 2) The forward difference quotient approximates the derivative using two points, while the central difference quotient uses three points for a more accurate approximation with less truncation error. 3) Higher-order formulas using more points provide even more accurate approximations but are more complex to derive. The tradeoff between truncation error and round-off error must be considered when choosing the step size h.

Uploaded by

Farida Nusrat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 158

1111!

Numerical
Differentiation

NEED AND SCOPE


Need for differentiation of a function arises quite often in engineering
and scientific problems. If the function has a closed form representation
in terms of standard calculus, then its derivatives can be found exactly.
However, in many situations, we may not know the exact function. What
we know is only the values of the function at a discrete set of points. For
instance, we are given the distance travelled by a moving object at some
regular time intervals and asked to determine its velocity at a particular
time. I n some other instances, the function is known but it is so compli-
cated that an analytic differentiation is difficult (if not impossible). In
both these situations, we seek the help of numerical techniques to obtain
the estimates of function derivatives. The iqjd of obtaining the de-
rivativeqaj
Ire iknown as
..frentiojon are essentially two situations where numerical
differentiation is required. They are:
i/ The function values are known but the function is unknown. Such
/ functions are called tabula/ed function.
2. The function to be differentiated is complicated and, therefore, it is
7/ d ifficult to differentiate
in this chapter, we discus's various numerical differentiation methods
that cou.ld be applied to both tabulated and continuous functions.
Remember that while analytical methods give exact answers, the nu-
merical techniques provide only approximations to derivatives, Numeri -
cal differentiation methods are very sensitive to roundoff errors, in
Numerical Methods
addition to the truncation error introduced by the methods themselves
Therefore, we also discuss the errors and ways to minimise them.

DIFFERENTIATING CONTINUOUS FUNCTIONS


the derivative
We diSCUSS here the numerical process of apprifidmating
f'(x) of a function f(x), when the function itself is available.
Forward Difference Quotient
Consider a small increment Ax = Ii in x. According to Taylor's theorem,
we have

f(x + h) = f(x) hf'(x) + f"(0) (111)

for x 0 !5 x - h. By rearranging the terms, we get


(11.2)

Thus, if h is chosen to be sufficiently small, f'(x) can be approximated by


(11.3)

with a truncation error of


11.4)

Equation (11.3) is called the first order forward diftrence qzwioflt. This
is also known as two-prnnt ftrmula. The truncation error is in the order
of h and can be decreased by decreasing h.
Similarly, we can show that the first-order backward difference quo-
tient is
(11.5)

Estimate appromate derivative of f(x) x21 at x , for h 0.2, 0.1,


0.05 and 0.01 using the first-order forward difference formula.

f()L±-L-2
Therefore,
[(1 ii.) -1(1:)
f(1) h
Numerical DifferentiatIon 349
Derivative approximations are tabulated below:

Error
0.2 2.2
0.1 2.1
o.os j 2.05 (Hj5
L 0,01 t 2.01

Note that the correct answer is 2. The derivative approximation ap-


proaches the exact value as ii decreases. The truncation error decreases
proportionally with decrease in h. There is no roundoff error.

•, 9 ntra I Difference Quotient


Note that Eq. (11.3) was obtained using the linear approximation tof(x),
This would give large truncation errors if the functions were of higher
order. In such cases, we can reduce truncation errors for a given h by
using a quadratic approximation, rather than a linear one. This can he
achieved by taking another term in Taylor's expansion. i.e..

f(x h) = f(x) + hf'(x) i f"(x) +.h3 f"(0 1 ) ( 11.6)

Similarly,

f(x-h)=f(x) hf(x)f_-_f'(x) hR
: t"(0 1 ) ( 11.7)
Subtracting Eq. (11.7) from Eq. (11.6), we obtain

f(x +h) -f( x h)=2hf'(x)+-[fr"(91)+f"(82)] (11.8)

Thus, we have

Li1ii
with the truncation error of
/2
f U)

h2
(11.9)

E (h) = -j-- If "(0 ) + [(02)] --f"(0)


which is of order h 2. Equation (11.9) is called the second-order central
difference quotient, Note that this is the average of the forward differ-
ence quotient and the backward difference quotient. This is also known
as three-point formula. The distinction between the two-point and three-
point formulae is illustrated in Fig. 11.1(a) and Fig. 11.1(b). Note that
the approximation is better in the case of three-point formula.
Numerical Methods

,proximation

True slope

x—h x
(a)

Approximation
True slope

x—h x
(b)
m
Fig. 1 1 IIIusration ot (a) I wa-point formula and (b) Three-pointt iuO

_71
Replaf the C . X(1' S vefl in Ex e. 11.1 for the three-point fbrrnula.
- ---- ------ -- ----
f(x+h)—f(h)
/ lx)=

Therefore,
I (l)=
f(l it ) —f(1--h)
2h
The derivative approximations are tabulated below:
h Error
ror

have used
The derivative is exact for all values of ii. This is because we
quadratic approximation (hr a quadratic function. We can also derive
further higher-order derivatives b y using more points in the formula.
given by
For example, the five-point central difference formula is
Numerical Differentiation

2h
1

This is a fourth-order approximation and the truncation error is of


order V. In this case, the truncation error will approach zero much
faster compared to the three-point approximation. The derivation of
Eq. (11.10) is left to the reader as an exercise. (Hint. use step .size 2h
instead ofh in Eq. (11.8) and use up to /11th derivative of Taylor's expan-
Sion).

Error Analysis
As mentioned earlier, numerical differentiation is very sensitive to round-
off errors. If E(h) is the roundoff error introduced in an approximate
derivative, then the total error is given by
E(h) Er() + E(h)
Let us consider the twu-poini., formula for the purpose of analysis. That is,
• f(x + h) - f(x) f1
f (x)
h
If we assume the roundoff errors in f1 and f0 as e 1 and eu, respectively,
then
(f4 e 1 ) -( f ) +e[))
t'(x) h

+
Ii h
If the errors e 1 and e are of the magnitude e and of opposite sign (i.e.,
the worst case) then we get the bound for roundoff error as

Er(h)l
/i
We know that the truncation error for two-point formula is

E,(h)I=
or
M2h
(/i)1
where M2 is the bound given by
M2 =Max If"(9)I
,'x t':^ x .,. It
Numerical Methods

Thus, the bound for total error in the derivative is

IE(h) 7!^ (11.11)

Note that when the step size h is increased, the truncation error in-
creases while the roundoff error decreases, This is illustrated in Fig.
11.2. For small values of h, roundoff error has an overriding influence on
the total error. Therefore, while reducing the step size, we should exer-
cise proper judgement in choosing the size. This argument applies to all
the formulae discussed here.

error

Trunca1n error
Error

Round off error

h
Fig. 11.2 Error in dorivalives as a function of h
We can obtain a rough estimate of h that gives the minimum error. By
differentiating Eq. (11-11) with respect to h, we obtain
M, 2e
2 h2
We know
know that E(h) is minimum when E'(h) = 0. That is,

M2 2e
2 h2
Solving for h, we obtain

hopt =2j (11,12)

Substituting this in Eq. (11.11), we get

E(hopj=2.feM2 (11.13)
Numerical Differentiation

Compute the approximate derivatives of 1(x) sin x, at x = 0.45 radians,


at increasing values of h from 0.01 to 0.64, with a step size of 0.005.
Analyse the total error. What is the optimum step size?
[lx) sin x
Using two-point formula

f'(x)
h
Given -;
x 0.45 radians
So, f(x) sin (0.45) = 0.4350 (rounded to four digits). Exact f'(x) = cos x
= cos(.45) = 0. 2QQ4 . -
Table below gives the approximate derivatives of sin x at x =0.45
using various values of h.

error
0.010 0.4439 0.8900 0.0104
0.015 1 0.4484 0.8933 0.0071
0.020 0.4529 0.8950 0.0054
0.025 0.4573 0.8935 0.0069
0,030 0,4618 0.8933 0.0071
0.035 0.4662 0.8914 0.0090
0.8 9 00

The table shows that the total error decreases from 0.010'l (at h = 0.01)
till It 0.02 and again increases when ft is increased as illustrated in
Fig. 11.2.
Since we have used four significant digits, the bound for roundoff
error e is 0.5 X104 . For the two-point formula, the bound M 2 is given by
M2 Max f"(0)l
O 0.49,

= I sin (0.49)1 0.4706


'I'herefore, the optimum step size is

2 10.5, 10--1
h ^PL-- 2 LJL -
V 0.4706
= 0.0206
This agrees very closely with our results.
Numerical Methods

Higher-order Derivatives
We can also obtain approximations to higher-order derivatives using
Taylor's expansion. To illustrate this, we derive here the formula for
f"(x). We know that,

and
h2 h3

Adding these two expansions gives


f(x + hi + f(x - h) = 2f (x) + h 2f"(x) + R 1 + R2
Therefore
f(x+h)_2f(x)+f(x-h) (R I +2)
h2 1i2

Thus, the approximation to second derivative is

111 14)
If

The truncation error is


+ R2
E(h) = 112

(O ) + f 1 ' ( 82))
4!

=-

The error is of order h2.


Similarly, we can obtain other higher-order derivatives with the er-
rors of order 12 1 and 11.

Limii41
Find approximation to second derivative of cos (x) at x = 0.75 with
------------- with the -true value. ------------

fAx) f(xih)2f(x)+f(x-h)
h2

f(0.76) 2f(0.75) + f(0.74)


f"(0.75),— -- (ath = 0.01)
00001
Numerical Differentiation

6.7248360 - 2(.7316888) ± 0.7384685


- 0.0001
14633046 -- 1.4632776

- 0.73Q00
Exact value off (0.75) = - cosi0.75)
=-0.73 16888
Error = 0.()016888
This error includes roundciff error as well.

U31 DIFFERENTIATING TABULATED FUNCTIONS

Suppose that we are ven a set of data points (X L , t , i = 0, 1, ... a which


correspond io the values of an unknown function f(x) and we wish to
estimate the derivatives at. these points. Assume that the points are
equally spaced with a step size of h.
When function values are available in tabulated form, may
approx maLe this function by an Mterp(ilation polynomial p(x) discussed
in Chapter 9 and then differentiate p(x). We will use here Newton's
divided difference i ntcrpOlatiOi) polynomial.
Let us first cunsi cler the linear equation
+ u 1 tx -
= al-I ±

where R 1 is the remainder term used for estimation. Upon differentia-


tion oi this formula, we obtain
di?,
pix =01
c
Then the approximate derivative of the function f(x) is given by
f'(x) = p 1 '(x) = a1

We know that
= fIx 1 . x11
---
= - fx1) f))
--
On substituting
/1 x, -
x1 = x +
X0
we get i__ ...........
Iii.1F
Numerical Methods

This is the familiar two-point forward difference formula.


Now, let us consider the quadratic approximation. Here, we need to
use three points. Thus,
P2(X) = a0 + a 1 (x - x0 ) + a2(x - x0) (x - x1)
Then

= + a2[(x - x) + (x - x 1] +
dx
Thus, we obtain
f(x) = a 1 + a 2 f(x x0) + Cx - x01 (11J6)
Let x = x, x 1 = x + h, x2 x + 2/z, Then
f(x+h)- f(x)
a]
=
f[xj,x2]-flx y,x1j
a2 = [x01 x 11 x23 -

f(x2)-•f(x1) f(xi)_f(xo)
X 2 _X1
X 2 -x0

- f(x+2h) . 2f(x i h) ff(x)


2h2
Substituting for a 1 and 0 2 in Eq. (11,16) and after simplification, we get

-3f (X) -
_
If f x + ^
11) -- ^f(x ^2^
- 2h)
(7
F
P, 2h
This is a three-point forward difference formula. We can obtain a three-
point backward difference formula by replacing h by -h in Eq. (11.17).
Therefore, the three-point backward difference formula is given by
IF
3f (.x.) - 4/'(x - h) - ^(x
f - 2h)
(11.18)
Similarly, we can obtain the three-point central difference formula by
letting x 0 = x, x 1 x h, x2 = x + h. in Eq. (11.16). Thus,

- f(x+h)-2f(x)ff(x -Ii)
02 -
2h2
Numecal Differentiation 35 7

Substituting these values in Eq. (11.16) we get

(1 1.19)

Error Analysis
Let us first take the linear case.
R1 fx0 , x 1 . x] (x - x0 ) (x - x1)
where

fix0 , x1,
- 2!
for some point q in the inteival containing x 0 , x and x. Then
= f"(9)
dx 2
Letting x 0 x and x 1 = .0 + It
dR It
^Oxh
dx 2
Therefore, the truncation error is of order h. This conforms with
Eq. (11.4). Now, let us consider the quadratic approximation.
R2 f[x01 x 11 x21 xl (x x0 )(x - x 1 ) (x - x2)

f"'(0)
I 1x0, x 1 , x, xl =
for some point q in the interval containing x 0, x 1 , x2 and x.

By setting x0 = x, x, =x and x+ 2h,

= !!2-f"'(0), rIRx - h
dx 3
This error equation holds good for both forward and backward three-
point, formulae.
For central difference formula, we must set x 0 = x, x 1 = x - h and
= x + h. Therefore,
x-h.:!^O:^x+h

Note that the error is of order It


IU Numerical Methods

Jv7
The table below gives the values of distance travt'lled b y a car at various
time intervals during the initial running
-- ----
Time, f(s) 5 67
Distance 10.0 19.5 1
2.0

Estimate velocity at time t = 5, t 7 and f 9


We know that velocity is given by the first derivative ofst. At
t = 5, we
use the three-point fbrward difference formula (11.171,

= 3s(t) 1 s(t ± /i) -+ 2/i)


i---.. --
Then
3(10)+4(14.5) - 19.5
v(o - ------------._----_.--

= 4.25 knils
At t 7, we use the central difference formulae (11.191. Therefor(,.,
s(8) - s(6)
i57)
2h

25.5- 14.5

At I = 9, we use the beckw ard_djffr . erice lorniulac (11.18)

35(9) 4s(8)+ s(7)


n(9)
2/i

- 3.32) -4(25.5)+ 19.5

= 6.75 kiriis

Higher-order Derivatives
Formulae for approximating the second and higher derivatives can also
be obtained from the Newton divided difference formula. The second-
order derivatives are as follows:
Central

["(x) f(x + h) - 2f (x) + f(x h)


(11.20)
Numerical DitterefltiatOfl 2

2
Error

Forward
(11.21)
f"x)

11]i.2 fl 4)
Error
=

Backward
2f (x) -- 5f(x - h) I 4f(x - 2k) - f(x 3/i) (11 22)
f (x) h2

111i2-- /
Error - -

to estimate acceleration
Use the table of data gR'efl in Example 11,5
at t = 7 s.

Acceleration is given by the second derivative of s(t). rçerefore


S(I + h) - 2s(i) + h)
a(t) =s"(t

Therefore.
25.5- 2U9.5+ 14.5
a(7) - 12
.2
= LOkmis

The equatOfl for deflection of a beam is given by


- =0 y(0) = U. y (1) = 0
Estimate, using a second-order derivative, the approximate deflections
is the deflectio n at x.
at x 025, 0 5, and 0.75. Note that y(x)

± y(x — h)
ytx ± 5)— 2y(x)
y'(x ) =

It 025
Then,
('+0.25) 2y ( x) 2

0.0625
Q Numerical Methods

Consequently,
y(x + 0.25) 2y(x) + y(x 0.25) 0.0625 e-1

Substituting = 0.25, 0.5 and 0.75 in the above equation in turn, we get
y(O.5) - 2y(O.25) + y(0) 0.0665
y(O.75) 2y(0.5) -f y(0.25) = 0-0803
y(l) - 2y(0.75) + y(O.5) 0.1097
Given y (O I = y(l) 0. Denoting
y 1 =y(O.25), y = y(O.S)
2 and y =y( 0.75)
3

We have
0 +y - 2y 0.0665
9 1

Y3 - 2Y2 + y = 0.0803
1

_ 2.Y3 +y + 0 0.1097
Solving the three equations for y, and v. we get
y 1 .

y(0.25) = - 0.1175
Y2 yOS) = . 0.1684
yj = y(0.75) = - 0.1391

DIFFERENCE TABLES

Tables 11.1 to 11.3 list difference derivatives f'(x) and f"(x) and associ-
ated errors for forward, backward and central difference formulae, Fol-
lowing notations are used:
f2 denotes f(x + 2h)
[2 denotes f(x 2/i j

Table 11.1 Forward difference derivatives


Derivative Formula Error

..3f +4f f2
f(x) 4
-- 3
(4e/h)

HJ — _/—
Numerical Differentiation 36 1

Table 11.1(Contd.)
rivatweJ__ Formula Error
I
-25fo 4 fi - 36f + 1613 314 f5t))
f x0)
12h
(32€/h)
f 2f + 12

f''(x) i4€1h21

h2
12 (12€/h2)

#Roundoff error

Table 11.2 Central difference drivative


Error

_L±f3(o)
2/i. 6

[28f/lf2

f(x0)

-451 45f9f3f3
- 140
I(lle/6h)

f. Tf1

Lh )
h 12
(4e/1i2)
f '(x0)
------

#Rotwdoff error

Table 11.3 Backward difference devatives


Derivative Formula Er

I "(
(9i/i)
(Contd.)
2 Numoicaj MathJ3
Table I 1.3(Co1d.)

Pormula, Error -

2h 3
f'(x)
L L (4e/h)

61?
11
P -1

flf-1.6ff36f248f2sfo
L (20c!31i

12h 5

f2-2f1+f0
- h[' di
f'x0)
(4/h2)
: 4f25f2f0
111z2
h2 12

#ROUI)dr)ff error

1ITL RICHARDSON EXTRAPOLATION


Richardson extrapolation is based on a model for the en-or in a numeri-
cal process. This is used to improve the estimates of numerical solutions.
us assume
xx -M
(11.23)
Xkis the kth estimate of solution x ' and M h'
is the error term. Let us
now replace Ii by rh and obtain another estimate for
x'.
xi M h
(11 24)
Multipl ying Eq. 0 1.23 by i -' and solving fir
x', we get

XP
X
I lr (11.25)
Thisis known as Richardson, extrapolation estimate.
term has been eliminated. Note that the error
This concept can be extended to the estimation of derivatives dis-
cussed so far. Using this, we can obtain a higher-order formula from a
lower-order formula, thus improving
the flccuracv of the estimates. This
Numerical Differentiation

process is known as extrapolation. Let us consider the three-point


central difference formula with its error term.
f(x ± h) -
OX)
2h
-
6
I 'tOi

=Thh)-'--f ... (9) (11.26)


where D(h) is the estimate obtained using h as step size. Note thatf'(x)
is the exact solution which is usually approximated by D(h). If we re-
move the error term, then we can obtain a better approximation. Now,
let us obtain another approximation for f'(x) by replacing h by rh. Thus,
f(x+rh)-f(x-rh)h2r2
tx)=—
2hr 6

= D(rh)-- /"(Th (II.2?

We can eliminate the error term by multiplying Eq. (11.26) by r2 and


subtracting it from Eq. Ui .27). The result would be

D(rh) - 1-2 D(h)


f'(x) (11.28)
=
This would give a better estimate of f(x) as we have eliminated the
error term 0. For r = 2, Eq. (11.28) becomes
fix - 2h - 8f (x - h)+8f( + hi f(x t- 2h)
f'(x) (11.29)

Note that this is a five-point central difference formula which contains


error only in the order of h 4 . We can repeat this process further to
eliminate the error term containing h4 and so on.
One of the most common choices of r is 0.5. Letting r = 1/2, Eq. (11.28)
becomes
f(x hi - 8x h121 ^ 8f (.z /i./2) f (x A- h)
f - -
(xi - ------------ (11.30)

Note that the use of this formula depends on the availability of function
values at x 4- Jr/2 points. 'l'hjs will be a restriction when Richardson's
extrapolation technique is applied to tabulated functions.

--
Show that, using the data given below, Richardson's extrapolation tech-
nique can provide better estimates !'or derivatives.
4 Nurnericai MeThods
r ------ -
x !0
- -0.5 _0 . 258±°2' 0.570.75 0.25 10 125 i-
2.1170
V±_ 06065± !2.711

Let us estimate 1 (x) at x = 0.5 and assume h = 0.5 and r 1/2. Then.
using three-point central formula, we have
f 1.0)- f(0
Th/1)=D(O.5)_ -
2s
0.5
---- 1.7183

= D(0.25) = f(O.75)-f(0.25) = 1.666


D , r/2)

f(x)= -Th---
D(r-r2D(h)
1- r
Therefore,
L660-0.25U.7183,
0.75
= 1.6486
Note that the correct answel is 1.6487. The result is much better than
the results obtained using three-point fOrmula with ii = 0.5 and 1 0.25.
Now, let us take i' 2. Again using the same three-point central
formula.

D(rh) D11.0) L( 1. 5) - [(-0.5) = L93 76


2O0.52)

1.9376
- 4(1.7183
f(x) ---- = 1,6462

This shows that the estimate with ,- = 1/2 is better than the estimate
with i' 2.

SUMMARY
In this chapter, we have seen how numerical differentiation techniques
may be used to obtain the derivative of continuous as well as tabulated
functions. We have used fOrward, backward and central difference quo-
tients to obtain derivative equations. We have also seen how Richardson
extrapolation is used to improve the estimates of numerical solutions.
The discussions in this chapter bring nut the following points:
. If we are given ii + 1 data points equally spaced, the interpolating
polynomial will be of order a, and the nth derivative will be the
highest that can be obtained.
Numerical Dlfferentiaion

Better approximation of derivatives can be achieved by using more


points in the formula.
For a given number of data points, the central difference formula is
more accurate than their forward or backward counter parts.
Roundoff error grows when h gets smafl. We Will always face the
step-size dilemma. One way to overcome thie problem is to use a
formula of higher order so that a large value of Ii will produce the
desired accuracy.
The problem becomes more pronounced when working with experi-
mental data which coutain not only roundoff errors but also mea-
surement errors. In such cases, we should first fit a curve to the
data by using least-squares technique and compute derivatives for
the curve.

Key Terms
Backward difference derivative Five-point formula
Backward difference quotient Forward difference derivative
Central difference derivative Forward difference quotient
Central difference quotient Richardson extrapolation
Difference tables Two-point formula
Extrapolation Three-point formula

1QNsi

Who t is numerical dilterentiat ion?


Why do we need to use numerical techniques to obtain the esti-
mates of function derivatives?
3. What are the three primitive numerical differentiation formulae?
Compare their truncation errors.
4. What is three-point formula? How is it different from the two-point
formula? Illustrate the difference using geometric interpretations.
5. Derive the five-point central difference formula
= -f (x t 2h+ 8fx + hi - 8f(x-h)tf(x 2/i)
['(xi
12h
Also estimate the order of truncation error.
6. Describe the effect of step size h on
(a) truncation error,
(b) roundoff error, and
(c) total error.
7. Using Taylor's expansion, derive a formula for computing second
derivative of a function.
S. Derive a three-point difference formula for estimating the first de-
rivative of 2 tabulated function.
Numerical Methods

9. Derive a formula to estimate the second derivative of a tabulated


function.
10. What is Richardson extrapolation? How does it improve the esti-
mates of derivatives?

1. Estimate the Lirst derivative off W = in x at x 1 using the first


order.
(a) first-order forward thiferance formula,
(b) first-order backward difference formula, and
(c) second-order central difference formula.
Compare the results with the exact vaIrK 1.
2, Estimate the first derivative of f(x) in z using the five-point
central difference formula. How does the result compare with the
results obtai.nad in Exercise 1.
3. Couip the approximate first derivatives of f = cos x at x = 0.75
radians at increasing values of h from 0.01 to 0.05 with a step size
of 0.005 (using four decimal digits). Analyze the variations s f error
in each step.
4. Apply the three-point central difference formula to obtain estimate*
of the first derivatives of the following functions at x 1 with
h = 0.01. Compare the results with true values.
(a) cosh
(b) exp(x) sin x
(c) in (1 + x2)
(d) x2 + 2x + I

(e) 1
I+X2
5. For each of the following functions
(a) cosx x=1.5
(b) exp(x/2) x = 2

(c) 1 - x=1
1 t-x2
estimate the size of h that will minimize total error when using the
three-point central difference formula.
6. Estimate the first derivatives of the functions given in Exercise 5
at the indicated points using the optimum size h obtained.
7. Use the three-point formula to estimate the second derivatives of
the functions given in Exercise 4 at x = 0.5 with h = 0.01.
8. Given below the table of function values of f = sin h(s). Estimate
the second derivatives off(s) at = 1.2, 1.3 and 1.4 using a suitable
formula.
Numerical Differentiation Z

rri LIii1Th il_Zi23i

9. Current through a capacitor is given by

1(t) = C = Cu'(t)
dt
where v(t) is the voltage across the capacitor at time t and C is the
capacitance value of the capacitor. Estimate the current through
the capacitor at t = 0.5 using the two-point forward formula with a
step size h = 0.2. Assume the following:
u(t) = (t + 0.1) e volts
C=2F
10. Using the function in Exercise 8, estimate the first derivative at
x 1.3 with h = 0.1 using the three-point centre formula. Compute
an improved estimate using Richardson extrapolation. Exact value
of f(x) = cosh(1.3) = 1.9709.
11. Evaluate the first derivative at z = - 3 and x = 0 of the following
table function:

L
12. Compute the first derivative for the following table of data at
x = 0.75, 1.00 and 1.2. Ue h = 0.05 and 0.1.

0.5 01 0.9 1.1


rt±I8 1.96
1.00j
Compare the results with h = 0.05 and h = 0.1. Comment on the
differences, if any.
13. The following table gives the velocity of an object at various points
in time
Time (seconds) 1 1.2 1.8 T2ij 8 3.0
iyec9.0: 9.5
J l0.2iL0 13.2 14.7 18.7 22.0

Find the acceleration of the object at T = 2.0 seconds. Assume a


suitable value for h.
14. The distances travelled by a vehicle at intervals of 2 minutes are
given as follows:
Time (seconds) 012 14 6 810 12 14 16
L_tancekm.t 0 1 1 2.2 4 11 13
Numerical Methods

Evaluate the velocit y and acceleration of the vehicle at 7 = 5, lo


and 13 seconds.

1. Write a program that will read on the value oi. k r i nd f(x cronpute
approximations to fu) and f' (x, and output x, f i x), f(X) and f"(x)
in four columns.
2. Write a program that will compote the total error at increasing
values of /i at regular steps and then estimate that valne of /i for
which the total error is minimum. Assume a formula of your choice.
3. Write a program to evaluate a given function at various points of
interest and estimate its first and second derivatives at an y speci-
fied point.
Numerical Integration

__J1 ^ ^ NEED AND SCOPE


Like numerical differentiation, we need to seek the help of numerical
integration techniques in the following situations:
1 Functions do not possess closed form solutions. Example:

f(x) CIet2dt

2. Closed form solutions exist but these solutions are complex and
difficult to use for calculations.
3. Data for variables are available in the form of a table, but no
mathematical relationship between them is known, as is often the
case with experimental data.
We know that a definite integral of the form

I f(x)dx (12.1)

can be treated as the area under the curve y = f(x), enclosed between
the limits x = a and x = b. This is graphically illustrated in Fig. 12.1. The
problem of integration is then simply reduced to the problem of finding
the shaded area.
One simple approach is to plot the function on a graph paper contain-
ing grids and find the area under the curve using the number grids
covered under the desired boundaries. The accuracy of this rough esti-
mate can be improved by using finer grids.
Numerical Methods

AX)

a b x
Fig. 12.1 Graphical representation of Integral of a function
Although the grid method and other such graphical approaches can pro-
vide us rough estimates, they are cumbersome and time-consuming and
the final results are far from satisfactor y limits. A better alternative
approach could be to use a technique that uses simple arithmetic opera-
tions to compute the area. Such an approach, if necessary, can be easily
implemented on a computer. This approach is called numerical integra-
tion or numerical quadrature. Numerical integration techniques are sini-
lar in spirit to the graphical methods. Both of them use the concept of
"summation" to find the area.
Numerical integration methods use an interpolating polynomial p(x)
in the place oif(x). Thus
h
1=ffx)dx=Jp(x)dx (12.2)
11 a

We know that the polynomial p(x) can be easily integrated analytically.


Equation (12.2) can be expressed in summation form as follows:
a
Ip,, (x)d- W Pr (1) (12.3)
1=0

where u = x 0 <x 1 <. ... <x,, = b


Since p(x) coincides with f(x) at all the points x 1 , i = 0, 1, ... a, we carl
say that,
a
I=Jf(x)da=w 1 (x) (12.4)
a

The values x, are called sum pling points or integration nodes and the
constants w, are called weighting coefficients or simply weights.
Equation (12.4) provides the basic integration formula that will be
extensively used in this chapter. Note that the interpolation polynomial
Numerical Integration 371
p(x) was used only to derive the formula (12.4) and will not be used in
the computation directly, Only the actual function values at sample
points are used in numerical computation.
There are various methods of selecting the location and number of
sampling points. There is a set of methods known as Newton-Cotes rules
in which the sampling points are equally spaced. Another set of methods
called Gauss-Legendre rules, uses sampling points that are not equally
spaced, but are designed to provide improved accuracy. In this chapter,
we discuss these two sets of methods in detail. We also discuss a method
known as Romberg integration that is designed to improve the estimates
of Newton-Cotes formulae.
In general, numerical integration methods yield much better results
compared to the numerical differentiation methods discussed in the pre-
vious chapter. This is due to the fact that the errors introduced in sepa-
rate subintervals tend to cancel each other. However, the estimates are
still approximate and, therefore, we also consider the magnitude of er-
rors in each of the methods discussed here.

. NEON-COTES METHODS
Newton-Cow ,, formula is the most popular and widely used numerical
integration formula. It forms the basis for a number of numerical inte-
gration methods known as Newton-Cotes methods.
The derivation of Newton-Cotes formula is based on polynomial in-
terpolation. As pointed our earlier, an nth degree polynomial p(x) that
interpolates the values of f(x) at n + 1 evenly spaced points can be used
to replace the integrand f(x) of the integral

1 Jf(x)dx

and the resultant formula is called (n + 1) point Newton-Cotes formula.


If the limits of integration a and b are in the set of interpolating points
X" i = 0, 1, ... n, then the formula is referred to as closed form. If the
points a and b lie beyond the set of interpolating points, then the formula
is termed open form, Since open fox-in formula is not used for definite
integration, we consider here only the closed form methods. They in-
clude:
1. Trapezoidal rule (two-point formula)
2. Simpson's 113 rule (three-point formula)
3. Simpson's 3/8 rule (four-point formula)
4. Boole's rule (five-point formula)
All these rules can be formulated using either Newton or Lagrange
interpolation polynomial for approximating the function f(x). We use
here the Newton-Gregory forward formula (Eq. (9.20)) which is given
below:
72 Numerical Methods

pa(s) = fo + M1s + A2f s(s - s(s - 1) (s - 2) +


2! 1) + 3!
(12.5)
where
s = (x - x0)/li
and

TRAPEZOIDAL RULE
1K:; 1L)
The trapezoidal rule is the first and the simplest of the Newton-Cotes
formulae. Since it is a two-point formula, it uses the first order interpo-
lation pomomiaI p 1 (x) for approximating the function f(x) and assumes
xO = a and x - b. This is illustrated in Fig. 12.2. According to Eq. (12.5),
1) 1 (x) consists of the first two terms T0 and T1 . Therefore, the integral for
trapezoidal rule is given by

f (x)

x1 =b x
Fig. 12.2 Representation of trapezoidal iule

b
I, =J(T0 + T1)di

b
JTç, th + T (Ix = +

Since T1 are expressed iii terms of s, we need to use the following trans-
formation
cLc = h x ds
x0 = a, x 1 =b and h=b — a
At x =a, Srr(a_x0)//? O
At \= b, .c = (b - =1
Numerical Integration 3Th

Then,
b

'0
cU. - J hf, dx - hfj
U

'\o
112 - '
I' d.x = l\fj sh cis = h

Therefore,

11 -hifo F

Sincef0 = f(ai andf = f(h), we have

H
Note that the area is the product of wcdth of the seb'riwni b - a) and
average bight of the points. fin) and fib,.

Error Analysis
Since only the first two terms of eq. (12.5) are used for I( the term T2
becomes the remainder and, therefore, the truncation error in trapezoi-
dal rule is given by
b '"(0
E, =JT dx—__-Is(s--1)hds
2 ç,

f"hH :4 211

- 2 H 2]o 12
It

Since dx/ds =
= h 2 f".0).
we obtain
(12.7)
1
12
where a < Q

Evaluate the integral

I J (x 3 + 1)dx
374 Numeilcd Methods

for the intervals (a) (1, 2) and (b) (1, 1.5)


Also estimate truncation error in each case and compare the results
with the exact answer.

Case a=1,b=2
h= I
1b-a
V(a)+f(b)l

+ 9) 5.5

EJ :5 —niaxlf"(x)I
12 15.52

["(r) = 6x
maxi f"(x) I= [" ( 2) = 12
1'x2

Therefore,

EUI ["(2) = 1

'exact = 975
True error I, - - 0.75
Note that the error hound is an overestimate of the true error.
Case a=1,b=1.5
h = 0.5

I lf(1) +f(1.5)J = 1.59375

IE Lt I .c 3 f"(l.S) = 0.09375

exact 1.515625
True error = 0.078125

Composite Trapezoidal Rule


If the range to he integrated is large, the trapezoidal rule can be im-
proved by dividing the interval (a, b) into a number of small intervals
and applying the rule discussed above to each of these subintervals. The
sum of areas of all the subintervalo is the integral of the interval (a, b,
This is known as composite or multiseg,nent approach. This is illustrated
in Fig. 12.3.
Numerical Integration

f (x)

x1=h, 1=0,1,.,. n-i

Fig. 12.3 Multisegment trapezoidal rule


in Fig. 12.3, there are it + 1 equally spaced sampling points
As seen in
that create n segments of equal width h given by
b-a
h=
n
a+ih, i=0,1.....n
From Eq. (12.6), area of the subinterval with the nodes x - and x is
given by

l =Jpi dx = [f(x ) + (x)!

The total area of all the n segments is

1f(x 1) + f(x1)1

= ft If (X,) ) + f(x)J +
ft ff(x 1 ) + f(x)1

+ ... +
ft If (x ]) + [(x,)]

Denoting j = f(x) and regrouping the terms, we get


n1 1
ft f0 +2 I f + f (12.8)
J
Equation 12.8) is the general form of trapezoidal rule and is known
as composite trapezoi+la! rule. Equation (12.8) can also be expressed as
follows:
Numerical Methods

= [f(a) + f(b)J + h f(a + i/i)


2 IA

Similarly, we can estimate the error in the composite trapezoidal rule


by adding the errors of individual segments. Thus

h3
E1 = - --- f'() (12.9)
2•'1

We know that f(q,) is the second derivative at q, XL _ 1 < 4 <xi . If the


q

maximum absolute value of the second derivative in the interval (a, bi is


F, then we can say that the truncation error is

F (12.10)
12 12n2

Theoretically, we can say that it is always possible to increase accuracy


by taking more and more segments. Unfortunately, this does not happen
alway s. When the number of segrnent '1'ncrcases, error due to rounding
77
off increases. /

Compute the integral

using composite trapezoidal rule for (a) n 2 and (b) n = 4.

Case n=2

h
2 2
fl-i
= h2 [(a) + fb)l + /u f(a -4- ih

Iexp (-1) + expKl)J + exp(0)

= 2.54308
Case n=4

h =.--- = 0,5
Nurllerlcai integration 3L7

+ lexp(-1) + expUj + iexp -0.5) + expW + exp(0.5)] 0.5


= 2.39917
Note that lexacc = 2.35040 and a = 4 gives bettor results.

Program TRAPE 1
Trapezoidal rule is a simple algorithm and can he itnolemented by a few
FORTRAN statements as shown in the program TRAPE1. Note that the
major computation is done by just one statement in a DO loop. This
statement calls a function subprogram to evaluate the given function at
a specified value of x. We can use this program to integ r ate any function
by simply changing the ftmction definition statement

F, = I

-------------- .--*
PRC'GRAN TRAPTI
*------.-.---------- -- ------------*
* Main program *
*
This program integrates a given function
using the tra p ezoiddi iule
* --------------------- ---
---- *
* Functions invoked *
* F *

* Subroutines used A

NIL
* Variables used *
*
A - Lower limit of integration *
* a - Upper limit of integration *
* H - Segment width *
*
N - Number of segments *
*
ICT - Value of integral k
* ------------------------ --- -------------- ---
--------*

* Constants used *
* MIL *
*

INTEGER N
REAL A, B, I-i, SUE, ICT
EXTERNAL F
WRITE(* , *) 'Give initial value of X'
READ(* , *) A
rITE(*, ) ' Give final value of X'
READ(* , *1
I"

an Numerical Methods
WRITE(*, *) 'What is the segment width?'
R.EAD(* *) H
N (B-A)/fl
SUM (F(A) + F(B))/2.0
DO 10 I = 1, N-i
SUM = SUN + F(A±I*H)
10 CONTJNUE
ICT SUM * H
WRITE(*, *)
WRITE(*, *) 'INTEGRATION BETWEEN', A,' AND', B
WRITE(*, *)
WRITE(*, *) 'WHEN H =', H, ' IS', ICT
WRITE (*, )
STOP
END
* ---- End of main TRAPE1 ------------------*
* ----------- ------------------------------------------
* Function subprogram I' (X) -
* --------------------------------------------------------- *

REAL FUNCTION F(X)


REAL X
F = t-XP-X/2.0)
RETURN
END
* ------------------ End of function F(X)

Test Run Results 'rest run results shown below give the value of inte-
gration of the equation
f(x) 1 -
from 0.0 to 10.0.
Give initial value of X
0.0
Give final value of X
10.0
What is the seqirtent width?
0.5
TNTEGRATION BETWEEN .0000000 AND 10.0000000
WHEN H = 5.000000E-001 IS 8.0031400
Stop - Program terminated.
Numerical Integration .Z2

SIMPSON'S 1/3 RULE

Another popular method is Simpsons 1/3 rule. Here, the function f(x>is
approximated by a second-order polynomial p 9 (s) which passes through
three sampling points as shown in Fig. 124. The three points include
the end points a and h and a midpoint between them, i.e., x 0 a, x 2 = b
and x 1 = ( a + b)/2. The width of the segments h is given by
—a
h= h

f(x1) I(b / f(x)

x3 =a X, x2=b x
Fig. 12.4 1opresentation of Simpsons Three-point rule

The integral for Simpson's 113 rule is obtained by integrating the first
three terms of equation (12.5), i.e.,
h b
I 1 =5p 2 (x)dx=-J(T0 +T 1 +72)dX
a a
b 1' b

= JT0 b ± jT 1 dx ± 5T2 dx
a a a

= 'all + 'au + 413


where
b
=Jfodx
a

b
1s12 r-_5Efosdx
a

,13 -
a 2
NumerccI Methods

We know that dx = Ii < ds and s varies from 0 to 2 (when x varies from a


to b). Thus,
2
= 5 fo h cis = 21i10
0

2
18 12 = I Ao sh ds = 2hf0

I,]3= h
1)/ids=-2f0
2 ,;( s
+ f,
Therefore,
+ 2fo]
'si = It[sfo + (12.11)

Since Af0 = f f0 and A2 = - equation (12.11) becomes

41 = V0 + 4f + 121 [f(a) + 4ff(x 1 ) + f(bi (12.12)

This equation is called &rnpson's 113 rule. Equation (12.12) can also be
expressed as
(h - f(a)_+_4f(x1+f(b)
-
6
This shows that the area is given by the product of total width of the
segments and weighted average of heights Ira), f(x 1) and [(b).

Error Analysis
Since we have used onl y the first three terms of Eq. (12.5), the trunca-
tion error is given by

E11 =JT3 dx

= -------- Js(s— l)(s - 2)/i ds


C)

-
6
--s
L4
--s2
12

Jo
Since the third-order error term turns out to be 'zero, we have to con-
sider the next higher term l'or the error. Therefore,
S
1 ti =5T4 dx
Numerical Integration

f(4)(U) 2
- Js(s-1)(s-2)(s-3)hd8
- 4!

hx f 4) ( O 5)Fs 5 6s + us 3 6s2120
- 24 [5 4 3 2

- 11
- -
90
Since f(6) = h 4 f 4 k6), we obtain

E1 (12.13)
90
where a < < b. It is importantnote pson's 1/3 rule is exact
up to degree 3, althoigh it yz(quadratic equation.

X
Evaluate the follolng integrals using Simpson's 1/3 rule

(a) Jex dx (b)J /sin dx

Ca. (a)

i =1ex dx

= ft 11(a ) +f(b) + 4f(x1)1


b-a
h -- =1

f(x1)f(a+b)
Therefore,
+4e0+e1
'sl = 2.36205

(Note that I gives better estimate than 'Ct when n 2. This is because
uses quadratic equation while I, uses a linear one)
Case (b)

1= .JIi(x)dx=ir/4

'si = 11(Q) + 4f(7o'.4) +f(m'2))


.2

= 0.2617993(0 + 3.3635857 + 1)
= 1.1423841
Numerical Methods

Composite SImpson's 1/3 rule


Similar to the composite trapezoidal rule, we can construct a composite
Simpson's 1/3 rule to improve the accuracy of the estimate of the area.
Here again, the integration interval is divided into n number of seg-
ments of equal width, where n is an even number. Then the step size is

h= --

As usual, x a + ih, i = 0, 1, ... n. Now, we can apply Eq.,(12.12) to each


of the n/2 pairs of segments or subintervals (x - , . ), (x - ,
This gives
n12
h [f(x_ 2 )+ 41(xn- ) -4- f(x 2 )l

= [f(a)+4f1 +2f2 +4f5 + ... 2f2+4f1+f(h)J

On regrouping terms, we get

'Cs1 f(u)+4 f(x 21 )+2 f(x21)±f(b)I (12.14


31 i-1-

An analysis similar to the error analysis of composite trapezoidal rule


can be performed to obtain the error due to truncation in composite
Simpson's 113 rule.

I E t Cl I --- nF
-180 F (1215)
180n4
where F is the maximum absolute value of the fourth derivative of f(x)
in the interval (a, b).

Compute the integral

dx

applying Simpson's 1/3 rule for a = 4 and a = 6 with an accuracy to five


decimal places.
The composite Simpson's 113 rule is given by

IrSI= f(x 0 ) f(x)) 4 f(x 2+ 2 f(x4


3 4-1 z=1

For n = 4, h = 71 18
Numerical Integration
There are five sampling points given by x;, = k7r18, k = 0, 1,..., 4. Substi
tuting the values of xk in the composite rule, we get,
- r [[(U) + fCnl2) + 4f 7r/8) + 41(3,r/8) + 2f (e4)]
I -

. [0 + 1.0 + 4(0.61861 + 0.96119) + 2 (0.84090)1

= 1.17823
For it G, Ii = it/12
There are seven sampling points given by . k,r/12, k = 0, 1.....6
Substituting these values in the above equation, we get
= 1L [0 + 1.0 + 4(0.50874 + 0.84090 + 0.98282) + 2(0.70711
+ 0.93060).

1.18728

Program SIMS1
Program SIMSI integrates a given function using the cornposit.e Simpson's
1/3 rule. Note that, unlike TRAPE1 which requests for segment width h,
SIMS 1 requests for number of segxñents n. Remember, n should be even.
This program also uses a function subprogram which can be easily
replaced for any other function without modifying the main program.
----------------------*
PROGRAM S.LMS1
* *
* Math program *
* This program integrates i given f unction *
* using the Simpson's 1/3 ruin *

* Functions invoked *
* F *
* *
* Subroutines used *
* NIL *
**
* Variables used *
* A - Lower limit of integration
* B - Upper limit of integration *
* H - Segment width *
* N - Number of segments *
* ICS - Value of the integral *
- -- -----------------------------*
Constants used *
* NIL
* -------------------------------------------------------- *
4 Numerical Mettio

INTEGER N,M
REAL A, 13, H, STJM, ICS, X, Fl, F2 F3
EXTERNAL F

WRITE (*,*) 'Initi1 value of X'


READ (*) A
WRITE*,*) 'Final value of X'
READ(*,) B
WRITE (*,) 'Number of eq-ments (EVEN number)'
READ(*,) N

H-
FT =

SUM 0.0
X=A
Fl = FX)
DO 10 I = 1,M
F2 =
F3 - F(X+2*H)
SUM SUM Fl 4. 4*F7 + F3
F]. = F3
x -' x + 2H
.10 CONTINUE

TCS = SUM Hi'3.0


WRITE ( , k)
WRITE *) INTEOP..AL FROM', A,' TO', B
WRITE ( k ,
'JTE : ' ' IS',
WRTTE(* , *) LCS

STOP
END

End of main SIMS] -----------------*

F,jflCt ion subprogram F(x)


-- ----- ------------------------------ *
-----------
REAL FUNCTION F(X)
REAL A

F = 1-F'XP(-X/20)
RETURN
END
--------------End of
fuflCtio F(X) -..
Numerical Integration
Test Run Results Output of the program for integrating the function
1(x) = 1 -
from GM to 10.0 is given below:
Initial value of X
0.0
Final value of X
10.0
Number of segments (EVEN number)
20
tNTEGRAL FROM .0000000 To 10.0000000
WHEN H = 5.000000E-O0i IS 8.0134330
Sto p - Prog ram, teI:nnatej.

SIMPSON'S 3/8 RULE

Simpson's 113 rule was derived using three sampling points that fit a
quadratic equation. We can ex-tend this approach to incorporate four
sampling points so that the rule can be exact, for f(A )
of degree 3.
Remember, even Simpson's 1/3 rule, although it is based on three points,
is third-order accurate. However, a formula based on four points can be
used even when the number of segments is odd.
By using the first four terms of Eq. (12.5) and applying the same
procedure followed in the previous case, we can show that

2 H/(o)+3f(xi)I3f(x2jl (12.16)
where h (b - (1)73. This equation is known as
Simpson's 3/8 rule. This
is also known as Newton's three-eighths rule.
Similarly, we can show that, using the fifth term of Eq. (12.5), the
truncation error of Simpson's 3/8 rule is

_f4)(baf(4)(8J
L2 (12.17)

where a < 0 <5.


' Or a given interval :, 6), the truncation error of Simpson's 113 rule is

E51 L6 (b—a)5
-- ö-14 2880
'his shows that the 3/8 rule is slightly more accurate than the 1/3 rule.
Numerical Methods c');

Use Siuipsen s 3/o rule to evaluate


2 l2
(a) J(x 3 --1)rlx (b) J'[siiEi(x)dx
1 (1

Case (a)
Basic Simpson's 3/8 rule is based on four sampling points arid, therefore,
IL = 3,

[1(a) 3f(x 1 ) + 3f(.i:) +

h
a 3
x1=a+h=1+1/3=4/3
)2t+2/ 1±2/3=5/3
on substitution of these values, we obtain
152 = [ f(1) + f(2) + 3f(413) + 3f(513)]

4.75
Note that the answer is exact. This is expected because Simpson's 3/8
rule is supposed to be exact for cubic polynomials.
Case (b)
irJ2
1=

Here again, n 3 and the integral is given by

= 3h [[(a) + 3f( x ) + 3f( x 2) + f(b)}

h ==!L
3 6

a+h=-

x2 z a + 2h = -
on substitution of these values, we obtain
it
f(0) + 3f(,r/6) + f(703) + f(it/2)]
=
=. [0 + 2.12132 + 2.79181 + 1.0]
1.16104
Numerical Integration 387

____ HIGHER ORDER RULES

There is no limit to the number of sampling points that could be incorpo-


rated in the derivation of Newton-Cotes rule. For instance, we can use a
five-point rule to fit exactly the function f(x) of degree 9 and so on. Since
the repeated use of lower-order rules provide sufficient accuracy of the
estimates, higher-order methods are rarely usecl
One more rule which is sometimes used is Boyle's rule based on five
sampling points. This is given by

l b = ( 7f0 + 32f1 + 1212 + 32f + 7 (1218)

where h=(b—a)/4
The truncation error of Bode's rule is

(12.19)
1
945

E.ampie 1,244
Use 13ooiey five-point formula to compute
,r12 _______

Ilsin(x) dx
U

and compare the results with those obtained in previous examples.


n = 4, Ii = 7r/8
f=0
f1 f0r18) 0.61861
12 = f(7rI4) 0.84090
f=f(3ir/8)=0.96119
f4 =f(ir/) =1.0

10 + 2(0.61861 +0.96119) + 12(0.84090) + 7(1.0)1

= 1.18062
The table below shows the results Qf
,r/2

J/sin(x) dx

obtained by various Newton-Cotes rules.


Numecical Methods

Rule n Result
Trapezoidal (simple) 1 0.78540
Trapezoidal (composite) 2 1.05314
Simpson's 113 (simple) 2 1.14238
Simpson's 3/8 3 1.16104
Simpson's 1/3 (composite) 4 1.17823
Boole's rule 4 1.18062
Simpson's 1/3 (composite) 6 1.18728
Simpson's 113 (composite) 12 1.19429

The estimate can be further improved by using still more intervals.


Table 12.1 lists the basic Newton-Cotes rules.
Table 12.1 Basic Newton-Cotes rules
Name In1eri'al (it) Formula Error

Trapezoidal 1
4 (f0 +
It

h5
f "(0)

Simpson's 113 2 4f + _.f4) (0)


4 +

Simpson's 3/8 3 S (f0+3f1+3f+f3) --1(o)

2h #f) - 8h7
Bode's rule 4 -( f + 32ff + 1212 + 3212
945
(0)
45

ROMBERG INTEGRATION
It is clear from the discussions we had so far that the accuracy of a
numerical integration process can be improved in two ways;
1. By increasing the number of subintervals (i.e. by decreasing h)—this
decreases the magnitude of error terms. Here, the order of the
method is fixed.
2. By using higher-order methods—this eliminates the lower-order
error terms. Here, the order of the method is varied and, therefore,
this method is known as variable-order approach.
The variable-order method can be implemented using Richardson's
extrapolation technique discussed in the previous chapter. As we know,
this technique involves combining two estimates of a given order to
obtain a third estimate of higher order. The method that incorporates
this process (i.e. Richardson's extrapolation) to the trapezoidal rule is
called Romberg integration.
According to the Euler-Maclaurin formula, the error expansion for
trapezoidal rule approximation to a definite integral is of the form

Jf(x)dx-T(h) = a2h 2 + a4h 4 + a6 h6 + ... ( 12.20)


Numerical Integration
T(h) is the trapezoidal approximation with step size = ( b - a)/n = h.
Let us define
T(h, 0) = T(h)
to indicate that T(h) is the trapezoidal rule with no Richardson's
extrapolation being applied (zero level extrapolation). Thus, Eq. (12,20)
can be written as
I = T(h, 0) + a 2h + a 4 h' + a 6h5 + ... ( 12.21)
Let us have another estimate with step size = (b - a)/2n = h12 (at zero
level extrapolation) as

I-_T(hI2,0)+_i_h2 +*h4 -* - h +... (12.22)


32
By multiplying Eq. (12.22) by 4 and then subtracting Eq. (12,21) from
the resultant equation, we obtain (after rearranging terms),
4T(h/2,O)-T(h,o) b
1 =— + 4 h 4 +b 6 h 6 +...
4-1
= T(h/2, 1) + b 4 h 4 + + ... ( 12.23)
where
T(h12, 1) = 4T(h12, 0) - T(Ji, 0)

is the corrected trapezoidal formula using Richardson's extrapolation


technique "once" (level U. Note that its truncation error is of the order
h 4 , instead of h 2 which is the order in the "uncorrected" trapezoidal
formula.
Now, we can apply Richardson's extrapolation technique once more to
Eq. (12.23) to eliminate the error term containing h 4 . The result would
be

16T(h/4, 1)- T(h/2, 1)


= 16-1 +..,

'I/iI4, 2) + C 6h6 + ... ( 12.24)


where
- 16T(h/4, 1) - T(h12, 1)
T(h/4, 2) _ —
16-1
is the estimate, refined again by applying Richardson's extrapolation a
second time (level 2). Similarly, we can obtain an estimate with third-
level correction as
64T(/L18, 2) T(h14, 2)
7W8, 3)
64 - 1
320 Numerical Methods
The entire process of repeated use of Richardson's extrapolation tech-
nique can be represented in general form as
4T(h/2t,j_l)_T(hI2t l , j-I)
T(h12',J)=--- (12.25)
4'-1
where i = 0, 1, 2 ... denotes the depth of division and j :^ i denotes the
level of improvement.
We can further simplify the notation of Eq. (12.25) by defining
R,1 = Ph/2'j)
Thus, we have

= 4J
RIJ
4J 1
(12.26)
Equation (12.26) is known as Romberg integration formula. Note that
this equation, when expanded, will form a lower-diagonal matrix. The
elements of the matrix R are computed row by row in the order indi-
cated in Fig. 12.5. The circled numbers indicate the order of computa-
tions and the arrows indicate the dependencies of elements. An element
at the head end depends on the element at the tail end.

F?(00)

0
®H(1,1)
0)

R(2,0) R(21) -- R(2)

R(3,1) R3.2) , R(3,3)

Fig. 12.5 Order of caiculolions for Romberg Integration


Elements in the first column represent trapezoidal rule at h, h/2, h14,
etc. They can be evaluated recursively as follows:
h = Li -a
R(O,O)= (f(a)+f(b)]
j-

R(i- 10) 2
R(i, 0) - " f(x_1) for i=1,2,... (12.27)
L 2
Numerical Integration 39i
,.-,,here

xk = a + kh
Equation (12.27) s known as recursive trapezoidal rule.

Compute Romberg estimate R 22 for

JlJxdx

First we apply the basic trapezoidal rule to obtain 11(0,0)

11(0, 0) = (a) + f(b)1

+ 1/2) = 0.75
2
Now, we obtain 11(1, 0) and R(2, 0) using equation (12,27)

R(1,0) =R(0,0) + h1f(x1)


2

=x-=0.7083333
2 2 1.5

R(2, 0) = 11(1,0)+ h.jf(x 1 ) + f(x)]


2
0.7083338 +.1
-*-- If(L25)+f(L75)]

= 0.6970237
Now. Romberg approximations can be obtained using Eq. (12.26).
411(1,0)- R(0,0)
R(1,1)=
3
- 4(0.7083333) - 0.75
=0.6944444
3
0)-R(1,0)
11(2, 1)

- 4(0.6970237) 0.7083333 = 0.6932538


3
16R(2, 1)- 11(1,1)
11(2, 2) =
15
92 Numerical Methods

16(0.6932538) -0.5944144
= 0. 6931744
15
Correct answer = 1,(2) = 0.6931471
Error = 0.0000273

Program ROMBRG
Computer algorithm for implementing Romberg integration is simple
and straight-forward. Starting from the element R(0, 0), all the other
elements are calculated row by row. The elements in the first column
are calculate using the recursive trapezoidal rule (Eq. (12.27)) and the
remaining elements are calculated using the Romberg integration for-
mula (Eq. (12?6 11). The process is terminated when two diagonal ele-
ments R(i - 1,j - 1) and R(i,j) agree to the required level of accuracy.
Program ROMBRG implements the steps involved in Romberg inte-
gration.

'itOCRAM i'OMBRG
*- *
Main progidli;
This proqram p erforms Romberg rltegra-on *
by bisecting the intervals N times *
-k
-
---- -- - - - - *

* Functions invoked *
* F,AI3S
* ----------------------------------- *
--- -------*
* Subroutines used *
* NIL
* -- ------- *
-- *
* Variables used *
*
A - StarLing point of the interval *
*
S - End noint of the interval
* H - Width of the interval
N - Number of times bisection is done *
H - Number of trapezoids *
R - Matrix of Romberg integral values
* - ---------- ------------------ *
------------------------- *
c onstants used
* *
EPS - Error bound
*

REAL A , B ..EPS,H,R, SUM, FXAJ3S


INTEGER N,H
INTRINSIC ABS
EXTERNAL F
PARAMETER( EPS = 0.00001
DIMENSION R(11010)
Numerical Integration

WRITE(* , *) 'Input endpoints of the interval'


READ(**) A,B
WRITE(*,*) 'Input maximum number of times'
WRITE(*,*) the subintervals are bisected'
READ(*,) N
Compute using entire interval as one Lrapeoid
H 3-A
R(l,l) = H (F(A) + I'(H))/2.0
WR1TE(*, *)
WRITE( k ,*) R(I,1)
DO 30 1 - 2, Nt-i
Determine number of tra p ezoids for i_th refinement
M = 2**(I_2)
* Reduce step size for 1th refinement
H = H/2
Use recursive trapezoidal rue far M strips
SUN = 0.0
DO 10 K - 1,M
X = A+2kK_1)H
SUM = SUM + F(X)
R(I,i) = R(l_1,1)!2.0+H*SUN
10 CONTINUE
Compute Richardson' s mprovenente
DO 20 L = 2,1
R(I,L) R(I,L-l)+(R(I,LI) -R(I-I.L-1))/ (4*(Ll)_1)
20 CONTINUE
• Write the results of improvements for Ith refinement
WRTTE(*,*) (R(I.L),L = 1,1)
• Test for desired accuracy
IF(ABSR(I-1,I-1) - R(T,I)) .LE. EPS) THEN
* Stop further refinement
WRITE (* *)
WRITE(,') 'RONBERG INTEGRATION =', R(I,I)
WRTTE(*, *)
GO TO 4[)
END IF
* Continue with the refinement process
30 CONTINUE
* write the final result
WRITE(*, *)
RITE( 4 ,') 'ROMBERG INTEGRATION ', R(Nfl,N+1)
WRITE(*,*( '(Exit from loop)'
WRITE , *
H4 Nurneilca! Methods

40 STOP
END
* - End of main ROMBRG --- - *
* Jr

* Function subprogram F(X) *


----------------------- -------------------------------- *

REAL FUNCTION F(X)


REAL X
F = 1.0,'X
RETURN
END
* - • - - ---- - - End of function F(X) ----------------

Test Run Results


)irSt run
Input endpoints of the inervo1
12
Input maximum number of times
the subintervals are bisecred.
I

7. 500000E-001
7.083334E-001 6.944445E-001
ROMBERG INTEGRATION - 6.944445E-001
(Exit from .00p)
Second run
Input endpoints of the interval
12
TuDut maximum number of times
the subintervals are bisected
2

-7 .500000E -001
7. 083334E -001 6.944445E -001
6.970239E -001 G. 932541E -Cal 6.931?47E 001
ROMBEEG INTEGRATION = 6.931747E-001
(Exit from loop)

GAUSSIAN INTEGRATION
Wu have discussed so far a set of rules based on the Newton-Cotes
formula. Recall that the Newton-Cotes formula was derived by integrat-
Numerical Integration

ing the Newton-Gregory forward difference interpolating polynomial.


consequently, all the rules were based on evenly faced sampling points
(function values) within the range of integral.
Gauss integration is based on the concept that the accuracy of nu-
merical integration can be improved by choosing the sampling points
wisely, rather than on the basis of equal spacing. For example, consider
a simple trapezoidal rule as shown in Fig. 12.6(a). Here, the end points
of the integral lie on the function curve. Now, consider Fig. 12.6(b).
Here, the straight line has been moved up such that area B = A + C.
Notice that the sampling points are moved away from the end points.
The function values at the end points are not used in computation.
Rather, function values f(x 1 ) and f(x 2 ) are used to compute the shaded
area. It is clear that the area obtained from Fig. 12.6(b) would be much
closer to the actual area compared to the shaded area in Fig. 12.6(a).
The problem is to compute the values of x 1 and x2 given the values a and
h and to choose appropriate "weights" w 1 and w 2 . The method of imple-
menting the strategy of finding appropriate values of xj and w and
obtaining the integral of 1(x) is called the Gaussian integration or quadra-
ture.

f (b)

-

f (x)

a b
(a) Trapezoidal rule

a x, x2 b

(b) Gaussian rule


Fig. 12.6 Gaussian integration
39 6 Nurnerkul Methods

Gauss integration assumes an approximation of the form

= ff(x) dx f(x) (12.28)

Equation (12.28) contains 2n unknowns to be determined. These un-


knowns can he determined using the condition given in the integration
formula (12.28). This should give the exact value of the integral for
pol y nomials of as high a degree as possible.
Let us find the Gaussian quadrature formula for u = 2. Tn this case,
we need to find the values of w 1 , w9, x 1 and x 2 . Let us assume that the
integral will be exact up to cubic polynomials. This implies that the
functions 1, x, x 2 and x3 can be numerically integrated to obtain exact
results.

+ W2
= Idx = 2

w1x + = x dx I)

+ = Jr 2 IIX

1Aj 1 x + tA) 2 X = Jr 2 dx=0

Solving these simultaneous equations, we obtain


W L = W2 1

x1 =- 0.5113302
=-

= = 0.5773502

Thus, we have the Gaussian quadrature formula for a 2 as

Jf(x)dx =f(-J)+f(lJ-J) (12.29)


-1

This formula will give correct value for integral off (x) in the range (-1,
1) for any function up to third-order. Equation (12.29) is also known as
Gauss-Legendre formula. Two-point Gauss quadrature is illustrated in
Fig. 12.7.
Numerical Integration 397

Fig. 12.7 Illustration of Gauss-Legendre formula

Compute je x dx using t\vo-point Gauss-Legendre formula

I =Jep(xdx

f(x 1 ) +f(x2)
where x 1 and x are Gaussian quadrature points and are given by

xi = - = - 0.5773502

= 0.773502

Therefore,
I = exp(-0.5773502) + exp(0.5773502)
= 0513839 -i- 17813122
= 2.3426961

Changing Limits of Integration


Note that the Gaussian formula imposes a restriction on the limits of
integration to be from —1 to 1. This restriction can be overcome by using
the technique of "interval transformation" used in calculus. Let
b
Jfx) d = C Jg(z) d2
98 Numericof Methods

Assume the following transformation between x and the new variable z.


x = Az + B
This must satisfy the following conditions:
At
x=a, z=-1 and x=b, z=1
That is
B-A = a
A + B -6
Then

A= - -- and

Therefore
b-a a+b
X =---2+

cit
This implies that
b-a
C = ---
Then the integral becomes
b-a1

The Gaussian formula for this integration is


b-a 1-
-b--- Jg(z) dz wg(z1)
-1 ' i-1

where WL and ; are the weights and quadrature points for the integra-
tion domain (-1, 1)

Compute the integral


2
I = Je2dx
-2

using Gaussian two-point formula.


rc= 2 and therefore
Numerical Integration

b—a
'g lw1g(z1) + w2g(z2)]

b—u b-i-a
=2z

Therefore,

For a two-point formula


w 1 = w2 = 1
I
21 =

22 =

Upon substitution of these values, we get


Ig = 2 [exp(-1/V_3_) . exp(1/I)1
= 4.6853922

Higher-Order Gaussian Formulae


By using a procedure similar to the one applied in deriving two-point
formula, we can obtain the parameters w i and ; for higher-order ver-
sions of Gaussian quadrature. These parameters for formulae up to an
order of six are tabulated in Table 12.2.
Table 12.2 Parameters for Gaussian integration

2 1 1.00000 -0.57735
2 1.00000 0.57735
3 1 0.55556 0.77460
2 0.88889 0.00000
3 0.55556 -0.77460
4 1 0.34785 -0.86114
2 0,65215 -0.33998
3 0.65215 +0.33998
4 0.34785 0.86114
5 1 0.23693 -0.90618
2 0.47863 -0.53847
3 0.56889 0.00000
4 0.47863 0.53847
5 0.90618
(Conk!.)
4Q0 Numeric v1eIhods

Table 12.2 (Contd.)


a WI ZI

6 1 0.17132 -0.93247
2 0.36076 -0.66121
3 0.46791 -0.23862
4 0.4679 1 0.23862
5 0.36076 0.66121
6 0.17132 0.93247

Use Gauss Legendre th.ree-point formula to evaluate


4
J(x4-Udx
2

Given n= 3, a 2, and 6 2. hence


3
19 wig(z)
i=1

w 1 9(z 1 ) + w2 9(2 2) + w39(z3)

(b —a) b+cr
X
2
Therefore,
g(z) = (z + 3)4 + 1
For n = 3, we have
0.55556 z = - 0.77460
W 2 0.88889 z2 = 0.0
= 0.55556 z = 0.77460
Then
0.55556 [(-0.77460 + 3)4 + 1]
+0.88889 [(0+3) + 1]
+0.55556[(0.77460 .. 3)4
= 14.18140 + 72.88898 + 113.33105
= 200.40 143
We can verify the answer with analytical solution which is 200.4. Note
that three-point Gauss formula should give exact answer for a second
order polynomial. The difference in the answer is due to roundoff errors.
Roundoff error can be minimised by increasing the precision of Gaussian
parameters.
Numerical Integralion 41

Algorithm 12.1 gives a simple pronodure for implementing Gauss-


L-:gcndre formula.

Gaussian Integration
1 Define the function, Ax)
P. Obtain integration limits (a, b)
3. Decide number of interpolating points (n)
4. Read the Gaussian parameters ( w, i)
5. Compute x, using
(b — a) b-a
xi = ---- z, ±

6. Compute l

/ -

7. Write result

Algorithm 12.1

SUMMARY
In this chapter, we discussed the integration of definite integrals using
numerical integration techniques. The following Newton-Cotes methods
were considered in detail:
• Trapezoidal rule
• Simpson's 1/3 rule
• Simpson's 3/8 rule
• Boo le'.s rule
We also presented a method known as Romberg integration to ho-
prove the accuracy of the results of the trapezoidal method.
We finally discussed another approach known as Gauss integration
which is based on the concept that the accuracy can be improved by
choosing the sampling points wisely, rather than equally.
FORTRAN programs were presented for the following methods:
• Trapezoidal rule
• Simpsons 1/3 rule
• Romberg integration

Key Terms
Boo/es rule Newtons three-eighths rule
Closed form Newton-Coles formula
(Contd.)
40 Numericci Methods
(Con Id.)
Composite approach Newion-Cotes rules
Composite Simpson's 113 rule Numerical integration
Composite trapezoidal rule Numerical quadrature
Extrapolation Open form
Gaussianintegration Recursive trapezoidal rule
Gaussian quadrature Richardson's extrapolation
Gauss-Legnndre formula Romberg integration
Gauss-Lcgcndre rules Romberg integration formula
Integration nodes Simpson's 113 rule
Lagrange interpolation polynomial Simpson's 318 rule
Mu/f/segment approach Trapezoidal rule
Newton interpolation polynomial Variable-order approach

What is numerical integration?


\T}l(n do we need to use a numerical method instead of analytical
i method for integration?
. Numerical integration is similar in spirit to the graphical method
of finding area under the curve. Explain.
4. Explain the basic pnnciple used in Newton-Cotes methods.
5. Describe the trapezoidal xnethi.,d of computing integrals.
9 What is c o mposite trapezoidal rule? When do we use it?
'. in composite trapezoidal rule, the error is estimated to be inversely
proportional to the square of number of segments. That is, we rim
decrease the error b y taking more and more segments. But this
does not happen always. Why? Explain.
8. Describe Simpson's method of computing integrals.
9. Prepare a flow chart for implementing the trapezoidal rule.
10. Prepare a flow chart fbr implementing Simpson's one-third rule.
11. Show that Simpson's one-third rule is exact up to degree 3.
12. Derive Simpson's three-eighth's rule using the first four terms of
Newton-Gregory forward formula.
13, State formulae and error terms for the four basic Newton-Cotes
rules,
14. How could we improve the accuracy of a numerical integration
procc-s?
15. What is Romberg integration? How does it improve the accuracy of
integration?
16. Explain the concept used in Gaussian quadrature.
Numerical integration 403

EWE*EXERCJs$J
• /a1uate analytically th following iiitegra1

(a) J(3x22x_5)

(b) j(3x3+2x2_1)dx

(c) f(3 cos x+5)dx

Evaluate the integrals in Exercise 1 using the basic single seent


trapezoidal rule.
3. Evaluate the integrals in Exercise 1 using the basic Simpson's 113
rule,
4. Evaluate the integrals in Exercise 1 using the basic Simpson's :3/8
rule.
luate the integrals in Exercise 1 using multiple application of
the following rules with n 4.
(a) Trapezoidal rule
(b) Simpson's 113 rule
(c) Simpson's 3/8 rule
Use the trapezoidal rule with it = 4 to estimate

dx
1+x2
correct to five decimal places.
Use Simpson's method with n = 4 to estimate

1+x2
correct to five decimal places. Compare this with the result oh
- tamed in Exercise 6. How do they compare with the correct answer
'20,785398.
1
8. Estimate the following integrals by (a) trapezoidal method and (b)
Simpson's 113 method using the given n:
dx
n=2,4 8
(a)
Ix
J -,

(b)J-_, n=4
404 Numerical Methods

5
(c) Je_ x2 dx, n =8

2 xdx, n6
Cos

(e) j[iTi COS 2 xdx, n.6

(0 j(e x2 1)dx, n=8

(/ The table below shows the temperature f(t) as a function of time.

6 7
[Peratlire_f(t) 81 75 1 0 83 78 70 60 ]

(a) Use Simpson's 1/3 method to estimate

f(t)d/

(I)) Use the result. in (a) to ctirnate the average temperature.


10. Use Romberg integration to evaluate
cosx
(aJ dx
vi_ sill x
3 /2
(b) jexsinxdx
0

c) ------dx
x

2i
(1) 5(5+2 sin x)dx

(e) 5
e l2 1( dx
0
11. Prove that if f" (x) > 0 and a x 5, the value of the integral
h
J(fxt)dx
Numerical Integration 4

by the trapezoidal rule will always be greater than the exact value
of the integral. Verify your conclusion for the following functions:
(a) f(x) 2x
(h) f(x) 1 + x i
The table below shows the speed of a car at various intervals of
time. Find the distance travelled by the car at the end of 2 hours

hr
Speed, kin/hr
71 _____

13. The velocity of a paic1e is governed by the law


sin( t)
u(t) = It 1)2 exp(t
If the initial position of the particle is x(0) = 0, then estimate the
position x(2) using the integral

X(t) =Jv(t)dt
0

by applying a suitable Newton-Cotes formula.


14. Estimate the integral
10 ( '1
I - j
expj dx
)
by Gauss qudrature, with n = 2, 3, and 4.
15. Evaluate the integral

I = J (1 0.25 sin' x)' /? dx


0

using Gaussian quadrature. Assume a suitable value of n.


16. In an electric circuit, the voltage across the capacitor is given by

v(T) =S i(t)dt volts


ü-2
C 0( 'r)
Assuming C = 5F, compute the value of voltage v(T) for T 1, 2,
and 3 seconds.
17. The circumference of an ellipse is given by

2j [(a+b)(ab)].2 9 d&
Circumference =4a
0
406 Numerical Methods

where 2a is the length of major axis and 2b is the length of minor


axis. Find the circumference if a = 30 metres and h 20 metres.
18. The viscous resistance of an object moving through a fluid with
velocity u is given by
1? -
The velocity is decreasing with time t. The time taken for the veloc-
ity to decrease from u0 to v is given by

T - Jdo seconds do seconda


p312
--:
where in is the mass of the object. Estimate the time T required thr
an object with in 30 kg to reach a velocity of 10 rn/sec from an
initial velocity of 20 mlsec.

I. Write a modular program TRAFE2 that uses the following subpro-


grams as modules to evaluate integrals using the composite trap-
ezoidal rules.
(a) Input module (Modulci.)
(in Evaluation module (Mod ulo2)
(c) Output. module (Module3)
Use a function subprogram to evaluate the given fijiitioii.
2. Develop a modular program -ilMS2 (similar to TRAPE2 to eaiu-
ate integrals using multiple application (i.e. composite) of Sinip
son's 3/8 rule.
3. Modify the program SIMPS1 to include a test to determine whether
n is even and stop the execution if it is odd.
4. Write a program that uses two-point Gaussian quadrature to esti-
mate the integral

J f(x)dx

Split the interval into ri equal subintervals and apply the quadra-
ture rule to each subinterval.
5. Show that the integral

1nJX 2 ? 1 th n=1,2,...

can be evaluated recursively by


=1n 'n - i n. 2, 3,
Numerical Integration 407

I
11 -- e

Write a program to evaluate 1 10 using this recursive formula anti


compare the results by Simpson's rule.
6. Write a program to evaluate the integral of a table of points using.
Newton's three-eighth's rule,
7. Write a program to experiment with the integration problem

1 5 cos(x) d

to see if you can determine an optimum value for It using Simpson's


rule.
Note: The trapejoidal rule and the Simpson's 1/3 rule can be used tc
evaluate the integral of a table of points. Development of
FORTRAN programs is left as an exercise to the readers, (U pro-
grams for evaluating the integral of tabulated data are given in the
Appendix D).
APTER-

Numerical Solution of
Ordinary Differential
Equations

NEED AND SCOPE


Many of the lows in ph y
sics, chemistry, engineering, biology and eco-
nomics are based on empirical observations that describe changes in the
states of systems. Mathematical models that describe the state of such
systems are often expressed in terms of not
only certain system param-
eters , but also their derivatives Such
mat hematical models, which use
differential calculus to express relationship between variables, are known
as differential equations.
Examples of differential equations are many. A few of thorn are listed
below to illustrate the nature of ' differential equations that occur in
science and engineering.
1. Law of cooling
The Newton's law of cooling states that the rate of loss of heat from a
liquid is
proportional to the difference of temperatures between the liq-
uid
and the surroundings This can he stated in mathematical form as
dT(1)
= k (T - 7Yf)
(13,1)
where T is the temperature of surroundings,
T(t) is the temperature of
liquid at time t and k is the constant of pioportionality.
2. Law of motion
The law governing the velocity r (t) of a moving
body is given by
Numeocal Solution of Ordinary Differential Eqtiaions 409

dvtl
-F
(13.2)
where m is the mass of the body and P
is the firce acting on it.
3. Kirchj-ioffs law for an electric circuit
The voltage across an electric circuit containing an inductance L and a
resistance R is given by
di
L-iR=V
dt (13.3)
4. Radioactive decay
The radioactive decay of an element is given by
dm
-kmO (13.-)
di
where in is the mass, t is time and k is the constant rate of decay.
5. Simple harmonic motion
The equation to describe a simple harmonic motion is given by
d2 dy
rn--+cI-4ky=U
dt2 di (13.5)
where y denotes displacement and Fn is the mass. Note that d2y/dt2
represents acceleration and dy/dt represents velocity of the moving weight.
6. Force on a moving boat
When a boat moves through water, the retarding force is proportional to
the square of the velocity. The acceleration is given by
du k 2
(13.6)

where m is the mass and k is the drag coefficient.


7. Heat flow in a rectangular plate
The model for heat flow in a rectangle plate that is heated is given by
I
x 2 dy (13.ii
where u(x. y) denotes the temperature at point (x, y) and f(x, y) is the
heat source.
Note that all these examples contain the rate of change of a variable
expressed as a function of variables and parameters. Although most of
the differential equations may be solved analytically in their simplest
form, analytical techniques fail when the models are modified to take
into account the effect of other conditions of real-life situations. In all
such cases, numerical approximation of the solution may be considered
as a possible approach.
41Q NurnecoI Methods

The main concern of this chapter is to present various methods of


numerical solution of a class of differential equations known as ordinary
differential equations. This implies that the differential equations may
appear in different forms. This is evident from ie ex - mples. We, there-
fore, define some important classes of differeuuial equations before con-
sidering the numerical solution of ordinary differential equations.

Number of Independent Variables


The quantity being differentiated is called the dependent variable and
the quantity with respect to which the dependent variable is differenti-
ated is called independent variable. If there is only one independent
variable, the equation is called an ordinary differential equation. If it
contains two or more independent variables, the derivatives will be par-
tial and, therefore, the equation is called a partial differential equation.
Eqs. (13.1) to (13.6) belong to the class of ordinary differential equations
while Eq. (13.71 is a partial differential equation. In this chapter we
shall consider only the ordinary differential equations.

Order of Equations
NJ
Differential equa1ion are also c1ed according to their order. The
order of a differential equation is the highest derivative that appears in
the equation. When the equation contains only a first derivative, it is
called afirst-order differential equation. For example, Eqs (13.1 . ) to (13.1)
are first-order equations. On the other hand, if the highest derivative is
a second derivative, the equation is called a second-order differential
equation. For example, Eq. (13.5) is a second-order equation.
A first-order equation can be expressed in the loirni
dv
dx = /x, v> I 13.8

A second-order equation can be expressed in the form


( 1 113.9)
where y" denotes the second derivative and v' is the first derivative.
Higher-order equations can he reduced to a set of first-order equations
by suitable transformations. For example, the equit ion
= f(x, v, y
can he equivalerilly represented by
U' = t'(x, ,v UI

D e 9 oi Fquati
Sometjm, th qtui.ion. are referred to b y their degree. The degree of
Numerical Solution of Ordinary Differential Equations 411

a differential equation is the power of the highest-order derivative. For


example,
xy"±v2y'=2v^3
is a first-degree, second-order equation while,
+ y' = 0
is a second-degree, third-order equation.

Linear and Nonlinear Equtions-,(-- t\) J


rifferentia1 equation is known as a linear equation when it does not
contain terms involving the products of the dependent variable or its
derivatives, For example,
y" + 3y' = 2 +
is a second-order, linear equation. The equations
-i- (v' 2 = I
y' -ay2
are nonlinear because the first one contains a product of y' and the
second contains a product oiy.

General and Particular Solutions


A solution to a differential equation is a relationship between the de-
pendent and independent variables that satisfy the differential equa-
tion. For example,

is the solution of
(ix - 1
Similarly,
y=(7X

is the solution of
=V

Note that each of the solutions given above is only one of an infinite
number of solutions. For example,
Y= 3x + x + 2
y 3x2 + x - 10
are also solutions of y' = 6x + 1. Tn general, y 6 ± 1 has a solution of
the form
=
3X 2 I x + c
where c is known as the constant of integration. Similarly, y' y has a
solution of the form y = ae', The solution that contains arbitrary con-
stants is not unique and is therefore known as the general solution,
412 Numeilcal Methods
If the values of the constants are known, then, on substitution U.
these values in the general solution, a unique solution known as particu-
lar solution can he obtained.

lnhaf Value Problems


-
In er to obtain the values of the integration constants, we need addi-
tional information. For example, consider the solution y = ocx to the
equation y' = y. If we are given a value of y for some x, the constant a
can be determined. Suppose y = 1 at x = 0, then,
y(0) =1
Therefore,
a- 1
and the particular solution is

If the order of the equation is a, we will have to obtain r von4ants and.


therefore, we need a conditions in order to obtain a unique solution
When all the conditions are speciffil i at a particular value of the : dc-
pendent variable x, then the problem is called an I; tial . euiue problem.
It. is also possible to specify the conditions at different values of the
independent variable, Such problems are called the boundary -value pmh-
(ems. For example, if, instead of specifying only yCO; 1, we also specify
v(0) + vii = 2, then th problem will he a bowidarv-valuv problem.
In
this cas,,
Y1 0 ) +y(l.i - oil ^ C) - 2
giving
a = 2/ti + C)

One-step and Multistep Methods


All numerical techniques for solving ditidrential equations involve a se-
ries of estimates of vx starting from the given conditions. There are tw
bask approaches that could be used to OsLi!riLe the values of-yx). They
are known as one -s/ep i cthvds and in eltisiep methods.
In one-step methods, we use information from only one preceding
point, i.e. to estimate the value v 1 , we need the conditions at the previ-
ous point v onl. Multistep methods use informatiort at two or more
Previo us steps to estimate a value.
Scope
In this chapter, we mainly concentrate on the solution of ordinary differ-
ential equations and discuss the following methods:
1. Taylor series method
2. Euler's method
3. Heun's method
Numerical Solution of Ordinary Differential Equations 41.

4. Polygon method
5. Runge-. Kutta method
6. Milne-Simpson method
7. Adams-Bashforth-Moulton method
The initial value problem of an ordinar y first-order differential equation
has the form
Y (X) = x, v(x)), y ( x 0 ) ( 13.10)

In this chapter, we determine the solution of this equation on a finite


interval (x 0 , b), starting with the initial point x 0. For the sake of simplic-
ity, in a number of places, we use ffor f(x, y ), y for y(x) and v for v(x).

TAYLOR SERIES METHOD

We can expand a function y(x) about a point x x 0 using Taylor's theo-


rem of expansion

Y(X) = y (x 0 ) +(x — X U ) y'(x 0 ) +(x _xo)2) (o)

yfl)
(13,11)
---In
where y '(x0) is the ith derivative of y(x), evaluated at x = x0. The value of
y(x) can be obtained if we know the values of its derivatives. This im-
plies that if we are given the equation
y'=f(x,y) (13.12)
we must then repeatedly differentiate f(x, y) implicitly with respect to x
and evaluate them at x0.
For example, if y' = f(i, y) then

=__'J_c!_If(x,y)]
dxI dx
dx ( L

=--[f(x,y)]
dx
+If( x' y)l—
t9y dx

=t+Tff1 +fxf (13.13)


dx dy
where f denotes the function f(x, y) and f and f, denote the partial
derivatives of the function fx, y) with respect to x and y, respectively.
Similarly, we can obtain
y =f + 2f f, +ff +ff +ff 2 (13.14)
Let us illustrate this through an example.
41.4 NumerIcal Methods

Consider the equation


y,=x2+y2
under the condition y(x) 1 when x = 0,
y' = x +
Y" = 2x + 2yy'
2 + 2yy" + 2(y')2
atx0, (0) = I and, therefore,
y'(0) = 1
y"(0) = 2
y"(0) = 2 + (2)(1X2) + ( 2)(1) 2S =
Substituting these values, the Taylor series becomes

1 ± x + X2 8 X3
Yix) = + + ... (13.15)

The number of terms to he used depends on the accuracy of the solution


needed.

Use the Taylor method to solve the equation


=x+
for x = 0,25 and x = 0.5 given y(0) = 1

The solution of this equation is given by Eq. (13.15). That is,

y(x) 1 + x + x,, + 8 x3+


Therefore,
y(O-25) = 1 + 0.25 + (0.25) + (0.25) +

= 1.33333
Similarly,
v(0.5) = I 0.5 + 0.5 + (0.5) +

= 1.81667

Improving Accuracy
The error in Taylor method is in the order of x - x0i' . if I x - I is
large, the error can also become large. Therefore, the result, of this
method in the interval (x0 , hi when lb -- .x 0 ) is large, is often found
unsatisfactory.
Numerical Solution of Ordinary Differential Equations

The accuracy can be improved by dividing the entire interval inb


subintervals (x 0, x1 ), (x 1 , x2 ), (x2. x.), ... of equal length and computing
x = 1, 2.... . a successively, using the Taylor series expansion. Here,
y(x) is used as an initial condition for computing v(r .1 ). Thus,

y(x)y(tl+ ---i--- (x., - x 1 )+ -.. (X, 4 ] -x)-f

+ - (13.16)
in!
If we denote the size of each subinterval as h, then,
x i , 1 —x--h for t=0,l,...,n_i
and Eq. (13.16) becomes

The derivatives y are determined using Eq. (J3.12), (13.13) and (13.14)
at x = xj and y = y1. This formula can be used recursively to obtain y
values.

Use the Taylor method recursively to solve the equation


y'=x 2 +y 2 , y(0)=O
for the interval (0, 0.4) using two subintervals of size 0.2.

The deriva Lives of y are given by '

y"=2x-+.2yy'
y" = 2 + 2(y)2 + 2yy" .
(4)
Y =6yy +2yy' ill
Iteration I V)

Ii = 0.2, y, =y(0) 0
Yó = )"(0) = 0 - y(0)2 = 0
y f = y"(0) 2 x 0 + 2 x y(0) x y(0) 0
AM Numerical Methods
Similarly,
Y6" = 2

Y )4 0
Therefore,
y 1 =0+0 f f

= 0.002667 (at x = 0.2)


Iteration 2
0.2
= 0.002667
y _; +y = ( 2 0 . 2) 2 + ( 0.002667)2 = 0.04

= 2x1 + 23,1Yj
= 2(0,2) + 2(0.002667) (0.04)
= 0.400213
Y = 2 + 2(y)2 + 2y 1 y'
= 2 + 2(0.04)2 + 2(0.002667) (0.400213)
= 2.005335

Y 1 -6yy' +2y1y"
= 6(0.04) (0.400213) + 20.002667) (2.005335)
= 0.I0674)

y2yl+yj/h2+h31-h4

0.002667 + 0.04(0.2) + P:P1.i (0.2)2

+ 2.005335 (0.20 + 0.106748


6 24
= 0.021352
That is
y(O.4) = 0.021352
If we use h (h - = 0.4 (without subdividing), we obtain

y(O.4) (0.4)"= 0.021333

The correct answer to the accuracy shown is v(0.4) = 0.021359. It shows


that the accuracy has been improved by using suhintervals. The accu-
racy can he further improved b y reducing h further, sa y , 1? = 0.1.
Numerical Solution of Ordinary Differential Equations 411

One major problem with the Taylor series method is the evaluation of
higher-order derivatives. They become very complicated. All these de-
rivatives must be evaluated at (;, ye), i = 0, 1, 2. .... This method is,
therefore, generally impractical from a computational point of view. How-
ever, it illustrates the basic approach to numerical solution of differen-
tial equations.

Picard's Method
Consider the differential equation
dy
.
/ k -, y)

We can integrate this to obtain the solution in the interval (x 0, x)

I dy = 5 f(x, y)dx

or

Y(X) =y(x0) + Jf(x,y)dx


XO

Since y appears under the integral sign on the right, the integration
cannot he formed. The dependent variable y should be replaced by either
a constant or a function of x. Since we know the initial value of y(at x =
x0 ), we may use this as a first appropriation to the solution and the
result can be used on the right-hand side co obtain the next appropria -
tion. Ihe iterative equation is written as

Y' + Y + I f(x, y(o) dx(13.18)

Equation (13.18) is known as Preard's method. Since this method in-


volves actual integration, sometimes it may not be possible to carry out
the integration. Example 13.3 illustrates the application of Picard's meth-
od.
It can be seen that Picard's method is not convenient for computer-
based solutions- Like Taylor's series method, this is also a semi-numeric
method.

Solve the following equations by Picard's method


(i) y'(x)=i 2 +y2 . y(0) = 0
ii) y'(x)=xr', y(0)=0
and estimate y(O.l), y(O.2) and y( 1)
411 Numerical Methods
(i) y'(x) x2
+ Y2
Yo 0' x0=0

(l) y0+J(x2+(y°)2)dx

=0+1 ,

Y 04- J (x 2 +(y')2)dx
Xu

4( 2 +Jdx=-+i

This process can be continued further although it may be a difficult task.


If we stop at y(2, then
Y(X)
=-+±
3 T3
y(O.1) 0.000033
y(O-2) = 0.0026667
Y(1) = 0.3492063
(ii) y '(x) = xe)
v,=0, x0=0

XLi) = 0
J Xe 0 dx =

I
=0 + XCX2 12 dx (x 2 12) -
f
U
Note that further integrations will become more difficult and even im-
possible. Now, let us assume
Y(X) _.(2) =e2'2) 1
y(O.l) = 0.0050125
y(0.2) = 0.0202013
y(l) = 0.64872 13
We know that the exact solution of y'(x) = xe is

y(x)
Numerical Solution of Ordinary Differential Equations 41

Therefore
y(0.1).(fl0.0050125
Y(0•2)PaCt = 0.0202027
y(l) = 0.6933147

Note that the error increases when (x - x 0 ) increases. Better accuracy


can be achieved by using the new initial value i.e. y (0.1) can be used
as the initial value for computing v(O.2), instead of y(0).

EULER'S ME OD

Euler's method is the simplest one-step method and has a limited appli-
cation because of its low accuracy. However, it is discussed here as it
serves as a starting point for all other advanced methods.
Consider the first two terms of the expansion (13.11)
y(x) = v(x 0 ) -i- y' (x i ,) (x - x)
Given the differential equation
y'(x) = f(x, y) with y(x0 ) =
we have
y'{x ( ,) = f(i 0 , Y)
and therefore
Y(X) y(- 0 ) + (x - x 0 ) f0c0 , Y(J)
Then, the value of y(x) at x x is givPn by
y(x 1 ) y(x (,) - x e,) f X I-1, Yo)
Letting h = x0, we obtain

Yi Ye + h fix 0 , Ye)
Similarly, y(.x) at = x 2 is given by
Y2 y 1 + h f(x 1 , yj)
In general, we obtain a recursive relation as
(13.19)
LeIi_1y1+hf(.,1
This flirmula is known as Euler's method and can be used recursively
to evaluate y 1 , y ..... . of y(x 1 ), y(x2 )..... .starting from the initial condition
= vx 0 ). Note that this does not involve any derivatives.
A new value of y is estimated using the previous value of y as the
initial condition. Note that the term It f(x, y) reprcsent.s the incremen-
tal value of and f(.x1 , y,) is the slope of y(x) at (x1 , y 1 ), i.e. the new value
is obtained by extrapolating linearl y over the step size It using the slope
at its previous value. That j
New value aid value + slope x step size
An Numerical Methods

This is illustrated in Fig. 131, Remember thaty 1 approximates y(x 1 ) and


Y2 approximates The difference between them is the rror intro-
duced by the method.
'

y(x)

Exact value /Actual solution y(x)


of &2)
/ Error in y2
--- Tangent line
Exact value at (x y1)
of /' --
N. Y2)

(x1, yi)
Tangent line Error in yt
at (, y0)

XG xl x?

Fig. 13.1 Illustration of Euler's method for two steps

Given the equation


dy
= 3x 1 with v(1) = 2
dx -
estimate y (2) by Euler's method using (i) Ii = 0.5 and (ii) h = 0.25.

(i) h 0.5
y(l) 2
y(l.5) = 2 + 0.5[3(1.0) - 11 = 4.0
y(2.0) = 4.0 + 0.5[3(L.5)' + 11 = 7.875
(ii) h = 0.25
y(l) = 2
y(1.25t = 2 + 0.2513W 2 + ii 3.0
y0.5) = 3 + O.25[3(1.25)2 + 1] =.42188
ytl.75 = 5.42188 + 0.25[3(1..5)2 + 11 7.35938
y(2.0) = 7.35938 + 0 .253(1 . 75 )2 + 1] = 9.90626
Numerical Solu t ion of Qrdinar1/ Differential Equations 41
Notice the difference in answers of y(2) in t'uese two cases. The accuracy
is improved considerably when h is reduced to 0.25 (true answer is 10.0).

Accuracy of Euler's Method


As usual, the accuracy is afThetcd b y two sources of error, namely, round-
off error and truncation error, Roundoff -ror is alwy 5 present in a
Computation and this can be minimised by increasing the precision of
calculations.
The major cause i toss of accuracy is truncation error. This arises
because of the use of a truncated Taylor series. Since Euler's method
uses Taylor series iteratively, the truncation error introduced in an it-
eration is propagated to the following iterations. This means the total
truncation error in any iteration step will consist of two components- the
propagated truncation error and the truncation error introduced by the
step itself.
The truncation introduced by the step itself is knOWfl as the local
truncation error and the sum of the propagated error and the local error
is called the y 1obal truicca lion error. Recall the Taylor series expansion
used iii Euler's method for estimating the values of y1.

tv/h +Lh 2 ±4ha.+...

Since only the first two terms are used in Euler's formula, the local
triuication error is given by

h2^ h •- —h
2
If the step size h. is very small, the higher-order terms may he neglected
and therefore

- 11. 2

The above analysis assumes that the function y' f(x, y) has continu-
ous derivatives. The local truncation error of El uler's method is of the
order h 2 , If the final estimation requires a steps, the total (global) trun-
cation error at the target point b will be

f Erg c C")/12
= ± + ... ± = nch2
where
= (C 1 + c - ... + c,. /0
Since
a (h -
Etg! -(h-x0jch
422 Numerical Methods

Compute the errors in the estimates of Example (13.4) when /i = 0.5


Given
= 32 ± 1
= fi
y"' 6
Step I
x0=1, v0 r2
- y(l.5) = 4.0 (from example (13.4))

E"

= (,0.5') 2 -4
q (0.5) -3 = 0.875
Step 2
= 1.5. V = 4.0

Y2 = y(LO) 7.875 from example (13.4))

E, 2 :±1(U.5j2 ±(0.F) -: L25


Exact solution is
y(x) x 3 + a
and therefore
True y(l.S) = 4.875
True y(2.0) = 10.000
The estimated and true values of and corresponding errors are tabu-
lated below.

Estrnrzt .dy fTrueT E Giol)a.1

4.875 L. 0.875
1- 2.0 7.875 _10.0(J1.250 2.125

Note that the local and global errors are equal at the first step and
they are different in the second step. The difference between them is the
propagated truncation error that results from the first step.
Observe that
= 0.875 since c r- 35

r 2(0.5) = 1.250 since c. 5.0


C = (c1 +C24 = 4.25
Etg c(b - x 0 )h = 4.25 x 1 0.5 = 2.125
NumeicaI So'(Ation of Ordinar y Differential Equations 4.

This confirms the error equations for local and global truncation errors
discussed in this section,

Program EULER
The program EULER estimates the s , of the first order differen-
tial equation y' f(x, y) at a given point using Euler's method (Eq.
13.19). The program is simple and self-explanatory . Note the use of an
intrinsic function ' in the line
N -- X)/H O.)
Given initial value of x and the point of solution x, this statement
computes the number of steps required for evaluation using the speci-
fied stop-size H. The tinction TNT returns the nearest integer of the real
value
XPP-x
H
* -------- -------.----- ---------------
l'i'OGPAM
- -- - - - - - - - - - - - - - - - - - -- - - - - - - - - -- - - - - - - - - - - - - - -- - -- - *
* Main prograis *
* Ti prurusi est ira-s he solution oC tLu fIrst *
* crcior differential q-uaLaori y' fix, yi at a *
* given joirit usin g Euler's rncrtod *
* - ------ *
* Func'c ons nvokod
* F. 1NT

Shr oit. nc's used *


* NIT *
-- -- --.- --------

Varih'Les used *
X - Intii vaLue ef indop dent v.abio
* V - ThiI.iaI viuc *
of doi:endect 'jar labIa
XP - ioinc of soL..t 01!*
F! - Tncrcrr.enta1 Fucjp-u:zo
* N !urnbs'--'f co oat j ora! ijLei:,r; rccu iced *
* DY norenerta Y cn each sten

* (:onsa:it user",
* NFL *
* ----------------------------------- ---*

REAL
INTEGFN N,
EXTPD-t. F
INTRI-5SIC LNI
424 Numcrlca; Methods
WRITE (
WRITE(* , 1) SOLiJ'I'ION 1Y EULERS METHOD'
WRITE(*. )

Read values
WRITE(*,*)
'Input initial values of x and y'
READ(*,*) Xy
WRITF(, 'Input x a wh(-- y Is required'
READ*,*) XP
WRITES , ,*) 'Input step--size h,
READ(**) H

Compute number of steps required


N

Compute Y recursively at each step

DC 10 I = 1,N
D'r = HF(X,Yj
=
Y+nY
WRITE(",
10 CONTINUE

* write the f.na1 result


WPITE(*, *)
WRITE(,, *) 'Value of Y at X =',X, ' is', V
WRITE(*,*)
STOP
END

* ---- End of main EULER - *


* ---- -.--
-------------------- -----
Furction subprogru[L *
*
- ----
REAL FUNCTION F(X,Y
REAL X, Y

F = 2.0 * Y/X

RETURN
END

* ----------- End of function F(X,Y) _________________


Numerical Solution o Ordinary Differential Equations 4
Test Run Results
S0L1:JioI 2'
Inpue iniLie i veJue 01 x and v'
1.0 2.0
Input- x it tti j c1 y i e q u i. rad
2.0
1rpui otop-sic h
P. C

1 1 .200000 3.0000000
2 i.5000o 4.2000000
3 1.7500000 5.6000000
4 2.0000000 7.2000000
Value of Y aL X = 2.0000000 i 7.2000000
SOca - Procjr p :crminstrd

HEUN'S METHOD
Eider's method is the simplest of all one-step methods. It does not re-
quire an y differentiation anti is easy Lo implement on computers. How-
ever, its major weakness is large truncation errors. This is due to its
linear characteristic. Recall that Euler's method uses onl y the first two
terms of the Taylor series. In this section, we shall consider an improve-
ment to Eulers method.
In Euler's method, the slope at the beginning of the interval is used to
extrapolate y 1 to y . over the entire interval. Thus,
= y + m1/i
where m 1 is the slope at (xe, y1 ). As illustrated in Fig. 13.2, y , is clearly
an underestimate ofy(x +

AX)
X)

o (Estimated using m2)


slope in ,/ Tangent at X x, ) (slope m2)
slope in,
slope m-, \

>c\ )T

XXI)- .. -.,-. (
/ - -\- ->- - y,, (Estimated using m)
Heun's method)
yj (Estimated using m1)
-
xi x,1 - x
Fig. 13.2 tilustratiun of Heun's method
426 Numerical Methods
An alternative is to use the line which is parallel to the tangent at the
point , y(x, )) to extrapolate from y, toy, * as shown in Fig. 13.2.
That is
Yi + y, + m2h
where in 2 is the slope at (x , y(, i. Note that the estimate appears
to he overestimated.
A third approach is to use a line whose slope is the average of the
slopes at the end points of the interval. Then
ni l + in 2
(13.20)
2

As shown in Fig. 13.2, this gives a better approximation to v . This


approach is known as 1.-leun's method.
The formula for implementing Hetin's method can be constructed easily.
Given the equation
y'(x) = ftx, y)
we can obtain
m1 y'(x,) = f(x, v)
m2 = y'(x, + i) f(x, 1, y +
and therefore
f(x,, y)+ )
M = -
2
Equation (13.20) becomes

(X,, vj) + f L-X^ + 1 , y ., + I A (13.21)


2
ry—I _-_^ Y I+
_ -

Note that the term y appears on both sides of Eq. (13.21) and, there-
fore, YL + cannot be evaluated until the value of y + inside the function
f(x1 + , y + i is available. This value can be predicted using the Ruler's
formula as
[ y , T = y + h x fxYj (13.22)

Then, Heun's formula becomes

=y, (13.23)

Equation (13.23) is an improved version of Euler's method. Since it


attempts to correct the values of y 1 + 1 using the predicted value of y +
(by Ruler's method), it is classified as a one-step predictor-corrector
Numerical Solution of Ordinary Differential Equations 47
rnet/wd. Eq. (13.22) is kndwn as the pred)c/w•
and Eq. (13.23) is known
as the corrector. Substituting Eq. (13.22 into Eq. (13.23), we obtain

+ [fix,, vi., + /' + Ii fix. y ,M1 (13.24)

I Eia mple L34


Givi'n the quaton
y'(x) = 2yix with y (l) = 2
estimate y2) using (i) Euler's method, and (ii) Heun's method, using
It = 0.25, and compare the results with exact answers.

Given
= r.1, y) 2y/.v
)'2. h-0.25
(i) Euler's met/icc!
-Y( 1.25) = V, = h. f(x, Y',

=3.00

y(1.5) = 3.0 + 0.2542


1,25
4 9 9
5 _.1_'= 5.15
= 4.2 f 0.2
1.5
x
y(2.0) = 5.6 + 0.25 2 5.67.2
lii) Heu.n's method
lteratioi 1

22
= 4.0
e u12 2 + 0.25(4.0) = 3.1)
2v30
17 = 4.8

v(1.25)r 2 1 (4.0 + 4.8) = 3.1


2
Iteration 2

2 x 3, 1
m1 = 4.96
= 3.1 + 0.25)4.96) = 4,34
4a Numericcil Methods

2 x 4.34
rn2 4.8
= --,---- -

(1.5) = 3.1 + (196 + 5.79) = 4.44


Iteru tion 3
2 x 4.44
5.92
y 1.75) = 4.44 I. 02515.92) = 5.92
2 x 5.92
677

v(1.75) = 4.44 +0.25 5.92 + 6771 = 6.03


hera/ton 4
2 6.03
rn1

y,(2.0) = 6.03 + 0.25(6.39) 7.75


2K ,775
(11 2 = = 7.75

y(10 - 6,03 + P. 6.89 + 7.75) 7.86

Exact solution of the equation


), '(x) 2v.x with ytli = 2
is obtained as
y(x)
The exact values of y(x) and the estimated values by both the methods
are tabulated below.

L Euler's_methodeun'srnethOdLAflalYt1Cal

HHiHiH_
1.50 4.20 4.44 4.50
^^1.75 5.60 6.03 6.125

2.00 7.20 7.811 8.00


All estimated values are accurate to two decimal places. it is clear that
Ieuns method provides better results compared to Euler's method.

Error Analysis
It can be easily shown that Heun's method is a second-order method
Numerical Solution of Ordinary Differential Equations 429

and, therefore, its local thiincation is of the order V. Let us consider


Eq. (13.24). Letting i = 0, for simplicity, we obtain

= y0 + A (In i + f(x0 + h, y 0 + rn 1 hi] (13.25)

Let us expand the term f(x0 h' y 0 + m 1 h) in a Taylor series form.

fix0 + h, y0 + ,n 1 h ) = f(x 1) , v 0) + h --- m 1 h


Lx

= + hf1 + m1hf
On substituting this into Eq. (13.2) we get

y1 =Y + hin, + (f + m 1 f) (13.26)
We know that
rn1 =
+ m I fi = y " ( see equation (13.13))
and therefore Eq. (13,26) can be written as

y i y 0 +h It
it
This proves that Noun's method is of order 1i and the local truncation
error is of the order h 3 , If the final estimate is obtained after u itera-
tions, then the global truncation error is given by

ch 3 = nc'h'1

We know that
X? -x 0h- x0

Therefore,
-r (b -- c)ch2
That is, the global tr)ncntion error is of the order h.

Program HEUN
The algorithm of Heun's method is implemented b y the program HETJN.
Note that the algorithm is very similar to that of the Euler's method,
except for the slope used in extrapolating the initial value.
* - --- ------.-.---- --- - *
PROG1-.Ai
* -------------------------------------------------------- *
* 14j pro.-am *
T)is prcq:-om n . i.v:: be f.r-s;. rcie dffaenta
_00 Numericol Methods
* equation y' r [x, Y) using neueun
* *
Functions invoked
* F,INT
* ---- *
-
* Subroutines used
* *
NTL
* --- ------- --------
* Variables used
X - initi vaue of
* '•.'atiiij-
y -- Initial value of de p
* endent vaiiabi
NP - Poirt of so1iL!on *
H -- Step-s:ze
* 1.
N - Number of steps
*
Constants used
* NIL
*

* --------- -------- - ------------- *

REAL
INTEGER N, INT
INTRINSIC INT
EXTERNAL F

WRITE(* *)
WRITR(*, *) SOLUTION BY 1-IETJNS METHOD'
WRITE(*, *)

* Input. viues

WRITE(*,*) inp1t 1flia values of x and y'


READ* , *) Xv
WTtlTE(*,
Inpc x at which y is rucraied'
READ*,*) NP
WRITE(**) 'Input step-size h'
READ(*,*) j.
*
Comp ute number of steps required
N

* Compute Y recursively at each step


DO 20 I l,N
Ml = F(X,Y)
M2 = F(X+H, Y+Ml*H)
X = X+H
Y -
WRITE(*,*) i,xy
Numerical Solution of Ordinary Dftferenfia! Equations 41
20 CONTINUE
*
Write the final result

WR1TE(, k)
WRITE(*.*) ' Vrt! '2P of '{ at x ' is,,Y
WRITE(* , *)

STOP
END
* -------------
End of no iCEUN ------------------*
* - --------
------------------------------------------
Function subprogram

REAL FUNCTION F(X,Y)


REAL X, Y
F 2.0 * y/x
R1-.'TU RN
END

End of funct jtn F(x y ) --------------------*


Test Run Results

F] -----
rS run
SOLUTION BY MEU5 METHOD
Input: -v&1U0S of x and y
1.0 2.0
input x at which y is requIred
2.0
Input Seep-size h
0.25
1 .2500000 3.1000000
2 1.5000000 4.4433330
3 1.7500000 6.0302380
4 2.0000000 7.8608460
ValTle Of Y at X 2.0000000 is 7.8608460
Stop - PLuaa:fl terminated
Second run

SOLUTION BY HEUNS METHOD


Input inlOin] valufs of xand y
1.0 2.0
Inp ut x at which y is required
2.0
432 Numerical Mothods
Input step-size S
0.125
1.1250000 2.5277780
2 1.2500000 3.1175920
3 1.3750000 3.7694530
4 1.5000000 4.4833640
5 1.6250000 5.2593310
6 1.7500000 6.0973560
7 1.8750000 6.9974420
8 2.0000000 7.9595900

Value of Y at X 2.0000000 1s7.9595900

Stop - Program terminated.


Third run
SOLUTION BY HSJNS METhOD
Input initial values ui x and y
1.0 2.0
Input x at which y is required
2.0
Input step--size S
0.1
1 1.1000000 2.4181820
2 1.2000000 2.8761710
3 1.3000000 3.3'1 39700
4 1.4000000 3.9115800
5 15000000 4.4890040
6 1 . 0000000 5.1062420
7 1.7000000 5.7632950
8 1.8003000 6.4601640
9 1.9000000 7.1968490
10 2.0000000 7.9733510
Value of Y at X = 2.0000000 is 7.9733510
Stop - Progtarn terminated,

POLYGON METHOD

Another modification of Ei.iler's method is to use the slope of the func-


tion at the eotimated midpoints of (x i , y) and y,) to approximate
Y+i Thus,

(xL+xL )'+Yi
= + 2

Y. + + h12, y +Ay/2)h (13.27)


Numerical Solution of Ordinary Differential Equations 433

\y is the estimated incremental value of y from y, and can he obtained


using Euler's formala as
Ii f(x, VL)

Then, equation (13.27) can be written as

Y)+l ),, + hf (x + h/2, v + h/2 f(x,


yj + hfx + h'2, y + ,n 1h12) (13.28
L=Yi + 11121?

where
( hm1h
171., = t ( x1 , y . arid 1719 = fx + +

Equation (13,28) is known as the modified Euler's method or improved


polygon. inrthod. The method, also called the midpoint method, is illus-
trated in Fig. 13.3.

/ ,,,Error in y,
Y,i
Slope rn
Slope m1

x+h/2 X41 x
Fig. 13.3 Midpoint method
Like Ileuri's method, this method is also of the order h2 and therefore,
the local truncation error is of the order 10 and the global truncation
error is of the order 1i,

Estimate y(l.5) with h 0.25 for the equation in Example 136 using
polygon method.

23!
Y' =f(x,y)=----
AM Numerical MeThods
y(l) = 2.0
y(l.25) 2.0 + 0.25 [(1 + 0.125, 2 + 0 .125f( 1 , 2))
2.0 + 0.25 [(1.125, 2.5) 3.11
y(1.5) = 3.11 + 0.25 1(1.25 -s- 0.125, 3.11 + 0. 1 25 [( 1. 25 , 3.11)
= 3.11 -f 0.25 f(1.375, 3.732) = 4.47

Estimated values of y(1.5) by various methods for the equation


y (x) = 2y/x with y(1( = 2.0
are given below:
Euler's method : 4.20
Heun's method : 4.44
Polygon method : 4.47
Exact answer : 4.50
Note that the polygon method yields better results compared to the
Heuri's method.

Program POLYGN
Program POI.YGN implements the polygon algorithm to solve a differ-
ential equation of type y = f(x, y)
* - -------------------------------------.---
PROGRPJ PCL'?GN
* r proq'in
* ['h prqrara solv€s the di ffer nLial eTJatiofl
by polyqon method *

*
4' Func L or:s irivo:cd
* 'F, IN'r
*
* --------------- ---- ---------------- -------------------_ *
* Subrouh nec used
* NIi k

* --------------------------------------------------- *

* Viriables used
* X - Lii Lial value of the indepeecient variable
*
* Y - ird r_ial value of the dependent variable *
* xp - point el soiuhon *
H - Increrneni.el step--sise *
* N - Number of computational st.opc required *
* -------------------------------------- - ------------.- *
* Constants used *
* NIL
* ------ --------------.--- -----*
Numerical Solution of Ordinary Di fferential Equations
43
REAL X,Y,XP,H,M1,N2F
INTEGER N,INT
INTRINSIC TNT
EXTERNAL F
WRITE
WRITE(*, ) SOLUTION BY POLYGON METHOD'
WRITE ( *
Input values
WRITE(*,) 'Input
initial values of x and y'
READ(*,) X,y
WRITE(*,*) 'Input x at which y is required'
READ(*,*) XP
WRITE(*,*) 'Input step-size h'
READ(,)
Compute number of steps required
N - INT((XP-x)/H+05)
Compute Y at each step
DO 30 1 = iN
Ml = F(X,Y)
M2 =
X = X+H
Y = Y+M2H
WR1TE(*,*) I,X,Y
30 CONTINUE
* Write the final value of Y
WRITE ( *
WRITE(*,*) 'Value of V at X ', X, ' is', V
WRITE ( , *)
STOP
END

* ---------------End of main POLYGN ------------------*


* --------------------------------------------------------*
* Function subprogram
* -----------------------------------------------------**

REAL FUNCTION F(X,Y)


REAL X,Y
F = 20 YIX
RETURN
END
* ---------------End of function F(x, y ) ---------------*
hi

4 Numerical Methods

Test Run Results


SOLUTION BY POLYGON METHOD
Input initial values of x and y
1.0 2.0
Input x at which y is required
2.0
Input step-size h
0.25
1 1.2500000 1.1111110
2 1.5000000 4.4686870
3 .1.7500000 6.0728310
4 .2.0000000 7.9235990
Vaof Y at X = 2.0000000 i s 7.9235990

\ /j
Stop - Program terminated.

RUNGE-KUTTA Fv CTHODS
N
\.._/ RungeKutta methods refer to a family of one-step methods used for
numerical solution of initial value problems. They are all based on the
general form of the extrapolation equation,
= y + slope X interval size
= Y A + inh
where m represents the slope that is weighted averages of the slopes at
various points in the interval h. If we estimate m using slopes at r points
in the interval (xi, ; then in can be written as
m = w 1 m 1 + 14) 2 771 2 + •.. + W. m r (13.29)
where w 1 , w 2,..., W r are weights of the slopes at various points. The
Slopes m 1 , 1719.....m r are computed as follows:
= f(x, y)
= f(x1 + a 1 h, y + b 11 'n1h)
M 3 = f(x + cx 2h, y + b 21 m 1 h + b 22 rn2h)

rnh. = + a, -1 h, y + br_i t 171 I h + ... + bri r-i mr_i h)


That is
rnJf(x,y) r=1

fi r f X i ±a ri h,y L +11, b 11 mj r^!2 (13.30)


NumereI S)!jtVn C' Crcj nr-ir,, Differential 4.37
Not ::i the cornput' L:erI 01 Si " ' Pe it P't ]iiU'V5 the slops n iii
pr'iL• ei !:r'oi,. Slope-1- c:. le )a'putad 1TCui.
'ly u g LqULi6011 1 13 :t
starting crorn 7n1
ljncr eKutta cRK incthod:, o::e kncwn b their ' • r For j u'i' ,
cui RE irethod is c dhJ i r.4r 2'i i; '- 'r rTO hi"J 1 c'ri
i$OpL_ t

tiic ulers thou i hr1 -ei 'i' P'i;-Kftü inez , ,,


larl y , Ileun's method is a r.o,uI order Range Kutta method because it
employs slopes at two end points of the interval.
As it was demonstrated by the Enter and He.un methods, higher the
order, better would he the accuracy of estimates. Therefore, selection of
order fr using f(l( e'iods depends on the problem under consider-

Determination oi
For using a Runge-Kntta method, the first requirement is the determi-
nation of weights of slopes at various points. The number of points is
equal ni the order of the mediod chosen. For the purpose of demonstra-
tion, we consider here the second-order Runge- Kutta method and show
how to evaluate varieos constants and weights.
The second-order Rh method has the form
= - (o' 1 nt 1u:

rn- i = 1'(x, y1)

= 1 '(x - a 1 h, y + b 11 m 1 h) (13.32)
The weights w 1 and 02 and the constants a 1 and h 11 are to be deter-
mined. The centre principle of the Runge-Kutta approach is that these
parameters are chosen such that a power series expansion of the right
side of Eq. (13.31) agrees with the Taylor series of expansion of y 1 in
terms of y j and f(x,, y,).
The iecoad mdr: T:",' ' ur :Cri(H aneiofl of v 1 about v is

y 1 = + 'Ji h2 (13.33)
2! ^
Given
Y1' = f(x 1 , y) = /
df
V
dX

Therefore, Eq. (13.33) becomes

(13.34)
4M Numerical Methods

Now, consider the right side of Eq. .13.31). Since m 1 is already a func-
tion of; and y 1 , we need to expand only m as a power series in terms of
f(x1 , y4 ). From Eq. (13.32)
= f(x1 + a1/z, y + b11111,11)
Expanding the function on the right-hand side using the Taylor series
expansion, we get
in 2 = f(x,, y1 ) + u 1 h f + b 1 ,n 1h f, + 0(h2)
Substituting this in Eq. (13.31) and replacing rn 1 = f(x, y) by f, we get
YI+I =y + w 1 f+ w 2 1+ wa i hfr + w 2b 11 h ff3,lh +
( 1 + w2)hf + (wa 1 f,
+- w - w 2 b 11 1 f) h 2 + 0(h3 ) (13.35)
If Eqs (13.34) and (13.35) are to be equivalent, then they should agree
term by term. This is possible only if
( V 1 •+ =1
= 112
10 9 b, I = 1/2
Note that we have four unknowns and only three equations. Therefore,
there is no unique solution. However, we can assume a value for one of
the constants and determine the others. This implies that there is an
infinite family of second-order RK methods. For example, if we choose
1/2, then we get
1/2, w9 = 1/2: U1 = 1, b 11 = 1

With these values, Eq. 13.31) becomes

where,
FY,-,
1
+ if1 '
2 ( 13.36)

tii I = f(x,., y)
1113 = f(x, + h. y, + tn,h)
Note that this equation is the Heun's formula.
Similarly, if we choose w 1 = 0, then we get
W1 = 0, 1v2 a1 = 1/2, b 11 1/2
and Eq. (13.31) becomes

(1337)
where
1111 = f(x,, y)
Numerical Solution of Ordinary Differential E quations 4

I in 1h
M 22 f(x
+ft,

This results in the midpoint or polygon method.


Another strategy is to choose the parameters such that the bound on
the truncation error is minimum. It has been shown by Ralston that
1/3 and u 2 = 2/3 produces minimum truncation error. With these
weights,

m1+2r
-+------------h (13.38)
1
F-1
where,
in1 = f(x, y)

m2 = f( x +hLy L + - rnjh)

Fourth-Order Runge-Kutfa Methods


It is clear from Eq. (13.29) and the discussions above that it is possible to
construct RK methods of different orders. However, the commonly used
ones are the fourth-order methods. Although there are different versions
of fourth-order RK methods, the most popular method is the classical
fourth-order Runge-Kutt-a method given below:

m1 =f(x,y)

m2 f(x± -2 , YL m1h
2)

I m2h
f ; +A, y 1 + ---- (13.39)

Ffl4 = f(x + h, y + rn3h)


1m 1 +2m 9 +2m 3 +Pfl4
Jh
::i=Yt

4IL
Use the classical ilK method to estimate y(0.4) when
y"(x) = x 2 +y2 with y(0) = 0
Assume h = 0.2

- f(,y)—x2+y2

in=f(x0,y)=0 C
44Q Numerical Methods

M2 =f X 0 ra1h'
'Yo f(0.1, 0) 0.01

2 0.01x0.2)_001
3 =f(xo i • Yo
fl1
iJf( 2 2
in4 = f(x 0 + h, y(, + ,n 3 h) = f(0.2, 0.01 x 0.2) = 0.04
0+2x0.01+2x0,01 - 0,04
y(O.2) = 0 + 0.2 = 0.002667
6
Iteration 2
= 0.2
Yi = 0.002667
in I = /'( 0. 2, 0.002667) = 0.04

rn 2 =f .3,0.002667+ 0.04x0.2) = 0.090044

M 3 f(0.3. 0.002667 + 0.090044 x_0.2 = 0.090136


in4 = [ ( 0.4, 0,002667 + (0.090136)(.0.2)) = 0.160428

y(0.4) 0.002667 + 29060428 0.2


6
0.021360 (correct to six decimals)
The exact answer is 0.021359. If we use h = 0.1, then y(O.4) will be
0.021359. Try and check.
Program RUNGE4
RUNGE4 is a program designed to compute the solution of a first order
differential equation of type y' = f(x, y) using the fourth-order Runge
Kutta method.
* ------------------------------------------------------A
PROGRAM RLTNGE4
* ----------------------- ---------------------------------
* Main program
This pro g ram computes the solution of first order *
* differential equation of type y' f(x,y) using *
* the 4th order Runge-icutta method *

Functions invoked *
F,INT *
*
Numerical Solution of Ordinary Differential Equations 441

* Subroutines used *
* NIL *
*-----------------------------------------------------------
Variables used *
X Initial value of independent variable *
* Y - Initial value of dependent variable *
XP - Point of solution *
H - Step-size *
N - Number of steps *
* --. ---------------------------------------------
* Constants used *
* NIL *
* —------------*

REAL X,Y,XP,H,Ml,M2,M3,I'14,F
INTEGER N,INT
1NTRINSIC INT
EXTERNAL F

WRTTE(, *)
WRITE (* * SOLUTION BY 4TH ORDER R-K METHOD
WRITE(*, *)

Input Values

WRT.TE(*,*) 'Input initial values of x and y'


READ(* , *) X,Y
WRITE(*,*) 'Input x at which y is required'
READ(,*) XP
WRITE(*,*) 'Input step-size h'
REA.n(*, ) H

* Compute number of steps required

N = INT((XP-X)/H+0.5)

* Compute V at each step


WRITE(* *)
WRITE(* *)s STEP X Y
WRITE(*,*)'

DO 40 1 = l,N
Ml = F(X,Y)
M2 = FlX+0.5*H,Y+0.5*M1*H)
M3 = F(X+0.5*H,Y+0,5*M2*H)
M4 = F(X+H,Y*M3*H)
= X+H
V = Yi(Ml+2.0*M2f2.0943+M4)*H/6.0
WRITE(,*) I,X,Y
442 Numerical Methods

40 CONTINUE
WRITE(*,*)'-----------------------------------------,

Vrit-.e the final value of Y

WRITE(*,*)
WRITE(**) 'Value ot Y at X X, is', Y
WRITE(*,*)

STOP
END

* --------------End of main RUNGE4 -•-*


* ---------------------------------------------------------*
Function subprogram *
*- --------------------- ----------

REAL FUNCTION F (X, Y)


REAL X,Y

F = 2.0 *

RETURN
END
*
-- End of tuction R(X,Y) -------------*
Test Run Results
SOLUTION BY 4_ 7 d ORDER P -KNETHOD
Input initial values of and y
1.0 2.0
Inputx at dinh i.n::T--o
2-C
Iflpu step-size h
0.25

STEP X Y
1 1.2500000 3.1246910
2 1.5000000 4.4993830
3 1.7500000 6.1240550
4 2.0000000 7.9986960
Value of Y at X 2.000000 is 7.9986960
Stop - Program terminated.

_ ACCURACY OF ONE-STEP METHODS


How do we achieve the desired level of accuracy in one-step methods?
One approach is to repeat the computations at decreasing values of h
until the required accuracy is obtained. Tb - 'ir involve a large
Numerica' Solution of Ordinary Differential Equations 44
number of repetitions if the initial value of h is far away from the
optimal value. Another approach is to estimate the value of h that is
likely to give the desired level of accuracy.
It is very difficult to have a formula in terms h for the global error.
However, we know that the order of global truncation error is hT if the
order of local truncation error is /x1 + 1 We can use this information to
study the sensitivity of the solution to the value of Ii and thereby esti-
mate the size of h. Obtain estimates of(h) at two different values of h,
say h 1 and h 2 . Then

Y,xact y(l), h 1 ) = ehç

y(b, h = ch
where c is the constant of proportionality. The above equations can be
solved for c as
y(h, h 2 ) - y(h, h1)
_ht(13.40)
/f .
If we need the answer to an accuracy of d decimal places, then the error
must not be greater than 0.5 x 10 and, therefore,
c/tv :5 0.5 x
Thus

(h_h)1od
h = ------ (13.41)

where Ay = y(h, h 2) - y(b, h 1 ). For example, for a second-order method,


the global error is proportional to h 2 and therefore ho is given by
pt

/(h?_hflio_dj
2A

If we choose h 1 = 2h 2, then

F8
Any value of h <h 0 will give the desired accuracy.

Two estimates of y(O8) of the equation


y'(x) = X2 + y 2 with y (0) 1
444 Numerical Methods

are obtained using fourth-order RK method at It = 0.05 and It = 0.025.


y(O.8, 0.05) = 5,8410870
y(O.8, 0.025) = 5 "47967
Estimate the value of It required to obtain the solution accurate to
(i) four decimal places and (ii) six decimal places
(i) d = 4

(0.05 -. 0.025)10
= 4.26 x 10
= 2(0.0068767)
h = 0.01437
(ii) d = G

(0.054 -0.025)10-
- 4.26 x 10-10
2(0.0068767) -
ii = 0.00454
We may Use It 0.01 to obtain a figure accurate to four decimal places
and It = 0.004 to obtain a figure accurate to six decimal places.

MULTISTEP METHODS
So far we have discussed man y methods for obtaining numerical solu-
tion of' first-order initial-value problems. All of them use information
only from the last, computed point (;,y,) to compute the next point (x *
y )• Therefore, all these methods are called single-step methods. They
do not make use of the information available at the earlier steps, y, -
Yi - 21 etc., even when they are available. It is possible to improve the
efficiency of estimation by using the information at several previous
points. Methods that use information from more than one previous points
to compute the next point are called multistep methods. Sometimes, a
pair of multistep methods are used in conjunction with each other, one
for predicting the value of v and the other for correcting the predicted
value of y1 + . Such methods are termed predi.rtnr-007'rector methods.
One major problem with multistepmethods is that they are not self-
starting. They need more information than the initial value condition, If
a method uses four previous points, say y0 , y , Yzs and v, then all these
values must be obtained before the method is actually used. These val-
ues, known as starting values, can he obtained using any of the single-
step methods discussed earlier, it is important to note that the degree of
accuracy of the single-step method must match that 'f the inultisiep
method to be used. For instance, a fourth-order RK mc liod is normally
used to generate starting values for implementing a fourth-order multi-
Numerical Solution of (Drdinor Differential Equations
step method. In this section, we consider the following popular multistep
methods:
1. Mime-Simpson method
2. Adanis-Baslifhrth-Moulton method
Both of them are fourth-order methods and use a pair of multistep
methods in conjunction with each other.

Mime-Simpson Method
The Milne-Simpson method is a predictor-corrector method. It uses a Mime
formula as a predictor and the popular Simpson's formula as a corrector.
These formulae are based on the fundamental theorem of calculus.

y(x1 = y(x1 ) + Jf(x,y)dx (13.42)

When J = i 3, the Eq. becomes an open integration formula and produc-


es the Milne's formula

+
(2fy (13.43)

Similarly, when i - 1. Eq. (13.42) becomes a closed form integration


and produces the two-segment Simpson's forrriuia

y 1±1 =y 1+i + (f 1 + 4f ff1 (13.)

Mime's formula is used to 'predict' the Starting points


value of y. 1 which is then used to cal- Y,-2Y)1 Y,
culate f + ( in Eq. (13.44)) from the dif-
ferential equation.
fi + = f ( X 1 YI * Prediction of y,,
Then, Eq. (13.44) is used to correct the
predicted value of y . The process is
then repeated for the next value of i.
Each stage involves four basic calcula- Evaluation of fi +
tions, namely,
1. prediction of y + 1
2. evaluation of IL*1
3. correction of y1 + Correction of y, , i
4. improved value off1 (fur use in
next stage)
It is also possible to use the corrector Next stage
formula repeatedly to refine the esti- (if necessary)
mate of y, before moving on to the Fig.13.4 Implementation of pre-
next stage (see Fig. 13.4). dictor-corrector meth-
ods
J4 Numerical Methods

Given the equation

y'(x)=i with y(1)=2


x
estimate y(2) using the Milne-Simpson predictor-corrector method,
Assume h 0.25.
Milne's formula at i = 3 is

: =y0+(2f1—f2+2f3)
Simpson's formula at i = 3 is

Y4 =2+(f2f3+f:)
where!; = f(x,, y)
To use these formulae, we require the estimates of Yi ' Y2 and y 3 i
addition to the initial condition yo. These can be obtained using any of
the single-step fourth-order methods,
Let us assume that they have been estimated using the fourth-order
RK method as follows:
Y 3 =y(1.25)= 3.13
y 2 = y(1.5 ) 4.50

Y3 = y(1.75) = 6.13
Then
2x 3.13
11= 125 =5.01

2x4.5
6.00

2x6.13
=7.01

Substituting these in Milzie's formula we predict the value of y(2) as

2.00 + (2 x 5.01 - 6.00 + 2 x 7.01) = 8.01


3
f4p 2x8.018

Now we obtain the corrected value of y(2) using Simpson formula as


y4r
= 4.50 + or (6.00 'F 4)': 7.01 + 8.01)
3
8.00
NumercCI So!utiofl of Ordinary Differential Equations 44.7-

We can again use the corrector formula to refine the estimate

t. 2

4.50 + (6.00 - 4 70! + 8.01 )


3
= 8.00
Note that the exact solution is Y( 2) =8.

Program MILSIM
An algorithm for evaluating the equation y' f(x, y) using Mime-Simpson
method is illustrated in Fig. 13.4. Progmm MILSIM shows the imple-
mentation of the algorithm in details. The program does the following:
1. Computes the starting points using fourth-order RK method
2 Predicts the function value by Mime's formula
3. (orrects the value obtained using Simpson's method
4. Writes the results

PnO(I, aAM NJ. LS TN


*
*tijjr,program
* PJ'° solves 5G L rt ardOr di fej:itil *
method
* or caLler, y ' = tx,y) using MilflC-SiI5PS'
. -----*
*
* 'ifl'tiOro' :i'okeci *
* i--------*
INT
*
Subroutines used *
* NIL ---- *
*
variables used *
* x11) -- inicia] value of independent variable *
i) initial value of dependent va:.LdlIie *
* Xp - Pairir. oL olutiOt1 *
N Nunber of steps
* H S:ep-s.e *
* X - Array ot ndepoint varioh.0
* Y Array of dependent variable - *
*
* Cocatants used *
* ft!L.
* - ------
44 Numerical Methods

REAL X, Y, H, XP, Ml, M2 M3 ,M4, SU1 . 1, SUN2, F


INTEGER N,INT
INTRINSIC 1NT
EXTERNAL F
DIMENSION X(10), Y(10)
* Read values

WRITE(,*) 'Input initial values of x and y'


READ(*,*) X(1) ,Y(1)
WRITE(,*) 'Input x at which y is required'
R/J.1(*,*) XP
WRITE(*) 'Input step-size h'
READ(*,*) H

* Compute number of computations involved


N INTNXP_x(l))/H + 0.5)
* We need four starting points for Mime-Simpson method.

** Initial values farm the first point. Remaining three


points are obtained using 4th order RE method
WRITE(*, (
WRITE(*,*) 'INlTIj, VALUES', X(i), Y(1)
WRITE(*,*)
* Computing three points by ER method
WRTTE(*, *) 'THREE VALUES BY ER METHOD'
DO 10 I 1,3
Ml =
M2 = F(X(I)0.5*H, Y(I)+0.5 * Ml *H)
M3 = F(X(I)+0.5*H, Y(I)+0.5*M2*H)
M4 - F(X)I)+I-(, Y(I)+M3*p
XI+1) = X(T)+H
Y(I+1) =
WRITE,*) I, X(I1), Y(I+j)
10 CONTINUE
WRITE(*, k)
WRITE(-,-) 'VALUES OBTAINED BY
MILNE-SINPSON METHOD'
DO 20 I = 4, N
F2 = F (X(I-2), Y(I-2))
F3 = F (X(1-1(, Y(I-l))
F4 = F(X(.L), Y(T))
* P
redicted value of y (by Mime's Eonnula)
Y(I+1) =
Numerical Solution at Ordinary Differential Equations 44
X(I+1) = X(1) + H
ES = F(X(I+1), Y(I41))

* Corxoct3d value of Y (by Sirir 30n,s formula)

= Y(T-1) + H/3.0 *(F3440*F4F5)


JhTTE(*,*) 1, X(I+1), Y(I1)
20 CONTINU.

WH[TE( *)
WRITE(*,*(Va3ue of Y at- X
X
? (N ±])
WR1TE(, *)

STOP
END

* ------- End of main MILS[M -------------.-- - *


* --- --------------------------- -------.-
-----------*
* Furactiort subprogram *
* --
------------------------*

REAL FUNCTION F(X,y)


REAL X,Y

F 2.0 Y/X

RETURI']
END
* ------------ -- End of function F(x, y ) ----------------*
Test Run Results

.Er!uuL .!}itidj vaJus of x and y


]..0 2.0
Input x ot which y is required
2.0
Input step-size b
0.125

INITIAL VALUES 1.0000000 2.000000C


THREE ', "ALUES BY RE METHOD
1 1.1250000 2.5312380
2 1.2500000 3.1249770
3 .375000Q 3.7912150
VALUES OBTAINED HY MLLNE-SIMHSUN METHOD
4 1.5300000 4.4999660
5 1.6250000 5.2812040
6 1.7500000 6.1249520
450 Numerical Methods

7 l..O77oCO
0 2..000000LJ 7.
'.o
j nt I . - 2.0000er: i
- Pro raid te n:0J.

Adams-Bashforth-Moulton Method
Another popular fourth-order predictor-corrector method is the Adams-
Bashforth-Moulton multistep method. '['lie predictor tdrm ula is known
as AdarnsBashfrth predictor and is given by

t55 - +37 - 9f (13.45

The corrector formula is known as Ada ms-Moulton corrector and is giv-


en by _ -
1. 0.46)
J
This pair of equations can b, implemented using the procedure described
for Milne-Simpson method.

Repeat Example 13.10 using Adams-Bashforth-Moulton method.


By Adams predictor formula

3 t2 + :37f1 - 9f)
= + 24 (55[ -

6.13 + p5 (5 . 7.01 - 59 x 6.00 + 37 x 5.01 - 9 x 4)

8.0146
2x 8.0146
= ..----.--- 8.0146

By Adams corrector formula

Y = +(f - 5f2 + 1 9f,+ 9 t 41')

= 113 24 (5.01-5 x 6.00 + 19 x 7.01 + 9 . 8.0146)


+
= 8.0086
yirefined) = 8.0079
Numerical Solution of Ordinary Differential Equations 4j
H, ACCURAèY OF MULTISTEP METHODS
We know that for each differential equation, there is an optimum step
size h. If h is too large, accuracy dimi.ishes and if it is too small, round-
off errors would dominate and reduce the accuracy.
By computing the predicted and corrected values of y • , we can
estimate the sLo and sign of the error. Let us denote the predicted value
by y" 1 . Similarly, denote the truncation error in predicted value by E1
and corrected value by Etc. Then, we have,

Es,, =y-yf

E. yy1
where y denotes the exact value of y(x The difference between the
error is
- yt I - y f 1 i ( 13.47)
A large difference indicates that the step size is too large. In such cases,
we must reduce the size of h.

Mime-Simpson Method
Both the Milne and Simpson formulae are of order h 4 and their error
terms are of order h5.
The truncation error in Mime's formula is

E, =
28
(5) (01) h°
90 -Y
The truncation error in Simpson's formula is

Etc --- - 1 Y (5gj 2"

If we assume that y 5 01 ) = y'5 ( 02 ) then

E IL- - 28
Etc
or,
EfP
= - 28FIr
Substituting this in Eq. (13.47) we obtain,

y1-yf+1
Etc -
29
452 Numerical Methods
If the answer is required to a precision of d decimal digits then

Lj = <0..ixlO

or
',, (13.48)
IY L

Adams Method
The truncation error in Adams-BasFifhrth predictor is
2a1 5i
E'.0 - -( y (01)h
and the truncation error in Adams-Moulton corrector is

Er r y (2)h3
720
Then, assuming y 5 9) = y( 9), we get

1;'
or
19 tc -

Substituting in Eq. (13.47) results In

E, yI)

For achieving an accuracy of'd decimal digits,

-Y j <270/19 x 0.5 x 10 7 x 10d (13.49)


According to Eqs (13.48) and (13.49, h should be reduced until the
difference between the corrected and predicted values is within the speci-
fied limit. It should be noted, however, that if the step length is changed
during the calculation, it will be necessary to recalculate the starting
points at the new step value.

Modifiers
Using the error estimates, we can modify the estimates of y ; + before
1
proceeding to the next stage. That is
Y 1 =Y'
For Mime's method

.v #1 =y 1 --( y : 1 -
Numerical Solution of Ordinary Differential Equations 4

For Adams meth J

Y1+i
-Q
270

Solve the differential equation


Y, (x) = —y2

for y(2.0) using the Milne-Simpson method with the application of modi-
fier to the corrector. The first four points are given under
y =y(x4)

0 1.0 1.0000000
1 1.2 33333
2 1.4 0.7142857
3 1.6 0.6250000

To estimate y(2 . 0) with h = 0.2, we need two iterations.

fL=-Y
f1 = - 0.6944444
12 — 0102040
f = -- 0.390f3250
Iteration I

y(1.S)y' =y0+4(2f1—f2+2f3)

= 1.0 (-1.13888889 + 0.5102040 — 0.7812500)

= 0.5571506

1P
() =-0.3106396

Y Y2+(2+4f3+14)

= 0.7142857 + 0 . (— 0.5102040 - 1.56250 - 0.3106396)

= 0.5553961

4
_____
Modifier = 0.0000674
F,11
29
44 Numerical Methods

Modified y = y4C + = 0.5554635


Iteration 2
(c)
f =-0.3085397

y(2.0) = y P = y 1 + ( 2f - + 2f)

= 0.5008366

I,' =-0.2508373
Y5 Y3+(f3+4f4+f)
= 0.4999585
Modifier E, = 0.0000303
Modified yC = 0.4999888
Exact answer = 0.5
Error = 0.0000112

SYSTEMS OF DIFFERENTIAL EQUATIONS


Mathematical models of many applications involve a system of several
first-order differential equations. They may be represented as follows:
dyj
=f1(x,y,y2,..., y,,,), y(x 0 ) =y10
dx
dy7
f2(x, Yi, Y21 •.., Yrn ), y2( x 0) = Y20

(13.50)

dym
dx fm(', Yi, Y2 .... . ym), y(x0) = Ymo

These equations should be solved for y 1 (x), y 2 (x), ..., y,(x) over interval
(a, b).
These equations can be solved by any of the methods discussed in this
chapter. At each stage, all the equations are solved before proceeding to
the next stage. For example, if h 0.5 and a = 0, then we must
evaluate y1(15), y2(0.5),..., y,(0.5) before preceding to the stage
h = 1.0.
Let us consider a system of two equations for the purpose of illustration.
Numerical Solution of Ordinary Differential Equations 455

y j( , = f1 (x,y 1 , y2 ), y1(x0)=y10

y (x) = f2 (x, Y I, y y2(x0) = Y20


Assume that we want to use the Heun's method. The first stage would
invo1v e following calculations.
M 1( l ) = f1( x0 , Yu), Y20)
in 1 (2) = f2 x$), Yi, )'2rj)
m 2 (1) = f1 (.r 0 + 1?, Yio + hm 1 (1), Y20 + hm1(2))
m 2 (2) f2( x ) + h, Yio + hrn 1 (l), Y20 + hm1(2))

mI()+ ni(l)
m(1) =
2

in1.(2)+m7(2)
m(2) =
2
y 1 ( x 1 ) = y(l) = y 1 (x) ± m(1)h = Yio + m(1)h
Y2(XI ) Y2(') y 2 ( x 0) + m(2)h = Yzo + m(2)h
The next stage use y 1 (1) and Y2(1) as initial values and, by following
similar procedure, yi(2) and y2 (2) are obtained.

Given the equations


dy1
v0-1
1 + y1 y2(0) =

estimate the values ofy(O.l) and y2(0•1) using Heun's method.


Given x 0 = 0. Yio = 1, Y20 —1
ni 1 (l) = f1 (x, Yin ' Y20) 0 + 1 1 = 0
n
r 1 (2) = f2(--CO, Yin ' Y20) 1 + 1 1 = 1
M 2( 1 ) = f1 ( x 0 + 1, Yo + hm 1 (1), Y20 + hm1(2))
= f1 (0.1, 1 + 0.1 x 0, —1 + 0.1 x 1)
=f1 (0,1, 1,-0.9)
= 0.1 + I - 0.9 = 0.2
/11 2( 2 ) = f2(x0 + h, Yio + h "1 1 ( l) , Y20 + hm1(2))
=12(0.1, 1,-0.9)
1 + 1 —0.9 = 1.1
4M NumercaI Methods

=m1h1m2(1)=01
,n(1)

1 (2)+rn 2 (2) 105


m2) m

y 1 (O.l) = y 1 (0) + hm(1) 1 + (0.1) (0.1) = 1.01


Y2 ( 1) = Y2(0) + Ii m(2) = —1 + (0.1) (1.05) = —0895

-- HIGHER-ORDER EQUATIONS
We have seen in the introductory section of this chapter that many
problems involve the solution of higher-order differential equations. A
higher-order differential equation is in the form
dmy / dy d 2 y d"'y
ã (13.51)

with in initial conditions given as


U I, . ' ( o ) = ij2
y(x1 ) V Pz- '(x0

We can replace Eq. (13.51) by a system of first-order equations as follows:


Let us denote
dy d2 d"1y
Y -Yi, jTYn
Then.
dy1
y1(Xn) Yo

dy2
dx Y2(10 ) Y20 =

(13.52)

dyj
dx =1 ym_i(xo)ymjoam.. 1

dv
- =ftx,y1,y2, Ym) y(x) = ynzcJ

This system is similar to the system of first-order Eq. (13.50) with the
conditions
t =y.+1, i=1,2,...,m-1
fm f(x, Yi Y2, "' Ym)
Numerical Solution of Ordinury Differential Equations 47

and, therefore, can be solved using the procedure discussed in the previ-
ous section.

Soh- following equation for y(O.2)


d d
2y
2— -3y=6x
dx dx 2

given y(0) = 0, y'(0) = 1. Use Heun's method

d y 2 dy
6x +, - 2
dx2=

dy
Let .Y =Yj,
Then,
dv
dx Y2 Yiü°

d:
---6x+3 j -2y , 2 Y2u1
dx
Let It = 0.2
(1)
MI =1 y2

m,(2) 6x + 3y 0
- 2 Y2G = - 2

y., 0 -4' hrn 1 (2) = 1 ± (0.2) (- 2) = 0.6


77Z 2 (2) = 6(0.2) + 3(0 + 0.2(1)) - 2(0.6) 1.2 + 0.6 - 1.2 = 0.6

1-0.6
md)=

-2•i-0.6
1iL(2)--

= y 1 (0) + 0.2m(l) 0 + 0.2 x 0.8 = 0.16


y 2 (0.2) = Y20 + 0.2rn(2) = 1 (0.2)(0.7) = 0.86
y(x) at x = 0.2 = 0.16
V(x) at i = 0.2 = 0.86

1!12 1 SUMMARY
We encounter differential equations in many different forms while at-
tempting to solve real life problems in science and engineering. The most
-40 Numerical Methods

common form of differential equations is known as ordinary differential


equation. In this chapter, we considered various methods of numerical
solution of ordinary differential equations. They include
• Taylor series method
• Euler's method
• Heun's method
• Polygon method
• Runge-Kutta method
• Mime-Simpson method
• Adams -Bashforth-Moulton method
We also discussed the accuracy (and techniques of improving the ac-
curacy) of these methods. Finally, we discussed the solution of a system
of differential equations as well as higher-order equations.
We presented FORTRAN programs and their test results for the Thl-
lowing methods:
• Euler's method
• Heun's method
Polygon method
• Runge-Kutta method
• Milne-Simpson method

Key Terms
Adams -Bash forth predictor Mull/step methods
Ada ms-Moo/ton corrector One-step methods
Boundary-value problem Ordinaiy differential equations
Corrector Partial differential equation
Differential equations P/card's method
Euler's method Polygon method
Global truncation error Predictor
Heun's method Predictor-corrector method
Initial-value problem Radioactive decay
Kirchtiaffs law Runge-Kuti'a method
Law of cooling Semi-numeric method
Law of motion Simple harmonic motion
Local truncation error Simpson's formula
Midpoint method Starting values
Mi/ne's formula Taylor series method
Milne-Simpson method

1. What, is a differential equation? Give two real-life examples of ap-


plication of differential equations.
2. Distinguish between ordinary and partial differential equations.
Numerical Solution of Ordinary Difft'rentiol Equations 42

3. State the degree and order of the following differential equations:


(a) (v")2 + 'iy' = 0
(b) y" + 5(y')2 = 1
(c) y" - y = 0
1A) "+ay2=0

(e) +3y'-2y=x2
(f) y(y')2 - 2 y' + y 0
(g) xy'—(x+l)yO
2
(h) y 2 (y') 2 + xy y' =0
(j) (y)2jy2=
4. What is a nonlinear differential equation? State which of the equa-
tions given in Question 3 are nonlinear.
5. What is an initial-value problem? How is it different from a bound-
ary-value problem?
6. Why do we need to use numerical computing techniques to solve
differential equations?
7. State the basic two approaches used in estimating the solution of
differential equations. How are they different?
8. Describe how Taylor's theorem of expansion can he used to solve a
differential equ. ion.
9. What are the limitations of Taylor's series method?
10. State the formula of Picard's method to solve the differential equa-
tion of type
dv
ny

What are its limitations?


11. State the formula of Euler's method. Illustrate its concept graphi-
cally.
12. Comment on the accuracy of Euler's method.
13. Illustrate Heun's method of solution graphically.
14. How does the accuracy of Heun's method compare with that of
Euler's method?
15. Heuns method is an improved version of Euleis method. Com -
ment.
16. Why is ileun's method classified as one-step predictor-corrector
method?
17. Wh y is the polygon method called the midpoint method? Illustrate
graphically.
18. Describe the basic concept employed in Runge-Kutta methods.
19. What is meant by an r-order Runge-Kutta method? What is the
order of the following methods?
(a) Euler's method
(h) Heun's method
(c' Polygon method
Ni imrcnI Mthd

Writ and dnerit s uf inuli iotup mLh


22. State brmuiae used in Mime-Simpson method. 1)eciflje tn.
ipro tio r scheme of these fo-mu]ae.
or and corrector b . u.od in Ada

step i.. ...........


25. A high-cider differential equation can be solved by replacing ic by a
system of first-order equations. Discuss.
----..
E:.-.....-.
.. VIEW EXER(E$:
.- .-. -J
T5
Taylor's expansion (with S1]. to :) t.' ole . lowing
differential ations

(a) x + xy, y(0) = 1

for x7AY25 and 0.5.

v(x 2 - P. . fl•J 1
for = 1.0. 1.5 and 2.0

c) x+ y , y(ffl = 1
or 0.1 and 0.5

y(0)=1

for x 0.25 and 0.5

(e. - = y( 1) = 0
dx
for = 2.0 and 3.0

(t) = .v. y(0) = 1y• (0) = I

Y (dx 2
dt 2 ++ x = 0,
(g
dt ) r(0) I and 40)0

fort = 2 and 5.
Numerical Solution of Ordinary Differential Equations 41
2. Solve the following equations by Picards method and estimate y at
x = 0,25 and 0.5:
dy
(a) r + (x + l )y, y(0) =
dx
dy
(b) = x2y - y, y(0) = 1

dy
=x+y, y(0)=l

dy
(d) =x2y2, y(l)=0

(e)
dx y
3. Use the simple Euler's method to solve the following equations for
Y(I) using JL= 0.5, 0.25 and 0.1
_a)- y2xy, y(0) = I
y(0) 2

y(0)=1

Y(0) 1
(e) y' -x+y +xy, y(0) = 1
-4She differential equation
dy
y(0)=l
dx
by the simple Euler's method to estimate y(l) using h = 0.5 and
h = 0.25. Compute errors in both the cases. How do they compare?
Also, compare your results with the exact answer given the analyti-
cal solution as
Y(x) 2e - x -
5. Use Heuji's method with h 0.5 and h = 0.25 to solve the equations
in Exercise 3 for y(l). How do the results compare with these ob-
tained using simple Euler's method.
6. Repeat Exercise 4 using the Polygon method instead of simple
Euler's method. Analyse the results critically.
7. Use the polygon method to solve some of the equation in Exercise 3.
8. Use the classical RK method to estimate y(O.5) of the following
equations with h = 0.25.
dy
(a) =x +y, y (0)= 1
dx
462 NumerIca Methods

(b) dy y(0)=l

(e) a—=y COS x , y(0)=l

dy =
(d) y + sin x, y(0) = 2

(e) =y + , y(0) = 1
9. Solve the following initial value problems for x 1 using the fourth-
order Mime's method.
dy
(a) =v_x2, y(0)=1

Use a step size of 0.25 and lburth-order Runge-Kutta method to


predict the starting values.
10. Repeat Exercise 9 using Adam's method instead of Mime's method.
Compare the results.
11. Repeat Exercise 10 and ii with the application of modifier to the
corrector. Compare the results.
12. Solve the pair of simultaneous equations
dy1
= y1(0) 0

dy9
Y1 y9+x 2 +1 Y2(0)0
to estimate y(0.2) and y 2 (0.2) using any method of your choice.
13. Solve the following equation for y(0.2)

d 2 fdy 2
+6x 0, y(0) 1, y'(0)=O
Use Heun's method.
14. The general equation relating to current i, voltage
V resistance R,
and inductance L of a serial electric circuit is given by

L + i.R = V

Find the value of current after 2 seconds, if resistance R = 20 ohms,


inductance L 50 H and voltage V = 240 volts. Current
I = 0 when
t = 0.
Numerical Soution of Ordinary Differential Equations 4

16. A tank contains a solution which is made dissolving 50 kg of salt in


1.00 gallons of w.ter. A more concentrated solution of 3 kg of salt
per gallon of water is pumped into the tank at a rate of 4 gallons
per minute. The solution (which is stirred continuously to keep it
uniform) is pumped out at a rate of 3 gallons per minute.
Find the amount of salt in the tank at t = 15 minutes. Note that
initially at t = 0, the amount of salt. x = 50 kg.
dx
Hint: If x represents the amount of salt in the tank at time t, dt
will represent change in the amount of salt.
Lb. An object with a ma.. of 10 kg is falling under the influence of
earth gravity. Find its velocity after 5 seconds if it starts from the
rest. The object experiences a retarding force equal to 0.25 of its
velocity.
Hint: The relationship between the various forces is given by
du
mass x Tt = mass x gravity - retarding force
where v is velocity at time t.
17. A body of mass 2 kg is attached to a spring with a spring constant
of 10. The differential equation governing the displacement of the
body y and time t is given by
d 2 vdv
dt 2dt
Find the displacement y at time t = 1.5 given that y(0) = 2 and
y'(0) —4

1. Rewrite the prorom R1JNGE4 such that a subprogram implements


the fourth order Runge-Kutta method and a main program receives
input information, drives the subprogram to compute the solution,
and prints the required output information.
2. Modify the program MILSIM to incorporate the following changes:
(a) Computing the starting points by Runge-Kutta method using a
subprogram
(h) Implementing Mime-Simpson algorithm by a subprogram
(c) Applying the modifier to the corrector with the help of a sub-
program.
3. Develop a user-friendly modular program as suggested in Project 2
for the fourth-order Adams method with modifiers.
4. Develop a user-friendly program for solving systems of differential
equations using Euler's method or Heun's method.
5. Repeat Project 4. but use the fourth-order Rnnge-Kut.ta method,
Boundary Value and
Eigenvalue Problems

NEED AND SCOPE


We have seen that we require in conditions to be specified in order to
solve an in-order differential equation. In the previous chapter, all the in
conditions were specified at one point, x = x 0 , and, therefore, we call this
problem as an nrtwi-va1ur. problem. It is not always necessary to specify
the conditions at one point of the independent variable. They can be
specified at different points in the interval (a, b) and, therefore, such
problems are called the hoendary u(1he problems. A large number of
problems fall this category.
In solving initial value problems, we move in steps from the given
initial value of x to the point where the solution is required. In case of
boundary value problems, we seek solutions at specified points within
the domain of given boundaries, for instance, given

-Ax, y,y') y(a)=y, y ( b)=y b (14.1)


dx
we are interested in finding the values of y in the range a <x s b.
There are two popular methods available for solving the boundary
value problems. The first one is known as the shooting method. This
method makes use of the techniques of solving initial value problems.
The second one is called the fi nit e difference method which makes use of
the finite difference equivalents of derivatives.
Some boundary value problems, such as study of vibrating systems,
structure analysis, and electric circuit system analysis, reduce to a system
of equations of the form
Ax )lx (14.2)
Boundary Vaue and [Igonvalue Problems
Such problems are called the eigen value problems. We need to determine
the values of ) and vector x which satisfy the Eq. (14.2). We have two
simple methods available to solve this t y pe of problems.
1. Polynomial method
2. Power method
In this chapter, we consider these two special categories of problems and
discuss the following methods to solve them:
1. Shooting method
2. Finite difference method
3. Pol ynomial method
4. Power method

SHOOTING METHOD
This method is called the shooting method because it resembles an
artillery problem. In this method, the given boundary value problem is
first converted into an equivalent initial value problem and then solved
using an y of the methods discussed in the previous chapter. The approach
is simple. Consider the equation
y"=f(x,y.v y(a)=A, v(b)B
By letting y' = a, we obtain the following set of two equations:
Y' = z
= [(a, y, z)
In order to solve this set as an initial value problem, we need two
conditions at a = a. We have one condition y(a) = A and, therefore,
require another condition for a at a a. Let us assume that z(a) =
where M 1 is a "guess". Note that M1 represents the slope y'(x) at a = a.
Thus, the problem is reduced to a system two first-order equations with
the initial conditions
y(a) =A
2 ' = /( x, Y . a) z(a) M 1 (= y' (a)) (14.3)
Equation (14.3) can be solved for y and a using any one-step method
using steps of h, until the solution at x = b is reached. Let the estimated
value of y(x) at a = b be fl. T1 B 1 = B, then we have obtained the required
solution. In practice, it is very unlikely that our initial guess z(a) M 1 is
Correct.
If B 1 t- B, then we obtain the solution with another guess, say z(a) =
M. Let the new estimate of y(x) at x b be B2 (see Fig. 14.1). If B 2 is
not equal to B, then the process may be continued until we obtain the
Correct estimate of y(b). However, the procedure can be accelerated by
using an improved guess for z(a) after the estimates Of B 1 and are
obtained.
466 Numecoi Methods

Y(X)

Direction of
shooting (y'(a) = M2)

A_
- x1 - X3 -
(x4)

Fig. 14.1 Illustration of shooting method


Let us assume that z(a) 43 leads to the value y(b) = B. If we assume
that the values of M and 23 are linearly related, then
M9 - M2 M2-M1
B-B 2 139-B1

Then
R- B2
i%'M 2 + --------- x(M2-M)
2 1
B 9 --
B x (M2 - M 1 ) 14.4)
12B1
Now with z(a) - we can again obtain the solution ofy(x).

Using shooting method, solve the equation

= 6x, y(l) = 2, y(2) = 9


dx2
in the interval (1,2)
By transformation we obtain the following:
dy
y(l)=2
dx

= 6x

Let us assume that z(i) = y '(l) 2(M 1 ). Applying H& a's method, we
obtain the solution as follows:
Boundary Vthue and E)genva)ue Problems 467

Iteration 1
h = 0.5
x0 = 1, y(l) (j = 2, z(1)=z 0 = 2
ni(1) = zo = 2
rn(2) - 6x 0 = 6
rn2(1) = + hm 1 (2) = 2 + 0.5(6) = 5
m 2(2) = 6(x0 + Ii) = 6(1.5) = 9
rn 1 (1)+m 2 (1) 2 5
2 2
m 1 (2)+m(2) 6+9
m(2)
2
y (x 1 )= y(l.5) (1) + m(1)h 2 + 3.5 x 0.5 = 3.75
z(x 1 ) = 2(1.5) = z(1) 4- 7?i(2)h = 2 + 7.5 x 0.5 = 5.75
Iteration 2
h = 0.5
1.5,y 1 = 3.75, z j5.75
m 1 (1) z i = 5.75
m 1 (2) = 6x 1 = 9
m 2 (1) =z, + hrn 1 (2) 5.75 + 0.5 x 9 10.25
rn 2(2) 6(x 1 + Ii) = 12
5.75+10.25
rn(1)- =8
2
9+12 -
rn(2) = = lOu

Y (X 2 ) ( 2) =y(l) + m(1)h = 3.75 + 8 x 0.5 - 7.75


This gives B 2 = 7.75 which is less than B = 9
Now, let us assume z(1) = y (l) = 4(M 2 ) and again estimate y(2).
Iteration I
h = 0.5
x0 =1, y0 =2, z0=4
m 1 (1) =zo= 4
m 1 (2) = 6x 0 = 6
rn2(1)=z0+hrn1(2)=4+0.5x6=7
,n2(2) = 6(x0 + h) = 6(1.5) 9
4+7
m(1)=--- =5.5
468 Numericcit Methods

6+9
7.5

Y(x i ) =y(].5) = 2 + 5.5 x 0.5 = 4.75


z(x1 )= z(1.5) = 4 + 7.5 x 0.5 = 7
Iteration, 2
h = 0.5
= 1.5, y 1 = 4.75, zj = 7.75
n 1 (l)
r 7:75
m 1 (2) = 6x 1 = 9
= z + hni(2) = 7.75 + 0.5 x 9 = 12.25
11 12(2) 6(x 1 + h) 12
7.75+12.25
rn(1) =---------- = 10

9 12
rn(2)=- 10.5
This gives B 2 9.75 which is greater than 13 = 9.
Now, let us have the third estimate of z(1) M3
(14,4) using the relationship

2 —B
M3 - A'!2 x
- B (M M1)

-.(9.75 - (1 2i
(9.75-7.75)
- 4 - 0.75 = 3.25
The new estimate for z(1) y'(l) = 3.25
Iteration I
It = 0,5
1,
Yci = 2, z0 3.25
= zo = 3.25
in(2) 6Xç 6
rn 2 (l) = Z 0 + It in i t2) = 3.25 + 0.5 x 6 = 6.25
= 6(x0 + Ii) = 9
3.25 6. 25
mu) =-------= 1.75

6+9
10)2) .•
Boundary Value and Eigerivalue Problems 49
Y0.5) = 2 + 4.75 x 0.5 = 4.375
a(1.5) = 3.25 + 7.5 x 0.5 = 7
Iteration. 2
h = 0.5
x1 -1.5, v-3."t z1=7
in 1 (1) = 7
nr ( 2) = 6x 1 = 6>< 1,5 = 9
rn2(1) =2 1 + hflir(2) = 7 + 0.5 x 9 = 11.5
m 7(2) = 6(z + hi = 12
7±11.25
rn(1)= =9.25

m(2) = 9+12-10.5

Y(2) 4.375 + 9.25 Y 0.5 = 9


The solution is y(lt 2, y(l.5) 4.375, y(2) = 9 the exact solution is
y(x) r x 3 ± 1 and therefore y(1.5) 4.375.

The sequence of pnxedurt's Sir implementiT the shooting method is


given in Algorithm 14.1.

Shooting Method
1. Convert the problem into an initial-value problem,
2. Inllralise the variables irrutuding two guesses at the initial slope.
3. Solve the equations with these guesses using either a one-step or a
multistep method.
4. Interpolate from these results to find an improved value of the slopes
obtained.
5. Repeat the process until a specified accuracy in the final function
value is obtained (or until a limit to the number of iterations is reached).

Algorithm 14.1

FINITE DIFFERENCE METHOD


In this method, Lhe derivatives are replaced by their finite difference
equivalents, thus converting the differential equation into a system of
algebraic equations. For example, we can use the following 'central
difference" approximations:
47Q Numerical Methods

- Y[+1- Y - (14.5)
2h

Yi+12YiYL-1
YL
11 (14.6)

These are second-order equations and the accuracy of estimates can be


improved by using higher-order equations.
The given interval (a, b) is divided into a subintervals, each of width
A. Then
= X 0 + ih = a +

y, y(x 1 ) y(a + h)
Y1) = y(a)
y,, = y(a + nh) = y(h)
This is illustrated in Fig. 14.2. The difference equation is written for
each of the internal points i 1, 2, ..,, n - 1. If the DE is linear, this will
result with (n - 1) unkiowns Yt Y2 ' •-. We can solve for these
unknowns using any of the elimination methods.

AX)

Y4

YO

Fig. 14.2 Solution of DE by finite difference method


Note that smaller the size of /i, more the subintervals and, therefore,
more are the equations to be solved. However, a smaller Jr yields better
estimates.

Given the equation

=e with y(0) = 0, y(l) = 0

estimate the values of y(x) at x = 0.25, 0.5 and 0.75.


Boundorv Value and Elgenvalue Problems 471

We know that
YO =y(0) -0
y(O.25)
Y2 =
y y(O.75)
Y4 =y(l) = ()
It 0.25
y12y+y1
yj' =-.---- .
/12
= 1, x = 0.25
Y22Y1 Yo _e025)2
Yi' = 1.0645
= 0,0625
2y y=ft066 (1)
2.x = 0.50

Y' .00__..ew5 = 1.2840

2.Y2 + Yi = 0.0803 (2)


= 3, x 0.75

Y' Y42Y 3 +Y2


(75)2
=L7551

Yd - 25'3Y2 0.109J (3)


Letting 0 and Y4 = 0, we have the following system of three equations.
2Yi fY20.0665
Yi - 2Y2 =0.0803
Y2 - 2y3 = 0.1097
Solution of these equations results in
Yi = y(O.25) - 0.1175
Y2 =y(O.SO) =-0.1684
Y3 = y(O.75) =-0.1391

The major steps of finite difference method are given in Algorithm 14.2.
472 Numerlrnt MeThods

Finite Difference Method


1. Divide the given interval into n subinterval-
2. At each point of x, obtain difference equation using a suitable
difference formula. This will result in (n - 1) equations with ( n - 1)
unknowns, y1 , y2 .... . y,, - 1.
3. Solve for y,, 1 1, 2..... n - I using any of the standard elimination
methods.

Algorithm 14.2

_SOLVING EIGEN VALUE PROBLEMS

As mentioned earlier, some bounffary value problems, when simplified,


may result in a set of homogeneous equation of the type

+ (a9 - A)x2... + ax = 0 14.7)

a, 1 x 1 + O 9 X 2 + ... + (a,,,, - 2L)x,, = 0


where A is a scalar constant. Equation (147) ma y be expressed as
[A — AU I [XJ = 0 (14.8)
where I is the ir1e.etuv matrix and [A - All is called the
characteristic
matrix of the coefficient matrix A.
The homogeneous Eq. (14.8) will have a non-trivial solution if, and
only if, the characteristic matrix is singular. That is, the matrix JA - All
is not invertible. Then, we have
IA — lJ (14.9)
Expansion, of the determinant will result in a polynomial of degree a in
A.
A' —A ip2AP 2 —p,, - 3 A —p,, = 0 (14.10,1
Equation (I'llO) will haven roots A 1 , A2, The equation is known
as the characteristic polynomial (or characteristic equation)
and the roots
are known as the eigenua/ues or characteristic Lalues
of the matrix A.
The solution vectors X1 , X. ....., K, corresponding to the eigenvalues
A1,
A,, are called the etgeriuectnrs.
The roots representing the cigenvalues ma y be real distinct, real re-
peated, or complex, depending oil nature of the coefficient matrix A.
The coefficients p of the characteristic polynomial are functions of the
matrix elements a, and must be deter-mined before the polynomial can
he used.
Example 14.3 illustrates the pruceduLC valuat.inir uf eigenvaluez
and eigejlvectors of a simple SyStem.
Bcundrlry Viu nod EenvaIue Problems 473

Th•Ji__
Find the eigcnvcctors of the tbliowing System:
8x1 - =
2x 12x2 = ?cx2
The characteristic equation of the given system is -
8 --i
2 2--). =0
That is
(8— 22- ,J±8=0
or
?*- l0X+S=0
The roots are
2=6
2 4
For 2. = 2. = 6, WO get
- 0
2x 1 - 4x2 r 0
Therefore .t1 2x2 and the con'espoinling
_2 eigenvector is

Li
Similarly, for X = 4 we get x 1 = x and the eigenvector is

X2 []

The process of finding the eigenvalues and eigenvectors of large matri-


ces is complex and involves a multistep procedure. There are several
methods available and a discussion on all these methods will be beyond
the scope of this book. We consider, in the next two sections, the follow-
ing two methods:
1. Polynomial method
2. Power method

45 POLYNOMIAL METHOD
The polynomial method consists of the following three steps:
1. Determine the coefficients p i of the characteristic polynomial using
the Fadeev-Levei-rjer method
2. Evaluate the roots (eigenvalues) of the characteristic polynomial
using any of the root-finding techniques
424 Numerical Methods

3. Calculate the elgenvectors using any of the reduction techniques


such as Gauss elimination

The Fadeev-Leverrier Method


The Fade' v-Leverrier method evaluate the coefficients p, i 1., 2.....
of the characteristic polynomial
2

The method consists of generating a sequence of matrices Aj that can be


employed to determine the p, values. The process is as follows:
A = A• (14.11)
Pi tA
Remaining values (t = 2,3,..., n) are evaluated from the recursive

equations:
A, = A(A L _ l -Pi - IF)
tr AL
(14.12)
where t,Ai is the trace of the matrix A. Remember, the trace is the sum
of the diagonal elements of the matrix.

Determine the coefficients of the characteristic pol ynomial of the system


(-1- ))x 1 = 0
+ (-2 - )- 4 3x ' 02 .
3 =

2x9 + (-3 - A)--C 3 0 =

using the Fadeev-Leverrier method.


The given system is a third-order one and, therefore, the characteristic
polynomial takes the form
AS
Pj 2 P 9) P:0
The matrix A is given by
-1 0 0
A- 1 -2 3
0 2
By using the Eq. (1411),
= A
t r A j -6
By using the Eq. (14,12k,
A2 = A(A1 -
Boundary 'Value and Eigenvulue Problenis 47

1
[- 1 0 0 1—i 0 0 [--6 0 0
= 1 -2 3 1 -2 3 Ho - a
o 2 -3 [o 2 - Lo 0 -6
[-1 0 r5
= 1 -2 3 1 4 3
o 2 3L° 23]
-5 0 0
= -3 -2 3
2 2

tr
P2=
2
Similarly,
A = A(42 -P2T)

--1 a
a rr--5 0 0 -5 0
= 1 -2 3H-3 -2 3 - 0 -5
O 2 _3ft2 2 -3 0 0

i o o o o o
= 1 -2 3 -3 3 3
La 2 -3 2 2 2

F0 0 01
=16 0 0
[a o
ptrA3
=

Therefore, the characteristic polynomial is


2L + 6.t 2 + s = a

or
+ 6 + 5) = 0

Evaluating the Eigenvalues


Let us consider the characteristic polynomial obtained in Example 14.4.
+ 6) + 5) = 0
One of the roots is , = 0, The other two roots can be obtained using the
familiar quadratic formula as
4M NumercoI MtII uds

A 2 —1
A 5 = —5
Since it is a quadratic equation, we can salve it using the quadratic
formula. However, if the polynomial is of hc. order, the roots may be
evaluated using the techniques dismissed in Chapter 6. We may use
either the Newton-Raphson method with synthetic division or the
Bairstow method.
Remember that the sum of the eigenvalues of a matrix is equal to the
tram of that matrix. In the problem discussed above,
trace ofAz —1 --2-3 =-6
Sum of eigenvalues = 0 1 5 = 6
Determining the Elgenvectors
Once eigenvalues are evaluated, eigenvectors corresponding to these
eigenvalues may be obtained by applying Gauss elimination method to
the homogeneous equations. Example 14.5 illustrates this.

Determine the cigenvectors for the system discussed in Example 14.4.


The eigenvalues are:
A] = 0, A2 l, Az3

Eigenvector 1 (A = 0)
The system of equations for A 1 0 is
—x i = 0
- 2x 2 + 3x 0
2x2 - 3x 3 0
This is equivalent to the s ystem of two equations
=0
2x 2 - 3 0
Choosing X,= 1,
-t:, 2/3 = 0.6667
Eigenvector 2 (A2 —1)
- + 3x 0
2x 9 -- 2x 3 = 0
Choosing x 2 1, we get x 3 = .1 and x 1 = - 2
Eigenvector 3 (A. - 5)
4x 1 = 0
x 1 -4- 3x 2 + 3x 3 = 0

2x2 + 2x3 0
Boundary Value and Eigenvalue Problems 477
X1= 0 and choosing x2 1, we get x3 = - 1
The three eigenvec€ors are:

1 1
[ 0.66671

X2= 1
Li
0
X3 = 1
_-1]

Computing Algorithm
The computing algorithm for polynomial method combines three differ-
ent algorithms discussed so far. Algorithm 14.3 lists the major steps
involved in implementing the polynomial method of finding eigenvalues
and associated eigenveetnrs.

Polynomial Method
1 Input order of the matrix and the elements of the matrix.
2. Determine the coefficients of the characteristic polynomial by using
the Fadoev-Leverrier method.
3. Evaluate the roots of the polynomial USilig the Bairstow method (use
Algorithm 6.10).
4. For each eigenvalue, construct the system of equations and then
solve tor the eiganvector using the Gauss elimination method (use
Algorithm 7.2).
5. Print eigenvalues and the associated eigenvoctors.

Algorithm 14.3

1i44 POWER METHOD


Power method is a 4single value' method used for determining the 'domi-
nant' eigenvalue of a matrix. It is an iterative method implemented
using an initial starting vector X. The starting vector can be arbitrary if
no suitable approximation is available. Power method is implemented as
follows:
-Y_-AX (14.13)

X= l y) (14.14)
k
478 Numescal Methods

The new value of X obtained from Eq. (14.14) is used in Eq. (14.13) to
compute a new value of Y and the process is repeated until the desired
level of accuracy is obtained, The parameter k, known as the scaling
factor, is the element, of V with the largest -nagrude.
Let us assume that the eigenvalues are j A l I > I21 fA,j and
the corresponding eigenvectors are X1 , X2,.., X. After repeated applica-
tions of Eqs (14.13) and (14.14), the vector X converges to X and k
converges to

Find the largest cigenvalue ) j and the corresponding cigenvector V of


the matrix
12O
21O
0 0 - 1]
using the power method.
Let us assume the starting vector as
0
X= 1
0
Equations (14.13) and 14.14) are repeatedl y used as follows
Iteration .1
1 2 00 21
YH2 1 0 1 =
0 0 -1 _ 0

r2 1
1 = 0.5
2o
o
Iterat ion 2
ri
2 0 11
Y=2 1 0
Lu 0 -iJ[oj Lu

2 0. 1 8-^

X =. 2.5_
2.5
Boundary Value and Eigenvolue Problems 479

The process is continued and the results are tabulated below:


3 4 5 6 7
2.0 2.0 2.8 2.86 2.98 2.98 3.0
Y 1.0 2.5 2.6 2.93 2.96 2.99 3.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0 1.0 0.8 1.0 0.98 1.0 1.0 1.0
X 1 0.5 1.0 0.93 1.0 0.99 1.0 1.0
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
The final entry in the table shows that A, = 3.0 (element of Y with
largest magnitude) and the corresponding eigenvcctor is the last X. That
Is,

1
I
0

Algorithm 14.4 gives an implementation of the power method. Note that


the stopping criterion is based on the successive values of the vector X.
There might be circumstances where the process will not converge at all
(or where it will converge very slowly). Therefore, it is necessary to put a
limitation on the number of iterations.

Power Method
1. Input matrix A initial vector X, error tolerance (EPS) and maximum
iterations permitted (MAX1T).
2. Compute Y= AX
3. Find the element kof Ythat is largest in magnitude.
4. Compute X = Y/k
5. If JX- XdJ < EPS or Iterations> MAXIT
write k and X
else
go to step 2

Algorithm 14.4
Engineers often come across cases where they are interested in the
smallest eigenvalue of the s ystem. The smallest eigenvalue can be deter-
mined by applying the power method to the matrix inverse of EAI.

SUMMARY
We considered two classes of problems in this chapter;
4N Numerical Methods

boundary value problems


• eigenvalue problems
We presented two methods for solving boundary-value problems:
• shooting method
• finite difference method
We also discussed in detail the nature and solution of eigcnvalrie
problems and presented two methods for evaluating eigenvalue.s and
eigenvectors:
• power method
• polynomial method

Key Terms

Boundary a/ue problem Finite difference method


Characteristic equation Identity matrix
Characteristic matrix Initial-value problem
Characteristic polynomial Polynomial method
Characteristic values Power method
Eigen value problem Scaling factor
Eicenvalues Shooting method
Eigenvecror Trace of the matrix
Fadeev-Le verrier method

1. What is a luundarv-vatue problem.? I-Tow is it different from an


initial-value probleni?
2. State the two popular methods used lhr solving boundary-value
problems.
3. What are eigenvalue problems? how are they different from bound-
ary-value problems?
4. State at least two methods used for solving cigenvalue problems.
5. Describe the shooting method with graphical illustration.
. Explain the concept employed in the firdie diffbrence method,
7. Define the fhllowiiig:
(a) Identit y matrix
(b) Characteristic matrix
(C) Characteristic polynomial or equation
(d) Eigenvalues
(e) Eigenvectors
(fi Trace of a matrix
8. What. is Fadeev-Levej-ner method used for? Explain.
9. Describe the algorithm of' polynonual method used for solving cigen-
value problems.
10. Describe the implementation id power method with the help of a
flow chart..
Boundary Value and Eigenvalue Problems 41

1. Solve the following equations using the shooting method.


d2y
(a) - = 6x + 4. y(0) 2 and y(l) =5
L

(b)
- =
12x2 , v(l) = 2 and y(2) = 17
2. Use the finite difference approach to solve the equations in Exer-
cise 1 with Ax = 0.2.
3. Use the shouting method to solve the following differential equa-
tion:

_ + 2— - 25 = 0
dx 2
given the boundary conditionsy(0) 10 and y (lO) 6.
4. Solve Exercise 3 uizig the finite difference method with Ax = 2.
5. Given the boundary-value problem

= 3x + 4y , y (0) = 1 and y(1) 1


2

obtain its solution in th range 0 x :^ 1 with Ax = 0.25 using


(a) shooting method
(b) finite ditThrence method
6. Given the equation
d 2d
x 2_2x i _2yx2 siax=0
&c 2 dx
and boundary conditions y(l) = 1 and y(2) = 2, estimate y(1.25,
y(1.5) and y(1.75) using the shooting method.
7. Solve the following boundar y-value problems using a suitable meth-
od.

(a') --6y2 = 0, y(l) = I and y(2) 0.25

(b) ±_ + -2y =0, O


y(l)= and y(2)= 1

(c) -.3-1-2y=2, y O)=l and y(1)=4

d2y dy
(d) -----x--y=-x2, y(0)=-2 and y(l)=l
S. Find the characteristic polynomials of the following systems using
Fadeev-Leverrier method.
(i) 2. 3..., - iC. =
412 Numerical Methods

8x 1 f3x+4x3 Xx2
lOx 1 + 4x2 +7x3=Xx,
(h) 16x 1 - 24x 2 + 18x 1 =
3x 1 - 2x9
-9x 1 +18x9 -. 17x.3 r2.x
(C) 2x 1 -i- 2x + 2x =

2x 1 + 5x, + 5x3=
2x 1 + 5X2+ 1x3 = Ix3
9. Evaluate the eigenvectors of the systems given in Exercise 8.
10. Find the largest eigenvalue and the corresponding eigenvector of
the following matrices using the power method.
2 -1 01
(a) A- -1 2 -1
O -1 2

-1 0 0
(b)R= 1 -2 3
[0 2 -3

-13 3
(c) C () -4 0
15 --9 7

RWOqR-A PR

1. Develop a program to implement the shouting method algorithm


for a linear, second-order ordinary differential equation.
2. Develop a program to implement the finite difference method of
solving a linear, second-order ordinary differential equation.
3. Develop a rriodu]ar program which uses the following subprograms
to implement the polynomial method.
(a) Suhprogam to obtain the coefficients of the characteristic
polynomial using Fadeev-Leverrier method.
(h) Subprogram to evaluate the roots of the characteristic poly-
nomial (use Bairstow method).
(c) Subprogram to determine the cigenvectors (use Gauss elimi-
nation method).
You may also use subprograms to receive input information and
print output information.
4. Develop a user-friendly program to evaluate the largest eigenvalue
and the corresponding eigenvector using the power method.
5. Develop a program to compute the smallest eigenvalue using the
power method.
_JJ
CHAPTER

Solution of Partial
Differential Equations

NEED AND SCOPE


Many physical phenomei.a in applied science and engineering when
formulated into mathematical models fall into a category of systems
known as partial difli?rvntlol equations. A partial differential equation is
a differential equation involving more than one independent variable.
These variables determine the behaviour of the dependent variable as
described by their partial derivatives contained in the equation. Some of
the problems which lend themselves to partial differential equations
include:
1. Study of displacement of a vibrating string,
2. Heat flow problems,
3. Fluid flow analysis,
4. Flectrical potential distribution,
5. Analysis of torsion in a bar subject to twisting,
6. Stud y of diffusion of matter, and so on.
Most of these problems can be formulated as second-order partial
differential equations (with the highest order of derivative being the
second). If we represent the dependent variable as f and the two
independent variables as x and v, then we will have three possible second-
72f d 2f
order partial derivatives (2 ' __!_. andin a>2
addition to the two
a y
- a df
first-order Part i al derivatives
and -
ax a
we can write a second-order equation involving two mdependent vari-
ables in general form as
44 Numerical Methods

(9 2 fd 2 f (92f df, df
a — +b ------+e-------- F .L,y,f,---- I (15.1)
(9X c9y ,32 (7X dy)
where the coefficients a, h, and c may be constants or functions of x and
y. Depending on the values of these coefficients, Eq. (15.1) may be classi-
fied into one of the three types of equations, namely, elliptic, parabolic,
and hyperbolic.
Elliptic, if b 2 - 4ac .c 0
Parabolic, if b 2 - 4ac 0
Hyperbolic, if b 2 - 4ac > 0
Uri, b, and c are functions of x and y , then depending on the values of
these coefficients at various points in the domain under consideration,
an equation may change from one classification to another.
Solution of partial differential equations is too important. to ignore
but too difficult to cover in depth iii an introductory book. Since the
application of analytical methods becomes more complex, we seek the
help of numerical techniques to solve partial differential equations.
There are basically two numerical techniques, namelvfinite-c/ifference
method and tinite-element method that can he used to solve partial
differential equations (PDEs). Although the finite-element method is
very important for solving equations where regions are irregular,
discussion on this technique is beyond the scope of this book, We will
discuss here the application of finite-difference methods only, which are
based on formulae for approximating the first and second derivatives of
a function. We will also consider problems, only those where the
coefficients a, b, and c are constants.

DERIVING DIFFERENCE EQUATIONS


In this section, we will discuss two-dimensional problems wily. Consider
a two-dimensional solution domain as shown in Fig. 15.1. The domain is
split into regular rectangular grids of width ii and height k. The pivotal
values at the points of intersection (known as grid points or nodes) are
denoted by f1 which is a function of the two space variables x and y.

YJ,2

= x. + h

y/_2

- ________,______,_____ I I
x_, x x11 x,2
FIg. 15.1 Two-dimensional finite difference grid
Solution of Partial Differential Equations 4

In the finite difference rnethod, we replace derivatives that occur in


the PDE by their finite difference equivalents. We then write the
difference equation corresponding each 'grid point" (where derivative
is required) using function values at the surrounding grid points. Solving
these equations simultaneously gives values for the function at each
grid point.
We have CL ssed in Chapter 11 that, if the function f(x) has a
continuous fouri derivative, then its first and second derivatives are
given by the following central difference approximations,
f (x i -i-h)-f (x i -h)
f C) =

or

1 (15.2)
21z

f(x h)-2f(x)+f (x i _-h)


"N- )

or
+fL-1
Ii" (15.3)

The subscript on f indicates the x-value at which the function is evaluat-


ed.
When [is a function of two variables x and y, the partial derivatives of
f with respect x (or y) are the ordinary derivatives of I with respect to
x (or y) when y (or x) does not change. We can use Eqs (15.2) and (15.3)
in the x-direction to determine derivatives with respect to x and in the
y-direction to determine derivatives with respect toy. Thus, we have
af(x,y) .
=/(x,v) =- -
f(x1 - 1 ,y) [(Xg1,yj)

9f(x,y) f(x,y11Y-f(x,y1_1)
=f(x.y)
2k

f(x1,1,y1)-2f(x1,y1)+[(x1,y1)
dX
=f(x,y)
2 = h2

d2f(x1,y1) - f(x1,y ) - 2f(x,y) + f(x, y1 )


y2 k2

dx)y - 4hk
Aft Nurnrlca! Mehods

It is convenient to use double subscripts i, j on f to indicate x and y


values. Then, the above equations become
fi+Lj1i-Lj
I
2h

I' ' IL,J+1Ii,j-i


(15.5)
= 2k

2f +ft1j
_LL (15.6)

I (15.7)

I = (15.8)
- 4hk
We will use these finite difference equivalents of the partial derivatives
to construct various types of differential equations.

ELLIPTIC EQUATIONS

Elliptic equations are governed by conditions on the boundary of closed


domain. WP consider here the two most commonly encountered elliptic
equations, namely,
Laplace's equation, and Poisson's equation.
Laplace's Equation
Equation (15.1), when a = 1, b = 0, c = 1, and F(x,y,f,f,f) 0, becomes
2 f af
(15.9)
The operator

V2 =^
(9x2 gy 2

is called the Laplacian operator and Eq. (15.9) is called Lap1aces equa-
tion. (Many authors use u in place of f.)
To solve the Laplace equation on a region in the xy-plane, we subdi-
vide the region as shown in Fig. 15.1. Consider the portion of the region
near (x i , y,). We have to approximate
2f ,92f
v2 f =-_±^ L =0
dx2 dyz
Solution of Partial Differential Equations 47

Replacing the second-order derivatives by their finite difference equiva-


lents (from Eqs (15.6) and (15.7)) at the point (xi , ),,), we obtain,

-L fJE12f +fJ1
V2f = +
k2
If we assume, implicity, h = k, then we get
V2f.. = 0 (15.10)
(f + - , +[. ) =

Note that Eq. (15.10) contains four neighbouring points around the central
point (xi, y) (on all the four sides) as shown in Fig. 15.2. Equation (15.10)
is known as the flue-point difference formula for Laplace's equation
(J + I

1,) 1+ 1,1

Fig. 15.2 Grid for Laplace's equation


We can also represent the relationship of pivotal values pictorially as
in Eq. (15.11).

\T2f =i{1 - i}f =0 (15.11)

From Eq. (15.10) we can show that the function value at the grid point
(x,, ,v,) is the average of the values at the four adjoining points. That is,

f(f + fi - +f +f) ] 15.12)

To evaluate numericall y the solution of Lap)ace's equation at the grid


points, we can apply Eq. 15.12> at the grid points where f is required
(or unknown), thus obtaining a system of linear equations in the pivotal
values f,. The system of linear equations may be solved using either
direct methods or iterative methods.
488 Numercaj Methods

Consider a steel plate of size 15 cm x 15 cm. If two of the sides are held
at 100°C and the other two sides are held at 0°C, what are the steady-
state temperature at interior points assuming a grid size of 5 cm x 5cm.
A problem with the values known on each boundar y is said to have
Drichit houndary conditions. The problem is illustrated below.

100 100
100

-10 0

14
100 ---e- 0

-
0 0 0
The s ystem of equations is as follows:
At point l: 14--f---'if1 +10O+iQ0 =0
At point 2: f1--f4- 4 f2 + 100 + 0 =0
At point 3: f1 + f4- 4 14 f 100+ 0 =0
At point 4: f2f3f4 0+ 0 =0
That is,
-414 -s-f+O=-2OO
fL 1 f2 0+f4=100
fi- 0-414--f4=-rnO
0+ f2 + 14- 4 14 = 0
Solution of this system are
14=75 f2=50
14=50 f=25
Note that there is a smimetry in the temperature distribution, Le it can
be stated that
T2f
and therefore the number of equations in Example 15.1 may be reduced
to three with three unknowns as shown below.
-4ff + 2f2=-200
11 -4f, -f4 = -100 (15.13)
12 2 14 =0
Soiutton of Partial Differential Equations 42

Uebmann's Iterative Method


We know that a diagonally domina-t system of linear equations can be
solved by iteration methods such a. Gauss-Seidel method. When such an
iteration is applied to Laplace's equation, the iterative method is called
Liehmann's iterative method.
To obtain ivotal values of f by Liebrnann's iterative method, we
solve for f, the ..uatioiis obtained from Eq. (15.10). That is,

= + 1 + f, + f, -) ] ( 15.14)
The value at the point ij is the average of the values of f at the four
adjoining points. If we know the "initial values" of the functions at the
right-hand side ofEq. (15.13), we can estimate the value fat the point if
We can substitute the values thus obtained into the right-hand side to
achieve improved approximations. This process may continue till the
values f, converge to constant values.
Initial values may be obtained b y either taking diagonal average or
cross average of the adjoining four points.

Solve the problem in Exannle 15.1 using Liehmann's iterative method


correct to one decimal place.
By applying Eq. (15.14) to every gvid point, we obtain

-. + 200

Ii ± f., + 100
A

f+f. +100
1 (15.15)

- 12 + 13
14—
4 -
Appropriate initial values fbr the iterative solution are obtained by tak-
ing diagonal average at 1 and cross average at other points, assuming
first f 0.

1 = ( 100 100 + 100 + 0) = 75.00 (average)

[2 = } ( 75 + 100 + 0 + 0) = 43.75
M Numericel Methods
f3=(100+75+0+0)=43.75

= (43.75 + 43.75 + 0 + 0) = 21.88


Note that / '2, f8, and f4 are computed using the latest values on the right-
hand side.
Using these initial values in Eq. (15.15) and performing iterations
gives the values as shown in Table 151.
Table 15.1
Initial Iteration.
Values 2 3
/1 75M0 71.88 74.22 74.81 74.95
f2 43.75 48.44 49.61 40.90 49.98
13 43.75 48.44 49.61 49.90 49.98
[4 21.88 24.22 24.81 21.95 24.99

The process may be continued till we get identical values in the last two
columns. Note that the values are approaching to correct answers ob-
tained in Example 15.1.

Poisson's Equation
Equation (15.1), when a = 1, b = 0, c 1 and F(x, y, f, f, f) = g(x, y),
becomes
<92f d2f
=g(x,y) (15.16)
or
2
V f = g(x, y)
Equation (15.16) is called Poisson's equation. Using the notation g, =
g(x, y ) Eq. 15.10 used for Laplace's equation may be modified to solve
Eq. 15.16. The finite difference formula for solving Poisson's equation
then takes the form
-4 =hgJ (15.17)
By applying the replacement formula to each grid point in the domain of
consideration, we will get a system of linear equations in terms of
These equations may be solved either by any of the elimination methods
or by any iteration techniques as done in solving Laplace's equation.

Solve the Poisson eLludtion


v2f= 2 X2Y2
over the square domain 0 s x 3 and 0 <-y!5 3 with f= 0 on the boundary
and h = 1.
Solution of Partial Differential Egucrions 49].

The comain is divided into squares of one unit size as illustrathd below:

0 x=1 x-.2 0
By applying Eq. (15.17) at each grid point, we get the following set of
equations:
Point 1: 0 + 0 + 12 + 13- 4f1 2(1)2(2)2
i.e. f2 + - 4f1 8 (a)
Point 2: 0 + 0 + f, + f4 - 4f = 2(2)2(2)2
i.e. t- 4 f2f =32 (b)
Point 3: 0 + 0 + f1 -- f4 413 = 2(1)2(1)2
i.e. / - 4f3 + f4 2 (c)
Point 4: 0 + 0 + f2 + f3 -- 414 = 2(2)2(1)2
(d)
i.e. 12 -13 - 4f = 8
Rearranging the equations (a) to (d), we get
-4f1f2f =8
f1 -4f -14 32
11 -4f+f4 = 2
f2f =8
Solving these equations by elimination method, we get the answers.
- 22 43
f2=

13
f3 = -;4 14- 4

Salve thi: priiin Hi Example 15.3 by Gauss-Seidel iteration method.


By rearranging the equations used in Example 15.3, we have

Il = (f3+f3-8)
492 Numerical Methods

12 = - ( f + f J2)

fa(f+f--2)

f4=
Note that f =
Therefore,

11 =

f2=(2f132)

2)
Assume starting values as f, 0
Iteration 1
f, = — 2. f2=-9, f., = — 1
Iteration 2

18 ii
Il --j-- , f2= 41, 13=
Iteration 3

43 13
/1- 4, f2 f3=_-_
Iteration 4

43 13
t1
4' f2, f3=___

PARABOLIC EQUATIONS
Elliptic equations studied previously describe problems that are time-
independent. Such problems are known as steady-state problems. But
we come across problems that are not steady-state. This means that the
Function is dependent on both space and time. Parabolic equations, for
which
V - 4czc = 0
describe the problems that depend on space and time variables.
A popular case for parabolic type of equation is the study of heat flow
in one-dimensional direction in an insulated rod. Such problems are
governed by both boundary and initial conditions,
Solution of Parlial Differential Equations 43
Insulation
f(x,i)
Roo

f(O,

x=O x
Fig. 15.3 Hual flow in a rod

Let / represent the temperature at any point in rod (Fig. 15.3) whose
distance from the left end is x. Heat is flowing from left to right under
the influence of temperature gradient. The temperature f(x, t) in the rod
at the position . and time 1, is governed by the heat equation

dl
k 1 —.---k2k - (15.18)
dx2 dt
where k 1Coefficient of thermal conductivity; k2 = Specific heat; and
= Density of the material.
Equation (15.18) may be simplified as
kf1 (x, t) = (15.19)
where

k2k:
The initial condition wilt be the initial temperatures at all points along
the rod.
Ax, 0)=f(x), 0:5x:^L
The boundary conditions f(0, t) and f(L, t) describe the tempeitr& at
each end of the rod as functions of time. If they are held constant, then
f(0,t)=c 1 , 0 t<
f(L,t)rc..,

Solution of Heat Equation


We can solve the heat equation given by Eq. (15.19) using the finite
difference formulae given below:
f(x,t+r)—f(x,t)
t.

=(fl, i (15.20)
2f (x, f) + f(x + h, t)
f(x. t) = / t,
/i 2
494 NumeicaI Methods

= - 2f + f (15.21)
Substituting (15.20) and (15.21) in (15.19), we obtain

3 (f -f) = (f1 1 - 2, + 2+)

Solving for f.
2rk) T
(1
[
=(l_2r)f1+rf.1+/,) (15.23)

where r
Tk
h2

Bender-Schmidt Method
The recurrence Eq. (15.23) allow; us to evaluate [at each point, x. and at
any time 1. If we choose step sizes At and Ax such that
2Tk
(]5.24)
h2
Equation 15.23 simplifies to

= (f (1525)
J
Equation 15.25 is known as the Bender-Schmidt recurrence equation.
This equation determines the value off at x = x,, at time t = t, + r, as the
average of the values right and left of x 1 at time t
Note that the step size in time At obtained from Eq. (15.24)
h2

gives the Eq. (15.25). Equation (15.23) is stable, if and only if the step
size r satisfies the condition r
2k

Solve the equation


2f(x,t)=/(x,0, 0<tz1.5 and 0<x<4
given the initial condition
f(x,O)=5U(4—x), 0!^x:54
Solution of Partial Differential Equations 4

and the boundary conditiois


f(0,t)=0, 0:5t1.5
f(4,t)=0, 0 5 tS1.5
If we assume Ax = 1, At rmust

2><2
Taking r = 0.25, have

1 = Fft,i + fz + )
Using this formula, we can generate successfully f(x, t). The estimates
are recorded in Table 15.2. At each interior point, the temperature at
any single point is just average of the values at the adjacent points of
the previous time value.
Table 15.2
0.0 1.0 2.0 3.0 4.0
f(,0)
0.0 150.0 100.0 50.0 0.0 50(4 - x)
0.00
0.0 50.0 100.0 50.0 0.0
0.25 0.0
0.50 0.0 50.0 50.0 50.0
0.0 25.0 25.0 25.0 0.0
0.75 0.0
1.00 0.0 12.5 25.0 12.5
0.0 12.5 12.5 12.5 0.0
1.25 0.0
1.50 0,0 6.25 12.5 13.25

The Crank-Nicholson Method


Solution of the parabolic equation given in Eq. (15.19) was solved using
a forward difference formula in Eq. (15.20) for the time derivative and a
central difference formula in Eq. (15.21) for the space derivative. This is
called explicit method because all starting values are directly available
from initial and boundary conditions and each new value is obtained
from the values that are already known.
Accuracy of the explicit method may be improved if we use central
difference formulae for both time and space derivatives. The forward
difference quotient used for the time derivative (Eq. (15.20))
1, i f.

may be treated as central difference if we consider it to represent the


midpoint of the time interval (j, f + 1). We can also use the central
difference quotient for the second derivative with distance, correspond-
ing to the midpoint in time. Then.
426 Numerical Methods

1' ( I +)-(f 1-
X, f1) (15.26)
The central difference quotient for the second-order space derivative is
obtained by taking the average of difference
quotients at the beginning
and cad of the time step, i.e.
Central difference at t1 = - ( Central difrence at t1 + Central
difference at t
Then,

k f( x,t + r/2)
k(fz_i,+f. 2f, j 11-1,1
--------.---. - .... —2f,,1

(15.27)
Then equating Eqs (15.26) and (15,27) and substituting
rh
r-
We get

(15.28)
Equation (15.28) is called the Crank-Nicholson formula. If
then Eq (15.28) simplifies to we let r =1,

(15.29)
The terms on the right-hand side are all known. Hence Eq. (15.29) forms
a system of linear equations. The points used in the Crank-Nicholson
formula are shown in Fig. 15.4. The boundar y conditions are used in the
first and last equations, i.e.
11, f ,J + 1 =
= = c2
The Crank-Nicholson formula is called an implicit method because the
values to be computed are not just a function of values at the previous
time step, but also involve the values at the same time step which are
not readily available. This requires us to solve a set of simultaneous
equations at each time step.
Referring to Fig. 15.4,
fA4fBfG=fD+fF
1j4 1 '.1+1 i-f 1.j-+- I
——c

0 (j+ 1/2

O E F

Fig. 15.4 The Crank-Nicholson grid


Solution of Partial Differential Equations 497

Solve the problem in Example 15.5 by the Crank-Nicholson implicit


method.
Let us use a table as shown in Table 15.3 for recording the function
values at various time steps. The values for the first time step (t - 0) are
obtained from the initial condition
f(x, 0) = 50(4—x)
and the values for f and f5 are obtained from the boundary conditions.
Table 15.3
1j x=O x=3 x=4
12 12 13 14 15
0.00 0.0 150.00 100.00 50.00 0.0
025 03) 56.25 75.00 43.75 0.0
1 3 = 0.51) 0.0 0.0
1 4 = 0.75 0.0 0.0
1 5 = 1.00 0,0 0.0

Now, for the second time step (1 0.25), we write equations at each point
using Eq. (15.29) and solve for unknowns. Thus, for the second row in
the table, we have
—0.0 + 4 12-13 = 0.0 + 150
—[2+413-14=150 +150
—13+414-0.0=101) +0.0
Solving these three equations for three unknowns, we obtain
12 = 56.25
13 = 75M0
[4 43.75
This process may be continued for each time step. Students may com-
plete the table.

HYPERBOLIC EQUATIONS

Hyperbolic equations model the vibration of structures such as build-


ings, beams and machines. We consider here the case of a vibrating
string that is fixed at both the ends as shown in Fig. 15.5.
The lateral displacement of string f varies with time t and distance x
along the string. The displacement f(x, t) is governed by the wave equation
T±t—.1
dx 23t2
where T is the tension in the string and p is the mass per unit length.
42L Numerical Methods

Fig. 15.5 Displacement of a vibrating string


Hyperbolic problems are also governed by both boundary and initial
conditions, if time is one of the independent variables. Two boundary
conditions for the vibrating string problem under consideration are
f(O,t)O O:!^t:^b
f(L,t)=O Ostih
Two initial conditions are
f(x,W = ftx ) Oxia
f1 (x,O)g(x) 0:5xa

Solution of Hyperbolic Equations


The domain of interest, 0 !^ x :!^ a and 0 ^ t 5 b, is partitioned as shown in
Fig. 156. The rectangles of size Ax = Ii and M

b HAXH

LI T
At

Fig. 15.6 Grid for solving hyperbolic equation


The difference equations for f(x, t) and f(x, t) are:
- f(x - h, ) - 2f(x, t) + f(x + h, t)
f(x, t)
h2
f(x,t-)-2f(x,t+f(x,t +)
frr(', I) -
r2
Solution at Partial Ditferentjcji Equations 4
This implies that,

T!I11±_2±,1 p±[±LlJ+1
Solving this for f; • j + , we obtain

Tr7'r2
fi +2(1_f, + ; 1 (L [Z J +f1)
If we can make

Tr
1- 0
p/i
then, we have
__ ___ = (1530)
_1
The value off at. x x, and t + t is equal to the sum of the values of
f at the point x = x Ii and x ' = .X,+ /i at the time t = t (previous time)
minus the value off at x = x at time t = t1 - r. From Fig, 15.6, we can say
that,
= 15 +,f,) - f

Starting Values
We need two rows of starting values, corresponding toj = 1 andj = 2 in
ordeT to compute the values at the third row. First row is obtained using
the condition
IC, 0) = f(x)
The second row can be obtained using the second initial condition as
follows;
(x, 0) =g(x)
We know that

f(x,0)= -
f,o+i fL,0-1

f 1 =f 1 -2g1for t=Oonly
Substituting this in Eq. (15.30), we get for t = t1

[.i=Ff+io+1o)+ T
In many eases, g(x) = 0. Then, we have
1 (15.31)

=
Numerical Methoas

Solve numerically the wave equation


f(x, e.) = 4f(x, t),
with the boundary conditions
f(0,t)=0 and f(5,t)=0
and initial values
f(x,O)=f(x)x(5-x)
f(x,O) =g(x) = 0
Let h = 1
Given,

P
and assuming
2
1--4— - 0
12
We get,

The values estimated using Eqs (1530) and (15.31) are tabulated in
Table 15.4.
Table 15.4

x 0 9 3 4 5
0.0 0.0 4 6 6 4 0.0 X(5 - x)
0.5 0.0 :3 ii 5 S 0.0 Equation (15.31)
1.0 0.0 1 2 2 0.0 Equation (15.30)
.5 0.0 -1 -2 --2 -1 0.0
2.0 0.0 .3 -5 —3 3 0.0
2.5 0.1) -4 -6 -4 0.0

SUMMARY
In this chapter, we discussed the solution of an important class of differ-
ential equations called partial differential equations. Due to complexity
and limited Scope of this book, we considered only the finite-difference
method of solving the PDE problems where the coefficients (I h, and c
are constants. We presented the following in this chapter:
• Definition and classification of partial differential equations.
• Derivation of difference equations for PDEs.
• Solution of Laplace's equation by ' t,h0l of elimination.

I
Solution of Partial Difterennoi Fquntions

Liehmann's iterative method for solving Laplace's equation.


Solution of Poisson's equation by hoththrcct and iterative methods.
Solution of parabolic type heat equation using the explicit Bender-
Sclunidt recurrence equation and the implicit Crank-Nicholson tor-
111111a.
Solution of hyperbolic t y pv Wave equation b y iterative procedure.

Key Terms

bender-Schrmdt cquatiun Hyperbolic equation


Crank-Nicholson formula Implicit method
Cross average Lap/aces equation
Diagonal average Lap/ac/an operator
Dir ichiet boundary condition Liebmann's method
Elliptic equation Parabolic equation
Explicit method Pa! tit derivatives
Finite-difference method Partial' differential equation
Finite-element method Poisson s equation
Gauss-Seidel if era ton Wave equation
Heat equation

[- - ----fl
QUESTIO N.

1. What is a partial differential equation? Give two examples.


2. State two real-life problems where partial differential equations
are required to construct mathematical models.
3. how are the partial differential equations classified? Give an ex-
ample from real-life situations for each type.
4. What are the various methods available to solve differential equa-
tions?
5. Explain how difference quotients are applied to solve partial differ-
ential equations.
5. What is Poisson's equation? 1-Low does it differ from Laplace's equa-
tion?
7. What is Liebmanri's iteration method? What are its advantages?
S. What is meant by IJirichiet boundary conditions?
9. What is diagonal-averaging? When do we use it?
10. Derive a difference equation to represent a Poisson's equation.
11. Derive the five-point formula for Laplace's equation.
12. What is Crank-Nicholson method? Why is it known as implicit
method?
13. What is Bender-Schmidt recurrence equation? Derive the formula.
14. Discuss the impact of size of the incremental width T for the time
variable t on the solution of a heat-flow equation.
15 Outline the argument that demonstrates the stability of the finite-
difference procedure for solving a hyperbolic equation.
2 Numerical Methods

L'
1. Determine which of the following equations are elliptic, parabolic,
and hyperbolic.
(a) 3f + 4f = 0
(b) f—f=0
(c) f,-2f+2/=2x+5y
(d) fyy
(e) f, - = 0
(0 f + 6f + 9f = 0
2. The steady-state two-dimensional heat-flow in a metal plate is by
' 2 T ?2T
dx 2 Jy2
Given the boundary conditions as shown in the figure below, find
the temperatures Ti , T9 , T3 , and 7'.

0 30

0 50 100 100
3. Solve for the steady-state temperatures in a rectangular plate 8 cm
X 10 cm, if one 10 cm side is held at 50°C, and Lite other 10 cm side

is held at 30°C and the other two sides are held at 10°C. Assume
square grids of size 2 cm x 2 cm.
4. Repeat Exercise 3 by Leibmann's method.
5. Evaluate f(x, y) at the internal grid points of the given domain
governed by Laplace's equation. Use Liebmann's iteration method.
0 0 0 100 20 50 20 0

0 0 0 0100 C
(a) (b)
Solution of Portia! Diffrential Equations

6. Torsion on a rectangular bar subject to twisting is governed by


V2T=4
Given the condition T 0 on boundary. find T over a cross section
of a bar of size 9 cm x 12 cm. Use a grid size of 3 cm x 3 cm.
7. Solve the equation
V 2 f F(x,y)
with F(x, y ) = xy and f = 0 on boundary. The domain is a square
with corners at (0, 0) and (4, 4). Use h = 1.
8. Estimate the values at grid points of the following equations using
Bender-Schmidt recurrence equation. Assume h = 1
(a) 0.15f, = 0
Given,
f(0, t) 0, f5, 0 = 0
Ax, 0) = x(5 - x)
(b) 9f, =
Given,
f(0, t) = -- 5, ff5, t) 5
j-5 for 0x2.5
f(x,0)= 5for2.5<!^5
9. Initial temperatures within an insulated cylindrical metal rod of 5
cm long are given by
T = 20x for 0 :^ x !^ 5
where x is the distance from one face. Both the ends are main-
tamed at 0°C. Find the temperatures as a function of x and t if the
heat flow is governed by
4T - T 0
10. Solve the following equation using Crank-Nicholson method.

-B
t9x2
Given,
f(0, t) 0, ff20, t 10
f(x, 0) = 2.0
Assume Ax = h z 5 and r 1
11. Solve Exercise 9 with the Crank-Nicholson method with r = 1.
12. Solve the following hyperbolic equations using finite difference meth-
od.
(a) f = 4 f,
Given,
f(0, t) = 0 and f5, t) = 0
04 Numerical Methods
f(x, 0) 100x 2 (5 - x)
t(x, 0) = 0
(b) / 4f,
Given,
[(0, t) = (I and [(1, t) = 0
f(x, 0) = f(x) .= sin (Irx) + sin (2rx)
f(x,0) = 0

1. Develop a program to solve Laplace's equation with Dirichiet condi-


tions.
2. Write a program to solve Poisson's equation.
3. Develop a program using forward-difference method to solve the
heat equation.
4. Write a program to solve the heat equation using Crank-Nicholson
method.
5. Write a program fbr finite-difference solution of the wave equation.

You might also like