Imcprlqwqi

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Numerical Method (CSC 207)

(Lecture Note for B.Sc. CSIT Third Semester)

Prajwal B. S. Kansakar
Prime College

October, 2018

Note: This is a work in progress. Please send your suggestions and comments at

prajwalknk@gmail.com
Contents

Title i

3 Numerical Differentiation and Integration 1


3.1 Numerical Differentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
3.1.1 Numerical Differentiation using Divided Differences . . . . . . . . . . 1
3.1.2 Error in Numerical Differentiation . . . . . . . . . . . . . . . . . . . . 2
3.1.3 Derivatives for evenly-spaced data . . . . . . . . . . . . . . . . . . . . 2
3.1.4 Numerical Differentiation for Explicitly Defined Functions . . . . . . . 3
3.1.5 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.2 Numerical Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.2.1 Newton-Cotes Method . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2.2 Composite formulas for evaluating integrals . . . . . . . . . . . . . . . 8
3.2.3 Numerical Double Integration . . . . . . . . . . . . . . . . . . . . . . 15
3.2.4 Romberg Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

Index 19

i
Unit 3

Numerical Differentiation and Integration

3.1 Numerical Differentiation


The method of obtaining the derivative of a function using a numerical technique is known as
numerical differentiation. There are mainly two situations where numerical differentiation is
required. They are

(i) The function value fi at some points xi are known but the function f itself is unknown.
Such functions are called tabulated functions.
(ii) The function f to be differentiated is known but is quite complicated and therefore diffi-
cult to differentiate.

When the function is given in tabulated form as (xi , fi ), i = 0, 1, · · · , n, the general method for
deriving the numerical differentiation formulae is to differentiate the corresponding interpolat-
ing polynomial. So corresponding to each of the interpolation formulae we have derived, we
can derive a formula for the derivative.

3.1.1 Numerical Differentiation using Divided Differences


Suppose that the tabulated values of a function f (x) are given at n + 1 points as (xi , fi ), i =
0, 1, · · · , n. The polynomial (Newton’s form) that interpolates these data points is
Pn (x) = f [x0 ] + f [x0 , x1 ](x − x0 ) + f [x0 , x1 , x2 ](x − x0 )(x − x1 ) + · · ·
· · · + f [x0 , x1 , · · · , xn ](x − x0 )(x − x1 ) · · · (x − xn−1 ) · · · · · · (1)
If Pn (x) is a good approximation of f (x), then we can assume that Pn0 (x) is a good approxima-
tion of f 0 (x). Therefore differentiating (1) with respect to x, we get
Pn0 (x) = f [x0 , x1 ] + f [x0 , x1 , x2 ][(x − x1 ) + (x − x0 )] + · · ·
X
n−1
(x − x0 )(x − x1 ) · · · (x − xn−1 )
· · · + f [x0 , x1 , · · · , xn ]
i=0
x − xi

1
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 2

Substituting for different values of x in the above expression, we can approximate the derivative
of f (x) for those values of x.

3.1.2 Error in Numerical Differentiation


The error in approximating f (x) by the interpolating polynomial Pn (x) is given by

f (n+1) (ξ)
E(x) = (x − x0 )(x − x1 ) · · · (x − xn )
(n + 1)!
where ξ is a point that depends on x. When this error term is differentiated, then we get the
error for approximating f 0 (x) by Pn0 (x) as follows:

f (n+1) (ξ) X (x − x0 )(x − x1 ) · · · (x − xn ) (x − x0 ) · · · (x − xn ) d (n+1)


n
0
E (x) = + f (ξ)
(n + 1)! i=0 (x − xi ) (n + 1)! dx

When x = xj , j = 0, 1, · · · , n, then

f (n+1) (ξ)
E 0 (xj ) = (xj − x0 )(xj − x1 ) · · · (xj − xj−1 )(xj − xj+1 ) · · · (xj − xn )
(n + 1)!
Y
n
f (n+1) (ξ)
= (xj − xi )
i=0,i6=j
(n + 1)!

which is the error of the approximation to f 0 (x) when x = xj .

3.1.3 Derivatives for evenly-spaced data


Suppose that the tabulated values of a function f (x) are given at n + 1 points as (xi , fi ), i =
0, 1, · · · n, where x0 , x1 , · · · xn are equal distance h apart i.e., xk = x0 + kh, k = 0, 1, · · · , n.
The Newton-Gregory forward difference interpolation polynomial for interpolating these points
is
∆2 f0 ∆n f0
Pn (x) = f0 + s∆f0 + s(s − 1) + · · · + s(s − 1) · · · (s − n + 1) · · · · · · (1)
2! n!
x − x0
where s = . Differentiating (1) with respect to x, we get Pn0 (x) which approximates
h
f 0 (x) as follows:
d d ds
Pn0 (x) = Pn (x) = Pn (x) ·
dx" ds dx #
∆n f0 X s(s − 1) · · · (s − n + 1)
2 n−1
1 ∆ f0
= ∆f0 + [s + (s − 1)] + · · · +
h 2! n! i=0 s−i

Substituting for different values of x in the above expression, we can approximate the derivative
of f (x) for different values of x.
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 3

3.1.4 Numerical Differentiation for Explicitly Defined Functions


The derivative of a function f (x) at some point x = a is given as the limit
f (a + h) − f (a)
f 0 (a) = lim .
h→0 h
When the function f (x) is known but complicated, then we can approximate the value of f 0 (a)
as the value of the ratio given by
f (a + h) − f (a)
f 0 (a) ≈
h
for some very small positive value of h. This formula is known as the forward difference
formula for f 0 (a). Note that f 0 (a) is approximated in this formula by approaching a from the
right side of a. If f 0 (a) is approximated by approaching a from the left of a, we obtain the
backward difference formula which is given by
f (a) − f (a − h)
f 0 (a) ≈ .
h
A more accurate formula known as central difference formula can also be used as
f (a + h) − f (a − h)
f 0 (a) ≈ .
2h
Second derivative central difference formula at x = a:
f (a + h) − 2f (a) + f (a − h)
f 00 (a) ≈
h2

3.1.5 Exercise
1. Find the derivative of the following tabulated function at x = 4.1 using divided differ-
ences table.
x 2 3 5 6
f 3 7 21 31

Solution: Here n = 3, so the formula for the derivation of above tabulated function is
P30 (x) = f [x0 , x1 ] + f [x0 , x1 , x2 ][(x − x0 ) + (x − x1 )]
+f [x0 , x1 , x2 , x3 ][(x − x0 )(x − x1 ) + (x − x1 )(x − x2 ) + (x − x0 )(x − x2 )] · · · · · · (1)

xi f [xi ] f [xi , xi+1 ] f [xi , xi+1 , xi+2 ] f [x0 , x1 , x2 , x3 ]


2 3
4
3 7 1
7 0
5 21 1
10
6 31
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 4

Therefore from (1), we have


P30 (x) = 4 + 1[(x − 2) + (x − 3)] + 0 = 2x − 1
When x = 4.1, we have
P30 (4.1) = 2 × 4.1 − 1 = 7.2.

2. Find the derivative of the following tabulated function at x = 0.242 using divided differ-
ences table.
x 0.21 0.23 0.27 0.32
f 0.3222 0.3617 0.4314 0.5051

3. For the function f (x) = ex sin x + ln x estimate f 0 (6.3) and f 00 (6.3) taking h = 0.01.
HINT: Use central difference formula.
4. How do you find the derivative if the function values are given in a tabulated form? The
distance traveled by a vehicle at the intervals of 2 minutes are given as follows. Evaluate
the velocity and acceleration of the vehicle at time t = 5, 10, 13.

T ime 0 2 4 6 8 10 12 14 16
Distance 0 0.25 1 2.2 4 6.5 8.5 11 13

5. Let f (x) = 3xex − cos x. Compute f 00 (1.3) using h = 0.1 and h = 0.01.
6. Consider the following table of data:

x 0.2 0.4 0.6 0.8 1.0


f (x) 0.9798652 0.9177710 0.808038 0.6386093 0.3843735

Use appropriate formula to compute f 0 (0.4), f 0 (0.6), f 00 (0.4), f 00 (0.6), f 0 (0.2), f 0 (1).

3.2 Numerical Integration


Many times we need to calculate the value of definite integrals of the type
Z b
f (x)dx.
a

If f (x) is a continuous function on the interval [a, b], then this definite integrals must exist.
But the class of functions f (x) for which such integrals can be calculated easily are limited.
For many functions f (x), it is extremely hard to find the integral using analytical techniques.
Also the function f (x) may be given in tabulated form. So in these cases we have to use
numerical methods for integration. In these numerical methods, we approximateZthe integrand
b
f (x) by a suitable polynomial function P (x) and then approximate the integral f (x)dx by
Z b a

P (x)dx. Since polynomials are easily integrable, so the latter can always be evaluated.
a
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 5

3.2.1 Newton-Cotes Method


To approximate the value of Z b
f (x)dx
a

numerically using Newton-Cotes method, we first of all divide the interval [a, b] into n equal
b−a
parts of length h by points xi = a + ih, i = 0, 1, · · · , n where h = . Then
n
a = x0 < x1 < x2 < · · · < xn = b

forms a partition of [a, b]. Let Pn (x) be the interpolating polynomial of f (x) interpolating at
n + 1 points (xi , fi ), i = 0, 1, · · · , n where fi = f (xi ). Then Pn (x) is given by the formula

s(s − 1) 2 s(s − 1) · · · (s − n + 1) n
Pn (x) = f0 + s∆f0 + ∆ f0 + · · · + ∆ f0
2! n!
200 C H A P T E R x4 − x0Numericalj Differentiation
j−1 and Integration
where s = and ∆ f0 = ∆ f1 − ∆ f0 are the j th forward differences. We now
j−1
h Z b Z b
approximate the4.6
Figure value of f (x)dx by Pn (x)dx.
a a

y = Pn(x)
y = f (x)

a  x x x x xn-1 xn  b x

Therefore
Z b Z b The following theorem is analogous to Theorem 4.2; its proof is contained in [IK],
p. 314.
f (x)dx ≈ Pn (x)dx
a a
Z  n 
Theorem 4.3 b Suppose that s(s −i f1)
i=0 a (xi ) 2denotes the (ns(s+−1)-point
1) · · · (sopen
− nNewton-Cotes
+ 1) n formula with
= xf−10 +
= s∆f 0 += b, and h ∆
a, xn+1 = · · · ++ 2). There exists ξ ∈ (a, b)∆forfwhich
f0−+a)/(n
(b 0 dx
a 2! n!
 
n  n+1
b
hn+3 f (n+2)
Z (ξb )
f (x) dx = ai f (xi ) + t 2 (t − 1) · · · (t − n) dt,
which is the Newton-Cotes formula
a for numerically
i=0
(n +
evaluating 2)! f (x)dx.
−1
a

if n is even and f ∈ C n+2


[a, b], and
 
n 
b
hn+2 f (n+1) (ξ ) n+1
f (x) dx = ai f (xi ) + t(t − 1) · · · (t − n) dt,
a i=0
(n + 1)! −1

if n is odd and f ∈ C n+1 [a, b].


6.1 Simpson’s Rule and Adaptive Simpson’s Rule 217
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 6
following type:
 1
Derivation of Trapezoidal rule from Newton-Cotes formula
f (x) d x ≈ A f (0) + B f (1)
0 Z b
Thus, theserule
The trapezoidal equations should be fulfilled:
for numerically evaluating f (x)dx results from Newton-Cotes formula
 1 a
when n = 1. Then h = b − a andf (x) x0 = = a,
1 :x1 = ad+ x=h= A+ b and
B so we have
Z b Z b Z b 0 1
1
f (x)dx ≈ P1 (x)dx = f (x) [f0 = : 0 ]dxx d x = = B
+ xs∆f
a a a 0 2
Z b Z b Z b
The solution is A = B = 12 , and the integrationb formula is x − x0
= f0 dx + ∆f0  sdx = f0 [x]a + ∆f0 dx
a a1 1 a h
 (x) d x2 ≈ b [ f (0) + f (1)]  
∆f0 0(xf − x0 ) 2 ∆f0 (b − x0 )2 (a − x0 )2
= f0 (b − a) + = f0 (b − a) + −
By a linear mapping y = (b h − a)x +2 a froma [0, 1] to [a, b], the hbasic Trapezoid
2 2
Rule for
the interval [a, b] ∆f
is obtained: 2
0 (b − a) ∆f0 h (f1 − f0 )h
= f0 h +  b = f0 h + = f0 h +
h 2 1 2 2
h f (x) d x ≈ (b − a)[ f (a) + f (b)]
= (f0 + f1 ). a 2
2
See Figure 6.1 for a graphical illustration.

f(x)

f(b)
p1(x)

f(a)

FIGURE 6.1
Basic Trapezoid x
Rule a b

   a+b 
The next obvious generalization is to take two subintervals a, a+b and , b and
Therefore b 2 2
to approximate a f (x) d x byZtaking the function of integration f (x) to be a quadratic
polynomial passing through the three
b
h f  a+b , and f (b). Let us seek a numerical
points f≈(a),
f (x)dx (f0 +2 f1 ).
integration formula of the following
a type: 2
 b
a+b
f (x) d x ≈ A f (a) + B f + C f (b)
Derivation of Simpson’s 1/3 a
rule from Newton-Cotes 2formula
The function f is assumed to be continuous on the Z binterval [a, b]. The coefficients A, B,
The Simpson’s 1/3 rule for numerically evaluating willf (x)dx
and C will be chosen such that the formula above give correct values
results fromfor the integral for-
Newton-Cotes
whenever f is a quadratic polynomial. It suffices toa integrate correctly the three functions
1, x, and 2 b−a a + bcombination of those
mula when n =x2. because
Then h a=polynomial
andofx degree
= a, xat most
=a+
0
2 is
h= a linear
1 , x = a + 2h = b and so
2
2 2
f (x) d x ≈ A f (−1) + B f (0) + C f (1)
−1

Thus, these equations should be fulfilled:


 1
f (x) = 1 : dx = 2 = A + B + C
−11
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 7
f (x) = x : x d x = 0 = −A + C
−1
 1
we have 2
f (x) = x :
2
x2 dx = = A + C
Z Z −1 3
b b
The solution isf (x)dx C = 13P
A = 13 ,≈ B = 43 . The resulting formula is
2 (x)dx
, and
a  Z1 a  
b 1 s(s+−4 1)
f (x) d x ≈ [ f (−1) f (0) 2+ f (1)]
= −1 f0 + s∆f 30+ ∆ f0 dx
a 2!
Using a linear mapping yZ =b 12 (b − 3s
a) + 12 (a +s2b) from [−1, 1] to s[a, b],we obtain the
basic Simpson’s Rule= over thefinterval
0+ ∆f + (∆f1 − ∆f0 ) − ∆f1 dx
[a, 0b]:
 b a 2  2 2 
h 1 a + b
f (x)
= d x(f≈ (b − a) f (a) + 4 f + f (b)
a 0+ 6 4f1 + f2 ). 2
3
See Figure 6.2 for an illustration.
f(a 
2
b
)
f(b) f (x)
p2(x)
p2(x)

f (a)

FIGURE 6.2
Basic Simpson’s x
a ab b
Rule 2

Figure 6.3 shows graphically the difference between the Trapezoid Rule and the Simp-
Therefore
son’s Rule. Z b
h
f (x)dx
Simpson ≈ (f0 + 4f1 + f2 ).
a 3
p (x)
2

f
p (x)
Derivation of Simpson’s 3/8 rule from1 Newton-Cotes formula
Z b
The Simpson’s 3/8 rule for numerically evaluating f (x)dx results from Newton-Cotes for-
FIGURE 6.3 aTrapezoid
Example of when n = 3. Then h = b − a
mula and x0 = a, x1 = a + h =
2a + b
, x2 = a + 2h =
a + 2b
,
Trapezoid Rule 3 3 3
x3 = a + 3h = b and so we have
vs. Simpson’s a ab b
Rule Z Z 2
b b
f (x)dx ≈ P3 (x)dx
a a
Z b 
s(s − 1) 2 s(s − 1)(s − 2) 3
= f0 + s∆f0 + ∆ f0 + ∆ f0 dx
a 2! 3!
3h
= (f0 + 3f1 + 3f2 + f3 )
8
Therefore Z b
3h
f (x)dx ≈ (f0 + 3f1 + 3f2 + f3 ).
a 8
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 8

3.2.2 Composite formulas for evaluating integrals


Composite Trapezoidal Rule
Z b
Suppose we have to evaluate the integral f (x)dx. We first divide the interval [a, b] into n
a
b−a
equally spaced subintervals by points xi = a + ih, i = 0, 1, · · · , n where h = . Then
Z xi n
in each subinterval [xi−1 , xi ], i = 1, 2, · · · , n, we approximate the integral f (x)dx by the
xi−1
h
trapezoidal formula [f (xi−1 ) + f (xi )] so that
2
Z b Z x1 Z x2 Z xn
f (x)dx = f (x)dx + f (x)dx + · · · + f (x)dx
a x0 x1 xn−1
h h h
≈ [f (x0 ) + f (x1 )] + [f (x1 ) + f (x2 )] + · · · + [f (xn−1 ) + f (xn )]
2 2 2
h
= [f (x0 ) + 2(f (x1 ) + · · · + f (xn−1 )) + f (xn )]
2
Therefore Z b
h
f (x)dx ≈
[f0 + 2(f1 + · · · + fn−1 ) + fn ]
a 2
Z b
which is the composite trapezoidal rule for calculating f (x)dx.
a

Algorithm (Composite Trapezoidal Rule):


I NPUT: A function f (x), limits of integration a and b and the number of intervals n.
P ROCESS :
b−a
SET h =
n
SET sum = 0
FOR i = 1 to n − 1 {
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 9

SET x = a + hi
SET sum = sum + 2f (x)
}
SET sum = sum + f (a) + f (b)
h
SET ans = sum ×
2
O UTPUT: Approximate value of the integral equal to ans.
Theorem (Error in Composite Trapezoidal Rule): If f is twice continuously
Z b differentiable
on the interval [a, b], then the error in approximating the integral f (x)dx by composite
a
trapezoidal rule with subinterval length h is
1
E=− (b − a)h2 f 00 (ξ)
12
for some ξ ∈ (a, b).

Exercise

1. Calculate the integral value of the following function from x = 1.8 to x = 3.4 using
composite trapezoidal rule.

x 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4
f (x) 4.953 6.050 7.389 9.025 11.023 13.464 16.445 20.086 24.533 29.964

Solution: Here h = 0.2. So using the composite trapezoidal rule, the integral value of
the given tabulated function from x = 1.8 to x = 3.4 is given by
Z 3.4
0.2
f (x) dx ≈ [6.050+2(7.839+9.025+11.023+13.464+16.445+20.086+24.533)+29.964]
1.8 2
= 0.1 × 239.944 = 23.9944.

2. Evaluate the integral of the following function from x = 1.0 to x = 1.8 using composite
trapezoidal rule with h = 0.1, h = 0.2 and h = 0.4

x 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8


f (x) 1.543 1.669 1.811 1.971 2.151 2.352 2.577 2.828 3.107

Solution: If h = 0.2, then the composite trapezoidal rule gives the following value of the
integral:
Z 1.8
0.2
f (x) dx ≈ [1.543+2(1.811+2.151+2.577)+3.107] = 0.1×17.728 = 1.7728.
1.0 2
Similarly we can calculate approximations for h = 0.1 and h = 0.4.
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 10
Z 1
2
3. Evaluate e−x dx using composite trapezoidal rule with n = 5 up to 6 decimal places.
0
b−a 1
Solution: Here a = 0, b = 1 and n = 5. So h = = = 0.2. So we get the
5 5
following table:

x 0 0.2 0.4 0.6 0.8 1.0


f (x) 1 0.960789 0.852144 0.697676 0.527292 0.367879
Z 1
2
Therefore the approximation of e−x dx using composite trapezoidal rule is
0
Z 1
2 0.2
e−x dx ≈ [1 + 2(0.960789 + 0.852144 + 0.697676 + 0.527292) + 0.367879)]
0 2
= 0.1 × 7.443681 = 0.7443681.

4. Use composite trapezoidal rule to evaluate the following up to 5 decimal places.


Z π
a. (3 cos x + 5) dx with n = 5
0
Z 1
dx
b. with n = 5
0 1 + x2
Z 0.5
c. cos2 xdx with n = 4
−0.5
Z e+2
dx
d. with n = 8
e x ln x
Z 1.75
e. (sin2 x − 2x sin x + 1)dx with n = 8
0.75
Z 0.5
f. x ln(x + 1)dx with n = 6. ≈ 0.09363
−0.5
Z 2
g. e2x sin 3xdx with n = 8. ≈ −13.7560
Z0 π
h. x2 cos xdx with n = 6. ≈ −6.42872
0
Z 2
ex
i. dx with n = 4.
1 x

Composite Simpson’s 1/3 Rule


Z b
Suppose we have to evaluate the integral f (x)dx. We first divide the interval [a, b] into n
a
b−a
equally spaced subintervals by points xi = a + ih, i = 0, 1, · · · , n where h = . However,
n
The exact answer in this case is e4 − e0 = 53.59815, and the error −3.17143 is far larger
than we would normally accept.
Applying Simpson’s rule on each of the intervals [0, 2] and [2, 4] uses h = 1 and gives
 4  2  4
ex dx = ex dx + ex dx
0 0 2
1 0
UNIT 3. NUMERICAL DIFFERENTIATION AND 1 2
 INTEGRATION  11
2 3 4
≈ e + 4e + e + e + 4e + e
3 3
here we assume that the number of1 such subintervals is even i.e., n is even. Then for each
= ne0 + 4e + 2e2 + 4e3 + e4 Rx
subinterval [x2i , x2i+2 ], i = 0, 1, · · ·3, − 1, we approximate the integral x2i2i+2 f (x)dx by the
2
Simpson’s 1/3 formula = 53.86385.
h
The error has been reduced to[f−0.26570.
(x2i ) + 4f (x2i+1 ) + f (x2i+2 )]
For the integrals on [0, 31],[1, 2],[3, 4], and [3, 4] we use Simpson’s rule four times with
so thath = 21 giving
Z b 4 Z1 x2  2 Z x4  3  4 Z xn
e dx == e fdx(x)dx
x
f (x)dx x
+ + e dx +f (x)dx
x
e dx++· · · +ex dx f (x)dx
x
a 0 0 x0 1 x2 2 3 xn−2
1h  1 h 2
+ 04e
≈≈ e[f0 (x ) 1/2
+ 4f+ (x
e 1+) + fe(x+24e + + [f
)]3/2 e (x2 ) + 4f (x3 ) + f (x4 )]
63 6 3
1 2  1h 
+ e + 4e5/2 ++e·3 · ·++ e[f3 (x
+ n−2 )+
4e7/2 + 4f
e4 (xn−1 ) + f (xn )]
6 6 3
h
1 0 (x ) 1/2 
2 ··· +
== 3 [f
e + 04e+ 4(f (x+
+ 2e 1 )4e
+3/2
f (x )+
+32e + 4e5/2f+(x2e 3 ))+7/2
+ 4e + e4
n−1
6
= 53.61622. 2(f (x2 ) + f (x4 ) + · · · + f (xn−2 )) + f (xn )]

The error for this approximation has been reduced to −0.01807.


Therefore
Z b  b
h
(x)dx ≈ this
To fgeneralize [f0procedure f3 ·an
+ 4(f1 +for · · arbitrary
+ fn−1 ) + 2(f2 + f4f+
integral (x)· ·dx,
· +choose
fn−2 ) +
anfeven
n]
a 3 a
integer n. Subdivide the interval [a, b] into n subintervals, and
Z b apply Simpson’s rule on
each consecutive pair of subintervals. (See Figure 4.7.)
which is the composite Simpson’s 1/3 rule for approximating f (x)dx.
a
Figure 4.7
y

y  f (x)

a  x0 x2 x2i x2i1 x2i+2 b  xn x

Algorithm (Composite Simpson’s 1/3 Rule):


yright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
I NPUT: A function f (x), endpoints a and b and an even number of intervals n.
review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

P ROCESS :
b−a
SET h =
n
SET sum = 0
n
FOR i = 1 to {
2
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 12

SET x = a − h + 2hi
SET sum = sum + 4f (x)
n
IF i 6= THEN SET sum = sum + 2f (x + h)
2
}
SET sum = sum + f (a) + f (b)
h
SET ans = sum ×
3

O UTPUT: Approximate value of the integral equal to ans.


Theorem (Error in Composite Simpson’s 1/3 Rule): If f is four times
Z continuously differen-
b
tiable on the interval [a, b], then the error in approximating the integral f (x)dx by composite
a
Simpson’s 1/3 rule with subinterval length h is
1
E=− (b − a)h4 f (4) (ξ)
180
for some ξ ∈ (a, b).

Exercise

1. Calculate the integral value of the following function from x = 0 to x = 1.6 using
Simpson’s 1/3 rule:

x 0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6


f (x) 0 0.24 0.55 0.92 1.63 1.84 2.37 2.95 3.56

Solution: Here h = 0.2. So using the composite Simpson’s 1/3 rule, the integral value
of the given function is approximated as
Z 1.6
0.2
f (x) dx ≈ [0 + 4(0.24 + 0.92 + 1.84 + 2.95) + 2(0.55 + 1.63 + 2.37) + 3.56]
0 3
0.2
= × 36.46 = 2.43.
3
2. Evaluate the integral of the following function from x = 0.7 to x = 1.9 using Simpson’s
1/3 rule:

x 0.7 0.9 1.1 1.3 1.5 1.7 1.9 2.1


f (x) 0.64835 0.91360 1.16092 1.36178 1.49500 1.55007 1.52882 1.44513

(Ans: 1.51938)
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 13

sin x
3. Compute the integral of f (x) = between x = 0 to x = 1 using Simpson’s 1/3 rule
x
with h = 0.5 and then h = 0.25.
Solution: Taking h = 0.25, we get the following table:

x 0 0.25 0.5 0.75 1


sin x
x
1 0.98962 0.95885 0.90885 0.84147

sin x
Here we have use the fact that lim = 1. Now for h = 0.5, the value of the integral
x→0 x
Z 1
sin x
dx is approximated as
0 x
Z 1
sin x 0.5 0.5
dx ≈ [1 + 4 × 0.95885 + 0.84147] = × 5.67687 = 0.946145.
0 x 3 3
Similarly we can approximate the integral taking h = 0.25.

4. Use composite Simpson’s 1/3 rule to evaluate the following up to 5 decimal places using
n = 4:
Z π Z 1 Z 2 x
dx e
a. (3 cos x + 5) dx b. 2
c. dx
0 0 1+x 1 x
Solution:
b−a π
a. Here a = 0, b = π and n = 4. So h = = . Therefore we get the following
n 4
table:
π π 3π
x 0 4 2 4
π
3 cos x + 5 8 7.12132 5 2.87868 2
Z π
Hence the approximation of the integral (3 cos x + 5) dx using composite Simpson’s
0
1/3 rule is
Z π
π/4 π
(3 cos x+5) dx ≈ [8+4(7.12132+2.87868)+2×5+2] = ×60 = 5π = 15.70796.
0 3 12

5. Calculate with 5 decimal places the problems 4(c)-4(i) of previous problem.

Composite Simpson’s 3/8 Rule


Z b
Suppose we have to evaluate the integral f (x)dx. We first divide the interval [a, b] into n
a
b−a
equally spaced subintervals by points xi = a + ih, i = 0, 1, · · · , n where h = . However,
n
here we assume that the number of such subintervals is divisible by 3. Then for each subinterval
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 14

n Rx
[x3i , x3i+3 ], i = 0, 1, · · · , − 1, we approximate the integral x3i3i+3 f (x)dx by the Simpson’s
3
3h
3/8 formula [f (x3i ) + 3f (x3i+1 ) + 3f (x3i+2 ) + f (x3i+3 )] so that
8
Z b Z x3 Z x6 Z xn
f (x)dx = f (x)dx + f (x)dx + · · · + f (x)dx
a x0 x3 xn−3
3h 3h
≈ [f (x0 ) + 3f (x1 ) + 3f (x2 ) + f (x3 )] + [f (x3 ) + 3f (x4 ) + 3f (x5 ) + f (x6 )]
8 8
3h .
+ · · · + [f (xn−3 ) + 3f (xn−2 ) + 3f (xn−1 ) + f (xn )]
8
3h
= [f (x0 ) + 3(f (x1 ) + f (x4 ) + · · · + f (xn−2 )) + 3(f (x2 ) + f (x5 ) + · · · + f (xn−1 ))
8
+ 2(f (x3 ) + f (x6 ) + · · · + f (xn−3 )) + f (xn )]

Therefore
Z b
3h
f (x)dx ≈ [f0 + 3(f1 + f4 + · · · + fn−2 ) + 3(f2 + f5 + · · · + fn−1 )
a 8
+ 2(f3 + f6 + · · · + fn−3 ) + fn ]
Z b
which is the composite Simpson’s 3/8 rule for approximating f (x)dx.
a
Algorithm (Composite Simpson’s 3/8 Rule):
I NPUT: A function f (x), endpoints a and b and number of intervals n which is divisible by 3.
P ROCESS :

b−a
SET h =
n
SET sum = 0
n
FOR i = 1 to {
3
SET x = a − 2h + 3hi
SET sum = sum + 3f (x)
SET sum = sum + 3f (x + h)
n
IF i 6= THEN SET sum = sum + 2f (x + 2h)
3
}
SET sum = sum + f (a) + f (b)
3h
SET ans = sum ×
8

O UTPUT: Approximate value of the integral equal to ans.


UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 15

Exercise
2
1. Apply Simpson’s 3/8 rule to integrate f (x) = e−x from x = 0.2 to x = 1.4 with n = 6.
2 b−a 1.2
Solution: Here f (x) = e−x a = 0.2, b = 1.4 and n = 6. Therefore h = = =
n 6
0.2. So we get the following table:

x 0.2 0.4 0.6 0.8 1.0 1.2 1.4


f (x) 0.960789 0.852144 0.697676 0.527292 0.367879 0.236928 0.140858
Z 1.4
2
Therefore the approximation of e−x dx using composite Simpson’s 3/8 rule is
0.2
Z 1.4
2 3 × 0.2
e−x dx ≈ [0.960789 + 3(0.852144 + 0.367879) + 3(0.697676 + 0.236928)
0.2 8

+2 × 0.527292 + 0.140858] = 0.075 × 8.620112 = 0.6465084.


Z 7
2. Evaluate f (t) dt using composite Simpson’s 3/8 rule using the following table.
1

t 1 2 3 4 5 6 7
f (t) 81 75 80 83 78 70 60

b−a 7−1
Solution: Here n = 6, and a = 1, b = 7. So h = = = 1. Therefore, using
n 6
composite Simpson’s 3/8 rule, we get
Z 7
3h 3
f (t) dt ≈ [81 + 3(75 + 78) + 3(80 + 70) + 2 × 83 + 60] = × 1216 = 456.
1 8 8

3. Use Simpson’s 3/8 rule to evaluate


Z 2.8
a. (x3 + 1) dx with n = 9
1
Z π/2
b. sin x dx with n = 6
0

3.2.3 Numerical Double Integration


Suppose we have to evaluate the double integral
Z bZ d
f (x, y)dydx
a c
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 16

where a, b, c and d are constants. For this, we write it as an iterated integral as


Z b Z d 
f (x, y)dy dx.
a c

This can be evaluated by first holding x variable constant while integrating with respect to
y variable to obtain the inner integral and then integrating with respect to the x variable to
1
obtain the outer integral. While integrating, we can use any of the trapezoidal, Simpson’s or
3
3
Simpson’s rule for both the x and y variables or any combination of these rules as required.
8

3.2.4 Romberg Integration


Z b
Let f (x) dx be the integral that has to be evaluated. Let the interval [a, b] be divided into
a Z b
subintervals of equal length h and T (h) denote the approximation of the integral f (x) dx us-
a Z
b
ing composite trapezoidal rule with subinterval length h. A better approximation of f (x) dx
 a
h h
can be obtained by taking subintervals of length which we denote by T . Then the
2  2
h
Romberg method of integration uses T (h) and T to obtain a better approximation R(h)
2
using extrapolation as follows:
     
h 1 h
R(h) = T + n T − T (h)
2 4 −1 2

where n is the order of the error.


Algorithm (Romberg Integration):
I NPUT: A function f (x), limits of integration x = a to x = b, and maximum number of stages
NST.
P ROCESS :

(b − a)
SET h =
2
SET sum= f (a) + 2f (a + h) + f (b)
h
SET T (0, 0) =sum×
2
SET d = 2h
FOR ST= 1 TO NST {
h
SET h =
2
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 17

d
Set d =
2
FOR i = 1 to 2ST {
SET x = a − h + di
SET sum= sum+2 × f (x)
}
h
SET T (ST, 0) =sum×
2
FOR j = 1 TO ST {
T (ST, j − 1) − T (ST − 1, j − 1)
SET T (ST, j) = T (ST, j−1)+
4j − 1
}
}

O UTPUT: Romberg integral table

Exercise
2
1. Use Romberg integration to find the integral of e−x between the limits of a = 0.2 and
b−a b−a
b = 1.5 with initial subinterval size as h = = 0.65 and final size h = =
2 16
0.08125.
Z 1.5
2
Solution: Let T (h) denote the approximation of the integral e−x dx using com-
0.2
posite trapezoidal rule with subinterval length h. We need to calculate T (h) for h =
0.65, 0.325, 0.1625 and 0.08125. We make the table as follows:
x f (x)
0.2 0.96079
0.28125 0.92395
0.3625 0.87686
0.44375 0.82126
0.525 0.75910
0.60625 0.69244
0.6875 0.62334
76875 0.55379
0.85 0.48554
0.93125 0.42012
1.10125 0.35874
1.09375 0.30231
1.175 0.25142
1.25625 0.20635
1.3375 0.16714
1.41875 0.13361
1.5 0.10540
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 18

Therefore
0.08125
T (0.08125) = [0.96979+2(0.92395+0.87686+0.82126+0.75910+0.69244+0.62334
2
+0.55379 + 0.48554 + 0.42012 + 0.35874 + 0.30231 + 0.25142 + 0.20635
+0.16714 + 0.13361) + 0.10540] = 0.65886
0.1625
T (0.1625) = [0.96979 + 2(0.87686 + 0.75910 + 0.62334 + 0.48554
2
+0.35874 + 0.25142 + 0.16714) + 0.10540] = 0.6589
0.325
T (0.325) = [0.96979 + 2(0.75910 + 0.48554 + 0.25142) + 0.10540] = 0.65948
2
0.65
T (0.65) = [0.96979 + 2 × 0.48554 + 0.10540] = 0.66211
2
Using the above approximations, we can calculate more accurate approximations as shown
in the table below:

Romberg Table of Integrals

0.66211
0.65860
0.65948 0.65882
0.65881 0.65882
0.65898 0.65882
0.65882
0.65886

Calculation of approximations in second column:

1
0.65948 + [0.65948 − 0.66211] = 0.65860
41
−1
1
0.65898 + 1 [0.65898 − 0.65948] = 0.65881
4 −1
1
0.65886 + 1 [0.65886 − 0.65898] = 0.65882
4 −1
Calculation of approximations in third column:
1
0.65881 + [0.65881 − 0.65860] = 0.65882
42 −1
1
0.65882 + [0.65882 − 0.65881] = 0.65882
42 −1
Calculation of approximations in fourth column:
1
0.65882 + [0.65882 − 0.65882] = 0.65882
43 −1
UNIT 3. NUMERICAL DIFFERENTIATION AND INTEGRATION 19
Z 1.5
2
Therefore, the approximation of the integral e−x dx using Romberg integration is
0.2
0.65882.

2. Use the following data table to get the integral by Romberg method between the limits
x = 1.8 to x = 3.4 and beginning with h = 0.8.

x f (x)
1.6 4.953
1.8 6.050
2.0 7.389
2.2 9.025
2.4 11.025
2.6 13.464
2.8 16.445
3.0 20.086
3.2 24.533
3.4 29.964
3.6 36.598
3.8 44.701

Solution:

Romberg Table of Integrals

25.1768
23.9181
24.2328 23.9147
23.9149
23.9944
Index

algorithm
composite Simpson’s 1/3 rule, 11
composite Simpson’s 3/8 rule, 14
composite trapezoidal rule, 8
Romberg integration, 16

20

You might also like