Numerical Differentiation and Integration-BK9
Numerical Differentiation and Integration-BK9
3.1 Introduction
3.2 Numerical Differentiation
3.3 Numerical Integration
3.4 Trapezoidal Rule
3.5 Simpson’s One Third Rule
3.6 Simpson’s Three Eight Rule
38
3.7 Waddle’s Rule
3.8 Cote’s Method
3.1 Introduction
We assume that a function f(x) is given in a tabular form at a set of n+1 distinct points
x0, x1, …, xn. From the given tabular data, we require approximations to the derivatives
f ( r ) (x), r 1 , where x may be a tabular or a non-tabular point. We consider the cases
r = 1, 2.
In many applications of science and engineering, we require to compute the value of
b
the definite integral f ( x ) dx , where f(x) may be given explicitly or as a tabulated data. Even
a
when f(x) is given explicitly, it may be a complicated function such that integration is not
easily carried out.
Here, we shall derive numerical methods to compute the derivatives or evaluate an
integral numerically.
39
b
The process of evaluating a definite integral f x dx from a set of tabulated values
a
Newton cote’s formula (or) General Quadrature formula for equidistant coordinates
b
Let I y dx where y = f(x) takes the values y0, y1, …, yn for x0, x1, …, xn. Let us
a
divide the interval (a, b) into n sub intervals of width h so that x0 = a, x1 = x0+h, x2 = x0+2h,
…, xn = x0+nh = b. After simplification, we get
n2n 3 2 nn 2 3
xn 2
n
I ydx nh y 0 y 0 y0 y 0 (1)
x0 2 12 24
1
By putting n = 2 in equation (1), Simpson’s rule is obtained.
3
3
By putting n = 3 in equation (1), Simpson’s rule is obtained.
8
h
2 y0 y0
2
h
y0 y0 y0
2
h
y0 y1
2
Similarly,
x2 x0 2 h
1
y dx
x1 x0 h
y dx h y1 y1
2
h
2 y1 y1
2
40
h
y1 y1 y1
2
h
y1 y 2
2
and so on.
xn x0 nh
y dx y dx
h
y n1 y n
xn 1 x0 n 1h
2
1
3.5 Simpson’s Rule (or) Simpson’s Rule
3
Putting n = 2 in equation (1) and neglecting the differences of higher order than
second order. We get,
xn
y dx 3 y y n 4 y1 y3 y n 1 2 y 2 y 4 y n 2 .
h
0
x0
Note:
It should be noted that for applying this rule, the interval must be divided into even
number of sub intervals of width h.
3
3.6 Simpson’s th Rule
8
Putting n = 3 in equation (1) and neglecting the higher order differences above the
third, we get
xn
y dx 8 y y n 3 y1 y 2 y 4 y5 y n 1 2 y3 y 6 y n 3
3h
0
x0
Note:
This is not as accurate as Simpson’s rule. This rule is used when the number of
subintervals is a multiple of 3.
Example: 1
1
dx
Using Trapezoidal rule, evaluate 1 x
1
2
taking 8 intervals.
41
Solution
Given y f x
1
1 x2
Given x = -1 to 1.
Length of interval = 2.
2 ba
h 0.25 . h
8 number of int ervals
1 1
0.25
8
We form a table
xn
y dx 2 y y n 2 y1 y 2 y3 y n 1
h
Trapezoidal rule is 0
x0
1 x
1
2
dx
0.25
0.5 0.5 20.64 0.8 0.9412 1 0.9412 0.8 0.64
1
2
0.25
1 25.7624
2
=1.5656.
Example: 2
1
dx 1
Evaluate 1 x
0
2
with h
6
by Trapezoidal rule.
Solution
Given y f x
1
1 x2
Given x = 0 to 1
1
Also h .
6
42
The table is
By Trapezoidal rule,
xn
y dx 2 y y n 2 y1 y 2 y3 y n1
h
0
x0
1
1
1
6 1 36 9 4 9 36
0 1 x 2 dx 2 1 2 2 37 10 5 13 31
1 3
23.9554
12 2
= 0.7842.
Example: 3
5.2
log e dx by using (i) Trapezoidal rule (ii) Simpson’s rule (iii) Simpson’s
x
Evaluate
4
3
rule, given that h = 0.2.
8
Solution
x = 4 to 5.2, h = 0.2.
The table is
y dx 2 y y n 2 y1 y 2 y3 y n 1
h
0
x0
0.2
1.737 2.258 21.824 1.910 1.997 2.084 2.171
2
43
= 0.3967.
1
(ii) By Simpson’s rule (or) Simpson’s rule,
3
xn
y dx 3 y y n 4 y1 y3 y n 1 2 y 2 y 4 y n 2
h
0
x0
5.2
log e
x
dx
0.2
1.737 2.258 41.824 1.997 2.171 21.910 2.084
4
3
= 0.0666[3.995+4(5.992)+2(3.994)]
= 2.394.
3
(iii) By Simpson’s rule,
8
xn
y dx 8 y y n 3 y1 y 2 y 4 y5 y n 1 2 y3 y 6 y n 3
3h
0
x0
30.2
1.737 2.258 31.824 1.910 2.084 2.171 21.997
8
= 2.3967.
Romberg’s Method
b
Romberg’s method is used to evaluate the integral of the form I y dx .
a
For Romberg’s method, let us apply Trapezoidal rule several times find the value of
I’s as follows:
h
I1: Dividing ‘h’ into 2 parts (i.e)
2
h h/2
I2: Dividing ‘h’ into 4 parts (i.e)
4 2
h h/4
I3: Dividing ‘h’ into 8 parts (i.e)
8 2
h h/8
I4: Dividing ‘h’ into 16 parts (i.e)
16 2
and so on.
44
Applying Romberg’s formula,
I I
I I2 2 1
3
We get the values of I. This method continues till we get two successive values of I’s
are equal. The systematic refinement of the values of I’s is called Romberg’s method.
Example: 1
1
dx
Use Romberg’s method to compare . Correct to 4 decimal places and hence
0 1 x 2
Solution
1
dx
Let I
0 1 x
2
To find I1:
h
Dividing h into 2 parts (i.e) .
2
1 0
h 0.5
2
X 0 0.5 1
1 1 0.8 0.5
y=
1 x2
By Trapezoidal rule,
I1
h
y0 y 2 2 y1
2
0.5
1 0.5 20.8
2
= 0.775.
To find I2:
h
Dividing h into 4 parts (i.e) .
4
45
1 0
h 0.25
4
By Trapezoidal rule,
I2
0.25
1 0.5 20.941 0.8 0.64
2
= 0.7828.
To find I3:
h/4
Dividing h into 8 parts (i.e)
2
1 0
h 0.125
8
By Trapezoidal rule,
I3
0.125
1 0.5 20.984 0.94 0.876 0.8 0.719 0.64 0.56
2
= 0.78475.
By Romberg’s Formula:
Iteration 1:
I I
I I2 2 1
3
0.7828 0.775
0.7828
3
I = 0.7854.
Iteration 2:
46
I I
I I3 3 2
3
0.78475 0.7828
0.78475
3
I = 0.7854.
To find π:
1
1 x
1
dx
0 1 x 2 tan 1
0
.
4
1
dx
But 1 x
0
2
0.7854
0.7854
4
π = 4(0.7854)
3.1416 .
The one point Gaussian formula is given by f x dx 2. f 0 which is exact for
1
polynomials of degree up to 1.
47
1
1 1
The two point Gaussian formula is 1 f x dx f
f
3 and this is exact
3
for polynomial of degree up to 3.
5 3 3
1
f x dx 9 f 0 9 f
8
The three point Gaussian formula is f
1 5 5
which is exact for polynomial of degree up to 5.
Note:
b 1
(i) The integral F t dt , can be transformed into
a
f x dx by the linear
1
transformation.
b a x b a
t .
2
b 1
(ii) The integral F x dx , can be transformed into
a
f t dt by the linear
1
transformation.
b a t b a
x .
2
Example: 1
1
dx
Evaluate 1 x
1
2
by two point and three point Gaussian formula and compare with
exact value.
Solution
1
1 1
By two point Gaussian formula, f x dx f
3
f
3
1
Given f x
1
.
1 x2
1 1 3
f
3 1 4
1
3
1 1 3
f
3 1 1 4
3
48
1
f x dx
3 3 6
1.5
1
4 4 4
1
f x
1
1 x
1
2
dx 1.5 .
5 3 3
1
f x dx 9 f 0 9 f
8
By three point Gaussian formula, f
1 5
5
f 0
1
1
1 0
3 1 5
f
5 3 8
1
5
3 1 5
f
5 1 3 8
5
5 5 5
1
f x dx
8
1
1
9 9 8 8
8 5 10
9 9 8
1
f x dx 1.5833 .
1
2 tan 1 x 0
1
2 0
4
2
1
dx
1 x
1
2
1.5708 .
Solution
5 3 3
1
f x dx f 0 f
8
Three point Gaussian Quadrature formula is 9
f
5
5
1
9
1
x2
Given dx
1 1 x
4
x2
Here f x
1 x4
f 0
0
0
1 0
3
3 15
f 5 2
5 3 34
1 2
5
Similarly,
3 15
f
34
5
5 3 3
1
f x dx f 0 f
8
9
f
5
5
1
9
8 5 15 15
0
9 9 34 34
1
x2
dx 0.4902 .
11 x
4
Simpson’s rule.
The formula for the evaluation of a double integral can be obtained by repeatedly
applying the Trapezoidal and Simpson’s rules.
50
Trapezoidal Rule for Double Integral
The formula for the evaluation of double integral using Trapezoidal rule is,
The formula for the evaluation of double integral using Simpson’s rule is,
Example: 1
2 2
Evaluate f x, y dx dy by Trapezoidal rule for the following data:
0 0
x 0 0.5 1 1.5 2
0 2 3 4 5 5
1 3 4 6 9 11
2 4 6 8 11 14
Solution
Here, h = 0.5, k = 1.
2 2
I f x, y dx dy
0 0
By Trapezoidal rule,
51
sum of the values at four corner of the box
hk
I 2sum of the values at the boundary of the box except the corner
4
4sum of the remaing values
0.5 1 2 5 14 4 23 4 5 11 11 8 6 3 44 6 9
4
I = 25.375.
Example: 2
1 1
1 1
Using Simpson’s
3
rule evaluate 1 x y dx dy taking h = k = 0.5.
0 0
Solution
x 0 0.5 1
0 1 0.6667 0.5
Let
1
gy
1
dx dy
0
1 x y
By Simpson’s rule,
g 0
0.5
1 0.5 40.6667 1.5 2.66668
3
g 0 0.69441889 .
g 0.5
0.5
0.6667 0.4 3.0667 40.5
3
52
g 0.5 0.51111 .
g 1
0.5
0.5 0.3333 40.4
3
g 1 0.405538 .
Hence
1
I g y dy
0
0.5
0.9441889 0.405538 40.51111
3
I 0.5241.
3.7 Weddle’s Rule
Put n = 6 in Newton-Cot’s Quadratic formula and neglecting all differences of orders
higher than sixth, we get
x 0 nh
f (x)dx 10 y0 5y1 y 2 6y3 y 4 5y5 y6 y6 5y7 y8 6y9 y10 5y11 y12
3h
x0
Example: 1
1
dx
Evaluate 1 x using Weddle’s rule with 6 equal intervals.
0
Solution
1
Here n = 6, h ,
6
1 1 2 3 6
Let y f ( x ) x 0, , , ,, .
1 x 6 6 6 6
x 0 1 2 3 4 5 1
6 6 6 6 6
1 1 0.8571 0.75 0.667 0.6 0.5455 0.5
y
1 x
53
By Weddle’s rule,
1
1 x dx 10 y 0 5y1 y 2 6y3 y 4 5y5
1 3h
0
1
3
1 5(0.8571) 0.75 6(0.6667) 0.6 5(0.5455 0.5
6
10
= 0.69320.
3.8 Newton’s – Cote’s Formula (or) Cote’s Formula
b
Newton’s-Cote’s formula gives a way for computing the integral f ( x )dx
a
numerically, when y = f(x) is known at equidistance values of x, but its derivation is based
on the integration of Lagrange’s interpolation formula.
b n n
f (x)dx h y k C k (u)du
a k 0 0
C k (u ) (1) n k
u k . n u nk
k!(n k )!
Put n = 1 and k = 0 in Ck (u )
C 0 (u )
u 0 . 1 u 1 u 1.
0!(1 0)!
C1 (u )
u 1. 1 u 0 u.
1!(1 1)!
Example: 2
Find the Cote’s polynomials for n=2.
Solution
C k (u ) (1) n k
u k . n u nk
k!(n k )!
54
C 0 (u )
u 0 . 2 u 2
0!(2 0)!
(2 u )(1 u )
2
2 3u u 2
2
C (u )
u . 2 u
1 1
1!(2 1)!
1
u (2 u )
1
= 2u-u2
C 2 (u )
u 2 . 2 u 0
2!(2 2)!
u (u 1)
2
u u2
C2 (u) .
2
Exercises:
2
dx
1. Evaluate the integral 1 x
1
2
using Trapezoidal rule with two subintervals.
2
2. Dividing the range into 10 equal parts, find the value of sin x dx by (i) Trapezoidal rule
0
e
x
4. Calculate x dx taking 5 ordinates by Simpson’s rule.
0.5
2
dx
5. Evaluate x
0
2
4
using Romberg’s method. Hence, obtain an approximate value of π.
6. Using Romberg’s method, Evaluate sin x dx correct to four decimal places.
0
1
1
7. Using three point Gaussian Quadrature formula, Evaluate dt .
0 1 t
2
55
x 2 2x 1
2
8. Evaluate 1 x 1
0
4
dx by Gaussian three point formula.
1.5
e
x2
9. Evaluate dx using the three point Gaussian Quadrature.
0.2
1
dx
10. Evaluate 1 x by Gaussian formula with two points.
0
5
1
11. Use Gaussian three point formula and evaluate dx .
1
x
3x 3x
1 1
12. Using Gaussian three point formula, evaluate (i) 2
5 x 4 dx (ii) 2
5 x 4 dx .
1 0
1 2
2 xy
14. Evaluate 1 x 1 y dx dy by Trapezoidal rule with h = k = 0.25.
0 1
2 2
2 2
dx dy
15. Evaluate x
1 1
2
y2
numerically with h = 0.2 along x direction and k = 0.25 along y
direction.
3 2
16. The function f(x, y) is defined by the following table. Compute f x, y dx dy using
1 0
x 0 0.5 1 1.5 2
56