Imcprlqwqi
Imcprlqwqi
Imcprlqwqi
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
Index 19
i
Unit 3
(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.
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.
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:
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)!
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.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)
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:
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).
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
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)
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
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
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
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
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:
y f (x)
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
Exercise
1. Calculate the integral value of the following function from x = 0 to x = 1.6 using
Simpson’s 1/3 rule:
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:
(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:
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
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
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:
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
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
(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
}
}
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:
0.66211
0.65860
0.65948 0.65882
0.65881 0.65882
0.65898 0.65882
0.65882
0.65886
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:
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