Chapter 11-15
Chapter 11-15
Numerical
Differentiation
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)
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
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
Thus, we have
Li1ii
with the truncation error of
/2
f U)
h2
(11.9)
,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
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
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
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
E(hopj=2.feM2 (11.13)
Numerical Differentiation
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,
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
111 14)
If
(O ) + f 1 ' ( 82))
4!
=-
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
- 0.73Q00
Exact value off (0.75) = - cosi0.75)
=-0.73 16888
Error = 0.()016888
This error includes roundciff error as well.
We know that
= fIx 1 . x11
---
= - fx1) f))
--
On substituting
/1 x, -
x1 = x +
X0
we get i__ ...........
Iii.1F
Numerical Methods
= + 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
-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
(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.
= !!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
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
= 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
= 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
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.
Therefore.
25.5- 2U9.5+ 14.5
a(7) - 12
.2
= LOkmis
± 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
..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
_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
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
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
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
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.
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
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
(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
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.
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
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
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
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
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
I J (x 3 + 1)dx
374 Numeilcd Methods
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
IE Lt I .c 3 f"(l.S) = 0.09375
exact 1.515625
True error = 0.078125
f (x)
1f(x 1) + f(x1)1
= ft If (X,) ) + f(x)J +
ft ff(x 1 ) + f(x)1
+ ... +
ft If (x ]) + [(x,)]
h3
E1 = - --- f'() (12.9)
2•'1
F (12.10)
12 12n2
Case n=2
h
2 2
fl-i
= h2 [(a) + fb)l + /u f(a -4- ih
= 2.54308
Case n=4
h =.--- = 0,5
Nurllerlcai integration 3L7
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) -
* --------------------------------------------------------- *
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
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
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
b
1s12 r-_5Efosdx
a
,13 -
a 2
NumerccI Methods
2
18 12 = I Ao sh ds = 2hf0
I,]3= h
1)/ids=-2f0
2 ,;( s
+ f,
Therefore,
+ 2fo]
'si = It[sfo + (12.11)
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
-
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
Ca. (a)
i =1ex dx
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
= 0.2617993(0 + 3.3635857 + 1)
= 1.1423841
Numerical Methods
h= --
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).
dx
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 -
= 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
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
STOP
END
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 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)
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');
Case (a)
Basic Simpson's 3/8 rule is based on four sampling points arid, therefore,
IL = 3,
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=
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
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
= 1.18062
The table below shows the results Qf
,r/2
J/sin(x) dx
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
Trapezoidal 1
4 (f0 +
It
h5
f "(0)
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
= 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(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.
JlJxdx
+ 1/2) = 0.75
2
Now, we obtain 11(1, 0) and R(2, 0) using equation (12,27)
=x-=0.7083333
2 2 1.5
= 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)
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
*
40 STOP
END
* - End of main ROMBRG --- - *
* Jr
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
f (b)
-
•
f (x)
a b
(a) Trapezoidal rule
a x, x2 b
+ W2
= Idx = 2
w1x + = x dx I)
+ = Jr 2 IIX
x1 =- 0.5113302
=-
= = 0.5773502
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
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
A= - -- and
Therefore
b-a a+b
X =---2+
cit
This implies that
b-a
C = ---
Then the integral becomes
b-a1
where WL and ; are the weights and quadrature points for the integra-
tion domain (-1, 1)
b—a
'g lw1g(z1) + w2g(z2)]
b—u b-i-a
=2z
Therefore,
22 =
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
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
(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
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
EWE*EXERCJs$J
• /a1uate analytically th following iiitegra1
(a) J(3x22x_5)
(b) j(3x3+2x2_1)dx
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
6 7
[Peratlire_f(t) 81 75 1 0 83 78 70 60 ]
f(t)d/
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 _____
X(t) =Jv(t)dt
0
2j [(a+b)(ab)].2 9 d&
Circumference =4a
0
406 Numerical Methods
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,...
I
11 -- e
1 5 cos(x) d
Numerical Solution of
Ordinary Differential
Equations
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)
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
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
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.
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)
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
1 ± x + X2 8 X3
Yix) = + + ... (13.15)
= 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
+ - (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.
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
= 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
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)
I dy = 5 f(x, y)dx
or
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
(l) y0+J(x2+(y°)2)dx
=0+1 ,
Y 04- J (x 2 +(y')2)dx
Xu
4( 2 +Jdx=-+i
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
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
y(x)
(x1, yi)
Tangent line Error in yt
at (, y0)
XG xl x?
(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).
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
E"
= (,0.5') 2 -4
q (0.5) -3 = 0.875
Step 2
= 1.5. V = 4.0
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
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
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
DC 10 I = 1,N
D'r = HF(X,Yj
=
Y+nY
WRITE(",
10 CONTINUE
F = 2.0 * Y/X
RETURN
END
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)
>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
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)
=y, (13.23)
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
22
= 4.0
e u12 2 + 0.25(4.0) = 3.1)
2v30
17 = 4.8
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
= --,---- -
L Euler's_methodeun'srnethOdLAflalYt1Cal
HHiHiH_
1.50 4.20 4.44 4.50
^^1.75 5.60 6.03 6.125
Error Analysis
It can be easily shown that Heun's method is a second-order method
Numerical Solution of Ordinary Differential Equations 429
= + 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
WR1TE(, k)
WRITE(*.*) ' Vrt! '2P of '{ at x ' is,,Y
WRITE(* , *)
STOP
END
* -------------
End of no iCEUN ------------------*
* - --------
------------------------------------------
Function subprogram
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
POLYGON METHOD
(xL+xL )'+Yi
= + 2
where
( hm1h
171., = t ( x1 , y . arid 1719 = fx + +
/ ,,,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
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
4 Numerical Methods
\ /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)
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:
= 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
(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
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,
m1+2r
-+------------h (13.38)
1
F-1
where,
in1 = f(x, y)
m2 = f( x +hLy L + - rnjh)
m1 =f(x,y)
m2 f(x± -2 , YL m1h
2)
I m2h
f ; +A, y 1 + ---- (13.39)
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
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
N = INT((XP-X)/H+0.5)
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(*,*)'-----------------------------------------,
WRITE(*,*)
WRITE(**) 'Value ot Y at X X, is', Y
WRITE(*,*)
STOP
END
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.
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)
/(h?_hflio_dj
2A
If we choose h 1 = 2h 2, then
F8
Any value of h <h 0 will give the desired accuracy.
(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.
+
(2fy (13.43)
: =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
t. 2
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
WH[TE( *)
WRITE(*,*(Va3ue of Y at- X
X
? (N ±])
WR1TE(, *)
STOP
END
F 2.0 Y/X
RETURI']
END
* ------------ -- End of function F(x, y ) ----------------*
Test Run Results
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
3 t2 + :37f1 - 9f)
= + 24 (55[ -
8.0146
2x 8.0146
= ..----.--- 8.0146
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
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 -
E, yI)
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
Y1+i
-Q
270
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
fL=-Y
f1 = - 0.6944444
12 — 0102040
f = -- 0.390f3250
Iteration I
y(1.S)y' =y0+4(2f1—f2+2f3)
= 0.5571506
1P
() =-0.3106396
Y Y2+(2+4f3+14)
= 0.5553961
4
_____
Modifier = 0.0000674
F,11
29
44 Numerical Methods
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
(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
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.
=m1h1m2(1)=01
,n(1)
-- 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)
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.
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
1-0.6
md)=
-2•i-0.6
1iL(2)--
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
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
(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
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
(e. - = y( 1) = 0
dx
for = 2.0 and 3.0
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
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
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
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)
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).
= 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
6+9
7.5
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
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
- Y[+1- Y - (14.5)
2h
Yi+12YiYL-1
YL
11 (14.6)
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
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
The major steps of finite difference method are given in Algorithm 14.2.
472 Numerlrnt MeThods
Algorithm 14.2
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 []
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
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.
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
=
or
+ 6 + 5) = 0
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.
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
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
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
1
I
0
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
Key Terms
(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
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
Solution of Partial
Differential Equations
(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.
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
or
1 (15.2)
21z
or
+fL-1
Ii" (15.3)
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
dx)y - 4hk
Aft Nurnrlca! Mehods
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
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
-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
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,
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
= + 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.
-. + 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.
[2 = } ( 75 + 100 + 0 + 0) = 43.75
M Numericel Methods
f3=(100+75+0+0)=43.75
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.
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
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..,
=(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
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
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
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
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
b HAXH
LI T
At
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
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
Key Terms
[- - ----fl
QUESTIO N.
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
-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