`Numerical iNtegratioN
Department Of Mathematics
Research Project
By
aNKit
(Roll-No:210087302014)
Under The Supervision
Dr. DileeP Kumar
goverNmeNt Post graDuate college, NoiDa
(chauDhary charaN siNgh uNiversity)
June, 2024
> INTRODUCTION
The term “numerical integration” first appears in 1915 in the publication. A course in
interpolation and Numeric Integration for the Mathematical Laboratory by David Gibb.
The beginnings of numerical integration have its roots in antiquity. A prime example of how
ancient these methods are, is the Greek quadrature of the circle by means of inscribed and
circumscribed regular polygons. This process led Archimedes to an upper bound and lower
bound for the value Pi. These methods were used widely due to the lack of formal calculus.
The method of the sum of an infinitesimal area over a finite range was unknown until the
sixteenth century when Newton formalized the concepts of what we know now know as
calculus. The earliest forms of numerical integration are similar to that of the Greek method
of inscribing regular polygons into curved functions. This process broken down was taking a
known area and overlapping it with an unknown area to approximate the area of the unknown
shape. One could improve accuracy by choosing a better fitting shape. Later methods decided
to improve upon estimation area under a curve decided to use more polygons but smaller in
area. Such as example is the use of rectangles evenly spaced under a curve to estimate the
area. Even further improvements saw the use of trapezoids instead of rectangles to better fit
the curvature of the function being analyzed. Today the best methods for numerical integration
are known as quadrature methods that have a very small error.
The process of evaluating a definite integral from a set of tabulated values of the integrand
f(x) is called numerical integration. This process when applied to a function of a single
variable, is known as quadrature.
The problem of numerical integration, like that ot numerical differentiation, is solved by
representing f(x) by an interpolation formula and then integrating it between the given limits.
In this way, we can derive quadrature formulae for approximate integration of a function
defined by a set of numerical values only.
The problem of numerical integration is started below:
Given a set of data points (𝑥0, 𝑦0), (𝑥1𝑦1), ………. , (𝑥𝑛, 𝑦𝑛) of a function y = 𝒇(𝒙), it is
required to find the value of the definite integral ∫ 𝒇(𝒙)𝒅𝒙
𝒃
𝒂
. The function 𝑓(𝑥) is replaced
By a suitable interpolating polynomial ∅(𝑥).
Then the approximate value of the definite integral is calculated using the following formula.
∫ 𝒇(𝒙)𝒅𝒙 ≅ ∫ ∅(𝒙)𝒅𝒙
𝒃
𝒂
𝒃
𝒂
Thus, different integration formulae can be derived depending on the type of the
interpolation formulae used.
A numerical integration formula is said to be of closed type, if the limits of integration
a and b are taken as interpolating points. If a and b are not taken as interpolating
points then the formula is known as open type formula.
General Quadrature Formula Based On Newton’s Forward
Interpolation.
The Newton’s forward interpolation formula for the equispaced points 𝑥𝑖, 𝑖= 0,1, . . . . . . , n,
𝑥𝑖 = 𝑥0 + 𝑖ℎ is
∅(𝑥) = 𝑦0 + 𝑢∆ 𝑦0 +
𝑢(𝑢−1)
2!
∆2
𝑦0 +
𝑢(𝑢−1)(𝑢−2)
3!
∆3
𝑦0 + . . . . . ,
Where 𝑢 =
𝑥−𝑥0
ℎ
, ℎ is the spacing.
Let the interval [𝑎 , 𝑏] be divided into 𝑛 equal subintervals such that 𝑎 = 𝑥0 <
𝑥1 < 𝑥2 < . . . . . . < 𝑥𝑛 = 𝑏. Then,
𝐼 = ∫ 𝑓(𝑥)𝑑𝑥 ≅ ∫ ∅(𝑥)𝑑𝑥
𝑥𝑛
𝑥0
𝑏
𝑎
= ∫ [𝑦0 + 𝑢∆ 𝑦0 +
𝑢(𝑢−1)
2!
∆2
𝑦0 +
𝑢(𝑢−1)(𝑢−2)
3!
∆3
𝑦0+ . . . . . ] 𝑑𝑥
𝑥𝑛
𝑥0
.
Since 𝑥 = 𝑥0 + 𝑢ℎ, 𝑑𝑥 = ℎ𝑑𝑢, when 𝑥 = 𝑥0 𝑡ℎ𝑒𝑛 𝑢 = 0 and when 𝑥 = 𝑥𝑛 then 𝑢 = 𝑛.
Thus,
𝐼 = ∫ [𝑦0
+ 𝑢∆ 𝑦0
+
𝑢2−𝑢
2!
∆2
𝑦0
+
𝑢3−3𝑢2+2𝑢
3!
∆3
𝑦0
+ .....] ℎ𝑑𝑢
𝑛
0
= ℎ[𝑦0[𝑢]0
𝑛
+
∆2 𝑦0
2!
[
𝑢3
3
−
𝑢2
2
]
0
𝑛
+
∆3 𝑦0
3!
[
𝑢4
4
− 𝑢3
+ 𝑢2
]
0
𝑛
+ ⋯ ]
= 𝑛ℎ[
𝑛
2
∆𝑦0 +
2𝑛2−3𝑛
12
∆2
𝑦0 +
𝑛3−4𝑛2+4𝑛
24
∆3
𝑦0 + ⋯ ] . . . . . ( 1 )
From this formula, one can generate different integration formulae by substituting
n = 1,2,3, . . . .
1. Trapezoidal Rule
Substituting n = 1 in equation ( 1). In this case all differences higher than the first difference
become zero. Then,
∫ 𝑓(𝑥)𝑑𝑥 = ℎ [ 𝑦0 +
1
2
∆𝑦0] = ℎ [𝑦0 +
1
2
(𝑦1 − 𝑦0)] =
ℎ
2
𝑥𝑛
𝑥0
(𝑦0 + 𝑦1) . . . (2)
The formula is known as the trapezoidal rule.
In this formula, the interval [𝑎, 𝑏] is considered as a single interval, and it gives a very rough
answer. But, if the interval [𝑎, 𝑏] is divided into several subintervals and this formula is
applied to each of these subintervals then a better approximate result may be obtained.
Error in trapezoidal rule
The error of trapezoidal rule is
𝐸 = ∫ 𝑓(𝑥)𝑑𝑥 −
𝑏
𝑎
ℎ
2
(𝑦0 + 𝑦1) . . .( 3 )
Let 𝑦 = 𝑓(𝑥) be continuous and processes continuous derivates of all orders. Also,
It is assumed that there exists a function 𝐹(𝑥) such that 𝐹′(𝑥) = 𝑓(𝑥) 𝑖𝑛 [𝑥0, 𝑥1]
Then,
∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝐹′(𝑥)𝑑𝑥 = 𝐹(𝑥1) − 𝐹(𝑥0)
𝑥1
𝑥0
𝑏
𝑎
= 𝐹(𝑥0 + ℎ) − 𝐹(𝑥0) = 𝐹(𝑥0) + ℎ𝐹′(𝑥0)
+
ℎ2
2!
𝐹′′(𝑥0) +
ℎ3
3!
𝐹′′′(𝑥0) + ⋯ 𝐹(𝑥0)
= ℎ𝑓(𝑥0) +
ℎ2
2!
𝑓′(𝑥0) +
ℎ3
3!
𝑓′′(𝑥0) + ⋯
= ℎ𝑦0 +
ℎ2
2!
𝑦′0 +
ℎ3
6!
𝑦′′0 + ⋯ . . . ( 4 )
Again,
ℎ
2
(𝑦0 + 𝑦1) =
ℎ
2
[𝑦0 + 𝑦(𝑥0 + ℎ)]
=
ℎ
2
[𝑦0 + 𝑦(𝑦0) + ℎ𝑦′(𝑥0 ) +
ℎ2
2!
𝑦′′(𝑥0 ) + ⋯ ]
=
ℎ
2
[𝑦0 + 𝑦0 + ℎ𝑦′
0
+
ℎ2
2!
𝑦′′
0
+ ⋯ ] . . .( 5 )
Using (4) and (5), equation (3) becomes,
𝐸 =
ℎ
2
[𝑦0 +
ℎ2
2!
𝑦′
0
+
ℎ2
6!
𝑦′′
0
+ ⋯ ] −
ℎ
2
[2𝑦0 + ℎ𝑦′
0
+
ℎ2
2!
𝑦′′
0
+ ⋯ ]
= −
ℎ3
12!
𝑦′′
0
+ ⋯
= −
ℎ3
12!
𝑓′′(𝑥0) + ⋯ ≅ −
ℎ3
12!
𝑓′′(𝜉), ⋯ (𝟔)
Where 𝑎 = 𝑥0 < 𝜉 < 𝑥1 = 𝑏.
Equation (6) gives the error in the interval [𝑥0,𝑥1].
The total error in the composite rule is
𝐸 = −
ℎ3
12
( 𝑦′′
0
+ 𝑦′′
1
+ ⋯ + 𝑦𝑛−1
𝑛
)
If 𝑦′′(𝜉) is the largest among the n quantities 𝑦′′
0
, 𝑦′′
1
, ⋯ , 𝑦𝑛−1
𝑛
then
𝐸 ≤ −
1
12
ℎ3
𝑛𝑦′′(𝜉) = −
(𝑏−𝑎)
12
ℎ2
𝑛𝑦′′(𝜉), as 𝑛ℎ = 𝑏 − 𝑎
Note:
Trapezoidal rule: The error term shows that if the second and higher order derivatives of
𝑓(𝑥) vanish then the trapezoidal rule gives exact result of the integral. This means, the
method gives exact result when 𝑓(𝑥) is linear.
Geometrical Interpretation Of Trapezoidal Rule
In this rule, the curve 𝑦 = 𝑓(𝑥) is replaced by the line joining the points 𝐴(𝑥0 + 𝑦0) and
𝐵(𝑥1 + 𝑦1) Figure(a). Thus the area bounded by the curve 𝑦 = 𝑓(𝑥), the ordinates
𝑥 = 𝑥0, 𝑥 = 𝑥1 and the x axis is then approximately equivalent to the area of the trapezium
(ABCD) bounded by the line AB, 𝑥 = 𝑥0, 𝑥 = 𝑥1 and x axis.
Figure(a): Geometrical Interpretation Of Trapezoidal Rule
Implementation Of Trapezoidal Rule Via Coding :
To The Implement Integral We Used Walfram Mathematica Software.
Questions :- Implement the following integrals using the Trapezoidal Rule
(i) ∫ 1/𝑥𝑑𝑥
3
2
(ii)∫
𝑑𝑥
1+𝑥2
1
0
(iii)∫ 𝑐𝑜𝑠2
𝑥𝑑𝑥
0.25
−0.25
Solution 1.
f[x_] = 1/x;
a = 2;
b = 3;
exactIn1 = Integrate[f[x],{x, a, b}];
approxiIn1 = (b-a) * ((f[a] + f[b] )/2);
error1 = Abs(exactIn1 - apporxiIn1);
print["Exact value of integration is: ", N[exactIn1]]
print["Integration using Trapezoidal rule is: ", N[approxiIn1]]
print["Error in the approximation is: ", N[error1]]
Output:-
print[ Exact value of integration is: , 0.405465 ]
print [ Integration using Trapezoidal Rule is: , 0.416667 ]
print [ Error in the Approximation is: , -0.0112016 Abs ]
Solution 2.
f[x_] = 1/(1+x^2);
a = 0;
b = 1;
exactIn1 = Integrate[f[x],{x, a, b}];
approxiIn1 = (b-a) * ((f[a] + f[b] )/2);
error1 = Abs(exactIn1 - apporxiIn1);
print["Exact value of integration is: ", N[exactIn1]]
print["Integration using Trapezoidal rule is: ", N[approxiIn1]]
print["Error in the approximation is: ", N[error1]]
output:-
print[ Exact value of integration is: , 0.785396 ]
print [ Integration using Trapezoidal Rule is: , 0.75]
print [ Error in the Approximation is: , Abs( 0. 785396 -1. approxiIn1 ) ]
Solution 3.
f[x_] = Cos[x]^2;
a = -0.25;
b = 0.25;
exactIn1 = Integrate[f[x],{x, a, b}];
approxiIn1 = (b-a) * ((f[a] + f[b] )/2);
error1 = Abs(exactIn1 - apporxiIn1);
print["Exact value of integration is: ", N[exactIn1]]
print["Integration using Trapezoidal rule is: ", N[approxiIn1]]
print["Error in the approximation is: ", N[error1]]
output:-
print[ Exact value of integration is: , 0.489713 ]
print [ Integration using Trapezoidal Rule is: , 0.469396]
print [ Error in the Approximation is: , 0. 0203171 Abs ]
1.1. Composite Trapezoidal Rule
Let the interval [𝑎, 𝑏] be divided into n equal subintervals by the points 𝑎 =
𝑥0, 𝑥1, 𝑥2, ⋯ , 𝑥𝑛 = 𝑏, where 𝑥𝑖 = 𝑥0 + 𝑖ℎ, 𝑖 = 1, 2, 3, ⋯ , 𝑛.
Applying the trapezoidal rule to each of the subintervals, one can find the
composite formula as,
∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝑓′(𝑥)𝑑𝑥 +
𝑥1
𝑥0
𝑏
𝑎
∫ 𝑓(𝑥)𝑑𝑥 + ⋯ + ∫ 𝑓(𝑥)𝑑𝑥
𝑥𝑛
𝑥𝑛−1
𝑥2
𝑥1
≅
ℎ
2
[𝑦0 + 𝑦1] +
ℎ
2
[𝑦1 + 𝑦2] +
ℎ
2
[𝑦2 + 𝑦3] + ⋯ +
ℎ
2
[𝑦𝑛−1 + 𝑦𝑛]
=
ℎ
2
[𝑦0 + 2( 𝑦1 + 𝑦2 + 𝑦3 + ⋯ + 𝑦𝑛−1) + 𝑦𝑛] . . . (7)
The above equation no 7 is called Composite Trapezoidal Rule
Error for Composite Trapezoidal Rule:
𝐸 ≤ −
1
12
ℎ3
𝑛𝑦′′(𝜉) = −
(𝑏−𝑎)
12
ℎ2
𝑛𝑦′′(𝜉), as 𝑛ℎ = 𝑏 − 𝑎
Geometrical Interpretation Of Composite Trapezoidal Rule:
The geometrical significance of composite trapezoidal rule is that the curve 𝑦 = 𝑓(𝑥) is
replaced by n straight lines joining the points (𝑥0, 𝑦0) and (𝑥1, 𝑦1) ; (𝑥1, 𝑦1) 𝑎𝑛𝑑 (𝑥2, 𝑦2);
⋯ , (𝑥𝑛−1, 𝑦𝑛−1) and (𝑥𝑛, 𝑦𝑛). Then the area bounded by the curve 𝑦 = 𝑓(𝑥), the lines 𝑥 =
𝑥0, , 𝑥 = 𝑥𝑛 and the x-axis is then approximately equivalent to the sum of the area of n
trapeziums (Figure b).
Implementation Of Composite Trapezoidal Rule Via Coding
Questions :- Implement the following integrals using the Composite
Trapezoidal Rule the indicated values of n.
(i)∫ 𝑥𝑙𝑜𝑔(𝑥 + 1)𝑑𝑥
0
−0.5
(ii) ∫ 𝑐𝑜𝑠2
𝑥𝑑𝑥
0.25
−0.25
, n=4
Solution 1.
ClearAll[a, b, exactIn, approxiIn, error, f, x, t, n, m]
n = 4;
f[t_] = 𝑥𝑙𝑜𝑔(𝑥 + 1)𝑑𝑥;
a = -0.5;
b = 0;
h = (b - a) / n;
x = Range[a, b, h];
m = Length[x];
exactIn = ∫ 𝑓[𝑡]𝑑𝑡
𝑏
𝑎
approxiIn = (ℎ
2
⁄ ) ∗ ( 𝑓[𝑥[𝑖]] + 𝑓[𝑥[𝑚]] + 2 ∗ ∑ 𝑓[𝑥[𝑖]]
𝑚−1
𝑖=2 )
error = Abs[exactIn - approxiIn]
Print["Exact value of integral is : ", N[exactIn]]
Print["Approximate value of integral using trapezoidal rule is : ", N[approxiIn]]
Print["Error in the approximation is ", N[error]]
Output:
Exact value of integral is : 0.0525698
Approximate value of integral using trapezoidal rule is : 0.0535485
Error in the approximation is 0.000978701
Solution 2.
ClearAll[a, b, exactIn, approxiIn, error, f, x, t, n, m]
n = 4;
f[t_] = Cos[t]^2;
a = -0.25;
b = 0.25;
h = (b - a) / n;
x = Range[a, b, h];
m = Length[x];
exactIn = ∫ 𝑓[𝑡]𝑑𝑡
𝑏
𝑎
approxiIn = (ℎ
2
⁄ ) ∗ ( 𝑓[𝑥[𝑖]] + 𝑓[𝑥[𝑚]] + 2 ∗ ∑ 𝑓[𝑥[𝑖]]
𝑚−1
𝑖=2 )
error = Abs[exactIn - approxiIn]
Print["Exact value of integral is : ", N[exactIn]]
Print["Approximate value of integral using trapezoidal rule is : ", N[approxiIn]]
Print["Error in the approximation is ", N[error]]
Output:
Exact value of integral is : 0.489713
Approximate value of integral using trapezoidal rule is : 0.488463
Error in the approximation is 0.00124981
2. Simpson rule:
In this formula the interval [𝑎, 𝑏] is divided into two equal subintervals by the points
𝑥0, 𝑥1, 𝑥2, where ℎ =
𝑏−𝑎
2
, 𝑥1 = 𝑥0 + ℎ 𝑎𝑛𝑑 𝑥2 = 𝑥1 + ℎ.
This rule is obtained by putting n =2 in (1). In this case, the third and higher order
differences do not exist.
The equation (1) is simplified as,
∫ 𝑓(𝑥)𝑑𝑥 ≅ 2ℎ [ 𝑦0 + ∆𝑦0 +
1
6
∆2
𝑦0]
𝑥𝑛
𝑥0
= 2ℎ [ 𝑦0 + (𝑦1 − 𝑦0) +
1
6
(𝑦2 − 2𝑦1 + 𝑦0)]
=
ℎ
3
[𝑦0 + 4𝑦1 + 𝑦2] . . . . . (8)
The above rule is known as Simpson rule.
Error in Simpson rule
The error in this formula is
𝐸 = ∫ 𝑓(𝑥)𝑑𝑥 −
𝑥𝑛
𝑥0
ℎ
3
(𝑦0 + 4𝑦1 + 𝑦2)
Let the function f(x) be continuous in [𝑥0, 𝑥2] and possesses continuous derivatives of all
order. Also, let there exists a function F(x) in [𝑥0, 𝑥2], such that F’(x) = f(x).
Then,
∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝐹′(𝑥)𝑑𝑥 = 𝐹(𝑥2) − 𝐹(𝑥0)
𝑥2
𝑥0
𝑥2
𝑥0
= 𝐹(𝑥0 + 2ℎ) − 𝐹(𝑥0)
= 𝐹(𝑥0) + 2𝐹′(𝑥0) +
(2ℎ)2
2!
𝐹′′(𝑥0) +
(2ℎ)3
3!
𝐹′′′(𝑥0) +
(2ℎ)4
4!
𝐹𝑖𝑣(𝑥0) +
(2ℎ)5
5!
𝐹𝑣(𝑥0) + ⋯ − 𝐹(𝑥0)
= 2ℎ𝑓(𝑥0) + 2ℎ𝑓′(𝑥0) +
4
3
ℎ3
𝑓′′(𝑥0) +
2
3
ℎ3
𝑓′′′(𝑥0) +
4
15
ℎ3
𝑓𝑖𝑣(𝑥0) + ⋯ . . . . . . . . (9)
Again,
=
ℎ
3
[𝑦0 + 4𝑦1 + 𝑦2] =
ℎ
3
[𝑓(𝑥0) + 4𝑓(𝑥0 + ℎ) + 𝑓(𝑥0 + 2ℎ)]
=
ℎ
3
[ 𝑓(𝑥0) + 4 { 𝑓(𝑥0) + ℎ𝑓′(𝑥0) +
ℎ2
2!
𝑓′′(𝑥0) +
ℎ3
3!
𝑓′′′(𝑥0) +
ℎ4
4!
𝑓𝑖𝑣(𝑥0) + ⋯ } + { 𝑓(𝑥0) + 2ℎ𝑓′(𝑥0) +
(2ℎ)2
2!
𝑓′′(𝑥0) +
(2ℎ)3
3!
𝑓′′′(𝑥0) +
(2ℎ)4
4!
𝑓𝑖𝑣(𝑥0) + ⋯ } ]
= 2ℎ𝑓(𝑥0) + 2ℎ2
𝑓′(𝑥0) +
4
3
ℎ3
𝑓′′(𝑥0) +
2
3
ℎ4
𝑓′′′(𝑥0) +
5
4
ℎ5
𝑓𝑖𝑣(𝑥0) +
⋯ . . . . . .. (10)
Using eq (9) and (10),equation (8) becomes,
𝐸 = (
4
15
−
5
18
) ℎ5
𝑓𝑖𝑣(𝑥0) + ⋯ ≅ −
ℎ5
90
𝑓𝑖𝑣(𝜉), ⋯ (𝟏𝟏)
Where 𝑥0 < 𝜉 < 𝑥2
This is the error in the interval [𝑥0, 𝑥2]
The total error in composite formula is
𝐸 = −
ℎ5
90
{𝑓𝑖𝑣(𝑥0) + 𝑓𝑖𝑣(𝑥2) + ⋯ + 𝑓𝑖𝑣(𝑥𝑛−2)}
= −
ℎ5
90
𝑛
2
𝑓𝑖𝑣(𝜉)
= −
𝑛ℎ5
180
𝑓𝑖𝑣(𝜉),
( 𝑤ℎ𝑒𝑟𝑒 𝑓𝑖𝑣(𝜉) 𝑖𝑠 𝑡ℎ𝑒 𝑚𝑎𝑥𝑖𝑚𝑢𝑚 𝑎𝑚𝑜𝑛𝑔 𝑓𝑖𝑣(𝑥0),
𝑓𝑖𝑣(𝑥2), ⋯ , 𝑓𝑖𝑣(𝑥𝑛−2))
= −
(𝑏−𝑎)
180
ℎ4
𝑓𝑖𝑣(𝜉), . . . . . . . . (12)
Geometrical interpretation of Simpson rule:
In Simpson’s 1/3 rule, the curve y = f(x) is replaced by the second degree parabola passing
through the points 𝐴(𝑥0, 𝑦0), 𝐵(𝑥1, 𝑦1) 𝑎𝑛𝑑 𝐶(𝑥2, 𝑦2). Therefore, the area bounded by the
curve 𝑦 = 𝑓(𝑥), the ordinates 𝑥 = 𝑥0, 𝑥 = 𝑥2 𝑎𝑛𝑑 𝑥 − 𝑎𝑥𝑖𝑠, 𝑖. 𝑒, the area of the shaded
region ABCDEA.
Implementation of Simpson rule via Coding:
Questions :- Implement the following integrals using the Simpson’s 1/3 Rule
(i) ∫ 1/𝑥𝑑𝑥
3
2
(ii) ∫
𝑑𝑥
1+𝑥2
1
0
(iii)∫ 𝑐𝑜𝑠2
𝑥𝑑𝑥
0.25
−0.25
Solution 1.
f[x_] = 1/x;
a = 2;
b = 3;
h = (b-a)/2
exactIn1 = Integrate[f[x],{x, a, b}];
approxiIn1 = (h/3) * ( [f[a] + 4*f[(a = b) / 2] + f[b]);
error1 = Abs(exactIn1 - apporxiIn1);
print["Exact value of integration is: ", N[exactIn1]]
print["Integration using Trapezoidal rule is: ", N[approxiIn1]]
print["Error in the approximation is: ", N[error1]]
Output:-
print[ Exact value of integration is: , 0.405465 ]
print [ Integration using Trapezoidal Rule is: , 0.583333 ]
print [ Error in the Approximation is: , -0.177868 Abs ]
Solution 2.
f[x_] = 1/(1+x^2);
a = 0;
b = 1;
h = (b-a)/2
exactIn1 = Integrate[f[x],{x, a, b}];
approxiIn1 = (h/3) * ( [f[a] + 4*f[(a = b) / 2] + f[b]);
error1 = Abs(exactIn1 - apporxiIn1);
print["Exact value of integration is: ", N[exactIn1]]
print["Integration using Trapezoidal rule is: ", N[approxiIn1]]
print["Error in the approximation is: ", N[error1]]
Output:-
print[ Exact value of integration is: , 0.785396 ]
print [ Integration using Trapezoidal Rule is: , 0.783333]
print [ Error in the Approximation is: , 0.00206483Abs ]
Solution 3.
f[x_] = Cos[x]^2;
a = -0.25;
b = 0.25;
h = (b-a)/2
exactIn1 = Integrate[f[x],{x, a, b}];
approxiIn1 = (h/3) * ( [f[a] + 4*f[(a = b) / 2] + f[b]);
error1 = Abs(exactIn1 - apporxiIn1);
print["Exact value of integration is: ", N[exactIn1]]
print["Integration using Trapezoidal rule is: ", N[approxiIn1]]
print["Error in the approximation is: ", N[error1]]
Output:-
print[ Exact value of integration is: , 0.489713 ]
print [ Integration using Trapezoidal Rule is: , 0.484617]
print [ Error in the Approximation is: , 0. 00509549 Abs ]
Simpson Composite rule
Let the interval [𝑎, 𝑏] be divided into n (an even number ) equal subintervals by the points
𝑥0, 𝑥1, 𝑥2, ⋯ , 𝑥𝑛, where 𝑥𝑖 = 𝑥0 + 𝑖ℎ, 𝑖 = 1, 2, ⋯ , 𝑛. Then,
∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝑓(𝑥)𝑑𝑥 +
𝑥1
𝑥0
∫ 𝑓(𝑥)𝑑𝑥 + ⋯ + ∫ 𝑓(𝑥)𝑑𝑥
𝑥𝑛
𝑥𝑛−2
𝑥4
𝑥2
𝑏
𝑎
=
ℎ
3
[𝑦0 + 4𝑦1 + 𝑦2] +
ℎ
3
[𝑦2 + 4𝑦3 + 𝑦4] + ⋯ +
ℎ
3
[𝑦𝑛−2 + 4𝑦𝑛−1 + 𝑦𝑛]
=
ℎ
3
[𝑦0 + 4(𝑦1 + 𝑦3 + ⋯ + 𝑦𝑛−1 ) + 2(𝑦2 + 𝑦4 +
⋯ + 𝑦𝑛−2 ) + 𝑦𝑛 ] . . . . . . . (13)
This formula is known as Simpson composite rule for numerical integration.
Error in Simpson Composite rule
𝑬 = −
(𝑏−𝑎)
180
ℎ4
𝑓𝑖𝑣
(𝜉)
Geometrical interpretation of Simpson Composite rule:
Putting 𝑛 = 2 in (1) above and taking the curve through (𝑥0, 𝑦0), (𝑥1, 𝑦1) 𝑎𝑛𝑑 (𝑥2, 𝑦2) as a
parabola (Figure C), i.e., a polynomial of the second order so that differences of order higher
than the second vanish, we get
(figure C)
Implementation of Simpson Composite rule via Coding
Questions :- Implement the following integrals using the Simpson’s 1/3
Composite Rule the indicated values of n.
(i)∫ 𝑥𝑙𝑜𝑔(𝑥 + 1)𝑑𝑥
0
−0.5
(ii) ∫ 𝑐𝑜𝑠2
𝑥𝑑𝑥
0.25
−0.25
, n=4
Solution 1.
ClearAll[a, b, exactIn, approxiIn, error, f, x, t, n, m, h]
n = 6;
f[t_] = 𝑡 ∗ 𝐿𝑜𝑔[𝑡 + 1];
a = -0.5;
b = 0;
h = (b - a) / (2*n);
x = Range[a, b, h];
m = Length[x];
exactIn = ∫ 𝑓[𝑡]𝑑𝑡
𝑏
𝑎
approxiIn = (ℎ
3
⁄ ) ∗ ( 𝑓[𝑥[𝑖]] + 4 ∗ ∑ 𝑓[𝑥[2 ∗ 𝑖]]
(𝑚−1)/2
𝑖=1 + 2 ∗ ∑ 𝑓[𝑥[2 ∗
(𝑚−1)/2
𝑖=2
𝑖 − 1]] + 𝑓[𝑥[𝑚]]);
error = Abs[exactIn - approxiIn]
Print["Exact value of integral is : ", N[exactIn]]
Print["Approximate value of integral using Simpson’s rule is : ", N[approxiIn]]
Print["Error in the approximation is ", N[error]]
Output:-
print[ Exact value of integral is: , 0.0525698 ]
print [ Integration using Trapezoidal Rule is: , 0.343574 ]
print [ Error in the Approximation is: , 0.294004 ]
Solution 2.
ClearAll[a, b, exactIn, approxiIn, error, f, x, t, n, m, h]
n = 4;
f[t_] = Cos[t]^2;
a = -0.25;
b = 0.25;
h = (b - a) / (2*n);
x = Range[a, b, h];
m = Length[x];
exactIn = ∫ 𝑓[𝑡]𝑑𝑡
𝑏
𝑎
approxiIn = (ℎ
3
⁄ ) ∗ ( 𝑓[𝑥[𝑖]] + 4 ∗ ∑ 𝑓[𝑥[2 ∗ 𝑖]]
(𝑚−1)/2
𝑖=1 + 2 ∗ ∑ 𝑓[𝑥[2 ∗
(𝑚−1)/2
𝑖=2
𝑖 − 1]] + 𝑓[𝑥[𝑚]] );
error = Abs[exactIn - approxiIn]
Print["Exact value of integral is : ", N[exactIn]]
Print["Approximate value of integral using Simpson’s rule is : ", N[approxiIn]]
Print["Error in the approximation is ", N[error]]
Output:-
print[ Exact value of integral is: , 0.489713 ]
print [ Integration using Trapezoidal Rule is: , 0.625861 ]
print [ Error in the Approximation is: , 0.136148 ]
Reasons For Numerical Integration:
There are several reasons for carrying out numerical integration.
1. The integrand f(x) may be known only at certain points, such as obtained by
sampling. Some embedded system and other computer applications may need
numerical integration for this reason.
2. A formula for the integrand may be known, but it may be difficult or impossible
to find an antiderivative that is an elementary function. An example of such an
integrand is f(x) = exp (−x2), the antiderivative of which (the error function, times
a constant) cannot be written in elementary form.
3. It may be possible to find an antiderivative symbolically, but it may be easier to
compute a numerical approximation than to compute the antiderivative. That
may be the case if the antiderivative is given as an infinite series or product, or
if its evaluation requires a special function that is not available.
Application Of Integration:
It Helps To:
➢ Locate the centroid.
➢ Find the arc length of graph
➢ Find the surface area of solid
➢ Find the volume of a solid figure
➢ Solve for the work done
➢ Solve the moment of inertia
➢ Find the area
It is also used to find:
➢ Water plane area
➢ Sectional area
➢ Submerged volume
Pros:
➢ Possible to integrate any function
➢ Multidimensional integrals are straightforward
➢ Ability to solve integrals along irregular domains in multidimensional spaces
(any shape).
➢ Numerical integration gives you an answer to some problems that analytic
techniques don’t.
Cons:
➢ There is an intrinsic error in calculation
➢ Numerical integrals are, always, computationally expensive.
Summary And References:
In numerical analysis, Numerical Integration constitutes a broad family of algorithms
for calculating the numerical value of a definite integral, and by extension, the term is
also sometimes used to describe the numerical solution of differential equations. This
article focuses on calculation of definite integrals. The term numerical quadrature
(often abbreviated to quadrature) is more or less a synonym for numerical integration,
especially as applied to one-dimensional integrals. Integration has been there since
even before the proper use of calculus. In modern day integration has led to some great
creations including the Petronas towers and the Sydney opera house.

More Related Content

PPTX
NUMERICAL INTEGRATION : ERROR FORMULA, GAUSSIAN QUADRATURE FORMULA
PDF
Applied numerical methods lec10
PDF
Error analysis in numerical integration
PPT
MATLAB : Numerical Differention and Integration
PPT
1519 differentiation-integration-02
PPTX
Newton cotes integration method
PDF
Overviewing the techniques of Numerical Integration.pdf
PDF
Numerical integration
NUMERICAL INTEGRATION : ERROR FORMULA, GAUSSIAN QUADRATURE FORMULA
Applied numerical methods lec10
Error analysis in numerical integration
MATLAB : Numerical Differention and Integration
1519 differentiation-integration-02
Newton cotes integration method
Overviewing the techniques of Numerical Integration.pdf
Numerical integration

Similar to Ankit_Practical_File-1.pdf A detailed overview of Rizir as a brand (20)

PPTX
NUMERICAL METHOD'S
PPTX
Trapezoidal Rule
PPT
25285 mws gen_int_ppt_trapcontinuous
PDF
A NEW STUDY OF TRAPEZOIDAL, SIMPSON’S1/3 AND SIMPSON’S 3/8 RULES OF NUMERICAL...
PDF
A NEW STUDY OF TRAPEZOIDAL, SIMPSON’S1/3 AND SIMPSON’S 3/8 RULES OF NUMERICAL...
PDF
A NEW STUDY OF TRAPEZOIDAL, SIMPSON’S1/3 AND SIMPSON’S 3/8 RULES OF NUMERICAL...
PDF
Numerical Integration: Trapezoidal Rule
DOCX
Trapezoidal Method IN Numerical Analysis
PDF
IRJET- Parallelization of Definite Integration
PDF
Quadrature
PDF
Efficient Accuracy: A Study on Numerical Integration.
PPT
Calc 4.6
PPTX
Numerical Computation
PPTX
The Trapezoidal rule is the first of the Newton-Cotes closed integration form...
PPTX
Presentation on Numerical Method (Trapezoidal Method)
PPT
Numerical differentiation integration
PPT
Chapter 3
PDF
Numerical Method for UOG mech stu prd by Abdrehman Ahmed
PPT
23MA401 NM Numerical integration anddifferenciation
DOCX
Numerical Analysis and Computer Applications
NUMERICAL METHOD'S
Trapezoidal Rule
25285 mws gen_int_ppt_trapcontinuous
A NEW STUDY OF TRAPEZOIDAL, SIMPSON’S1/3 AND SIMPSON’S 3/8 RULES OF NUMERICAL...
A NEW STUDY OF TRAPEZOIDAL, SIMPSON’S1/3 AND SIMPSON’S 3/8 RULES OF NUMERICAL...
A NEW STUDY OF TRAPEZOIDAL, SIMPSON’S1/3 AND SIMPSON’S 3/8 RULES OF NUMERICAL...
Numerical Integration: Trapezoidal Rule
Trapezoidal Method IN Numerical Analysis
IRJET- Parallelization of Definite Integration
Quadrature
Efficient Accuracy: A Study on Numerical Integration.
Calc 4.6
Numerical Computation
The Trapezoidal rule is the first of the Newton-Cotes closed integration form...
Presentation on Numerical Method (Trapezoidal Method)
Numerical differentiation integration
Chapter 3
Numerical Method for UOG mech stu prd by Abdrehman Ahmed
23MA401 NM Numerical integration anddifferenciation
Numerical Analysis and Computer Applications
Ad

Recently uploaded (20)

PPTX
Accounting Management SystemBatch-4.pptx
PDF
Investment in CUBA. Basic information for United States businessmen (1957)
PDF
From Legacy to Velocity: how we rebuilt everything in 8 months.
PPTX
Week2: Market and Marketing Aspect of Feasibility Study.pptx
PPTX
IndustrialAIGuerillaInnovatorsARCPodcastEp3.pptx
PDF
The Impact of Immigration on National Identity (www.kiu.ac.ug)
PPTX
IMM.pptx marketing communication givguhfh thfyu
PDF
the role of manager in strategic alliances
PDF
Chembond Chemicals Limited Presentation 2025
PPTX
Oracle Cloud Infrastructure Overview July 2020 v2_EN20200717.pptx
PDF
Challenges of Managing International Schools (www.kiu. ac.ug)
DOCX
Handbook of entrepreneurship- Chapter 7- Types of business organisations
PDF
How to run a consulting project from scratch
PPT
BCG内部幻灯片撰写. slide template BCG.slide template
PDF
Diversity and Inclusion Initiatives in Corporate Settings (www.kiu.ac.ug)
PDF
109422672-Doc-8973-05-Security-Manual-Seventh-Edition.pdf
DOCX
Center Enamel Can Provide Pressure Vessels for Maldives Chemical Industry.docx
PDF
dataZense for Data Analytics unleashed features
PPT
Retail Management and Retail Markets and Concepts
PDF
Cross-Cultural Leadership Practices in Education (www.kiu.ac.ug)
Accounting Management SystemBatch-4.pptx
Investment in CUBA. Basic information for United States businessmen (1957)
From Legacy to Velocity: how we rebuilt everything in 8 months.
Week2: Market and Marketing Aspect of Feasibility Study.pptx
IndustrialAIGuerillaInnovatorsARCPodcastEp3.pptx
The Impact of Immigration on National Identity (www.kiu.ac.ug)
IMM.pptx marketing communication givguhfh thfyu
the role of manager in strategic alliances
Chembond Chemicals Limited Presentation 2025
Oracle Cloud Infrastructure Overview July 2020 v2_EN20200717.pptx
Challenges of Managing International Schools (www.kiu. ac.ug)
Handbook of entrepreneurship- Chapter 7- Types of business organisations
How to run a consulting project from scratch
BCG内部幻灯片撰写. slide template BCG.slide template
Diversity and Inclusion Initiatives in Corporate Settings (www.kiu.ac.ug)
109422672-Doc-8973-05-Security-Manual-Seventh-Edition.pdf
Center Enamel Can Provide Pressure Vessels for Maldives Chemical Industry.docx
dataZense for Data Analytics unleashed features
Retail Management and Retail Markets and Concepts
Cross-Cultural Leadership Practices in Education (www.kiu.ac.ug)
Ad

Ankit_Practical_File-1.pdf A detailed overview of Rizir as a brand

  • 1. `Numerical iNtegratioN Department Of Mathematics Research Project By aNKit (Roll-No:210087302014) Under The Supervision Dr. DileeP Kumar goverNmeNt Post graDuate college, NoiDa (chauDhary charaN siNgh uNiversity) June, 2024
  • 2. > INTRODUCTION The term “numerical integration” first appears in 1915 in the publication. A course in interpolation and Numeric Integration for the Mathematical Laboratory by David Gibb. The beginnings of numerical integration have its roots in antiquity. A prime example of how ancient these methods are, is the Greek quadrature of the circle by means of inscribed and circumscribed regular polygons. This process led Archimedes to an upper bound and lower bound for the value Pi. These methods were used widely due to the lack of formal calculus. The method of the sum of an infinitesimal area over a finite range was unknown until the sixteenth century when Newton formalized the concepts of what we know now know as calculus. The earliest forms of numerical integration are similar to that of the Greek method of inscribing regular polygons into curved functions. This process broken down was taking a known area and overlapping it with an unknown area to approximate the area of the unknown shape. One could improve accuracy by choosing a better fitting shape. Later methods decided to improve upon estimation area under a curve decided to use more polygons but smaller in area. Such as example is the use of rectangles evenly spaced under a curve to estimate the area. Even further improvements saw the use of trapezoids instead of rectangles to better fit the curvature of the function being analyzed. Today the best methods for numerical integration are known as quadrature methods that have a very small error. The process of evaluating a definite integral from a set of tabulated values of the integrand f(x) is called numerical integration. This process when applied to a function of a single variable, is known as quadrature. The problem of numerical integration, like that ot numerical differentiation, is solved by representing f(x) by an interpolation formula and then integrating it between the given limits. In this way, we can derive quadrature formulae for approximate integration of a function defined by a set of numerical values only. The problem of numerical integration is started below: Given a set of data points (𝑥0, 𝑦0), (𝑥1𝑦1), ………. , (𝑥𝑛, 𝑦𝑛) of a function y = 𝒇(𝒙), it is required to find the value of the definite integral ∫ 𝒇(𝒙)𝒅𝒙 𝒃 𝒂 . The function 𝑓(𝑥) is replaced By a suitable interpolating polynomial ∅(𝑥). Then the approximate value of the definite integral is calculated using the following formula. ∫ 𝒇(𝒙)𝒅𝒙 ≅ ∫ ∅(𝒙)𝒅𝒙 𝒃 𝒂 𝒃 𝒂 Thus, different integration formulae can be derived depending on the type of the interpolation formulae used. A numerical integration formula is said to be of closed type, if the limits of integration a and b are taken as interpolating points. If a and b are not taken as interpolating points then the formula is known as open type formula.
  • 3. General Quadrature Formula Based On Newton’s Forward Interpolation. The Newton’s forward interpolation formula for the equispaced points 𝑥𝑖, 𝑖= 0,1, . . . . . . , n, 𝑥𝑖 = 𝑥0 + 𝑖ℎ is ∅(𝑥) = 𝑦0 + 𝑢∆ 𝑦0 + 𝑢(𝑢−1) 2! ∆2 𝑦0 + 𝑢(𝑢−1)(𝑢−2) 3! ∆3 𝑦0 + . . . . . , Where 𝑢 = 𝑥−𝑥0 ℎ , ℎ is the spacing. Let the interval [𝑎 , 𝑏] be divided into 𝑛 equal subintervals such that 𝑎 = 𝑥0 < 𝑥1 < 𝑥2 < . . . . . . < 𝑥𝑛 = 𝑏. Then, 𝐼 = ∫ 𝑓(𝑥)𝑑𝑥 ≅ ∫ ∅(𝑥)𝑑𝑥 𝑥𝑛 𝑥0 𝑏 𝑎 = ∫ [𝑦0 + 𝑢∆ 𝑦0 + 𝑢(𝑢−1) 2! ∆2 𝑦0 + 𝑢(𝑢−1)(𝑢−2) 3! ∆3 𝑦0+ . . . . . ] 𝑑𝑥 𝑥𝑛 𝑥0 . Since 𝑥 = 𝑥0 + 𝑢ℎ, 𝑑𝑥 = ℎ𝑑𝑢, when 𝑥 = 𝑥0 𝑡ℎ𝑒𝑛 𝑢 = 0 and when 𝑥 = 𝑥𝑛 then 𝑢 = 𝑛. Thus, 𝐼 = ∫ [𝑦0 + 𝑢∆ 𝑦0 + 𝑢2−𝑢 2! ∆2 𝑦0 + 𝑢3−3𝑢2+2𝑢 3! ∆3 𝑦0 + .....] ℎ𝑑𝑢 𝑛 0 = ℎ[𝑦0[𝑢]0 𝑛 + ∆2 𝑦0 2! [ 𝑢3 3 − 𝑢2 2 ] 0 𝑛 + ∆3 𝑦0 3! [ 𝑢4 4 − 𝑢3 + 𝑢2 ] 0 𝑛 + ⋯ ] = 𝑛ℎ[ 𝑛 2 ∆𝑦0 + 2𝑛2−3𝑛 12 ∆2 𝑦0 + 𝑛3−4𝑛2+4𝑛 24 ∆3 𝑦0 + ⋯ ] . . . . . ( 1 ) From this formula, one can generate different integration formulae by substituting n = 1,2,3, . . . . 1. Trapezoidal Rule Substituting n = 1 in equation ( 1). In this case all differences higher than the first difference become zero. Then, ∫ 𝑓(𝑥)𝑑𝑥 = ℎ [ 𝑦0 + 1 2 ∆𝑦0] = ℎ [𝑦0 + 1 2 (𝑦1 − 𝑦0)] = ℎ 2 𝑥𝑛 𝑥0 (𝑦0 + 𝑦1) . . . (2) The formula is known as the trapezoidal rule.
  • 4. In this formula, the interval [𝑎, 𝑏] is considered as a single interval, and it gives a very rough answer. But, if the interval [𝑎, 𝑏] is divided into several subintervals and this formula is applied to each of these subintervals then a better approximate result may be obtained. Error in trapezoidal rule The error of trapezoidal rule is 𝐸 = ∫ 𝑓(𝑥)𝑑𝑥 − 𝑏 𝑎 ℎ 2 (𝑦0 + 𝑦1) . . .( 3 ) Let 𝑦 = 𝑓(𝑥) be continuous and processes continuous derivates of all orders. Also, It is assumed that there exists a function 𝐹(𝑥) such that 𝐹′(𝑥) = 𝑓(𝑥) 𝑖𝑛 [𝑥0, 𝑥1] Then, ∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝐹′(𝑥)𝑑𝑥 = 𝐹(𝑥1) − 𝐹(𝑥0) 𝑥1 𝑥0 𝑏 𝑎 = 𝐹(𝑥0 + ℎ) − 𝐹(𝑥0) = 𝐹(𝑥0) + ℎ𝐹′(𝑥0) + ℎ2 2! 𝐹′′(𝑥0) + ℎ3 3! 𝐹′′′(𝑥0) + ⋯ 𝐹(𝑥0) = ℎ𝑓(𝑥0) + ℎ2 2! 𝑓′(𝑥0) + ℎ3 3! 𝑓′′(𝑥0) + ⋯ = ℎ𝑦0 + ℎ2 2! 𝑦′0 + ℎ3 6! 𝑦′′0 + ⋯ . . . ( 4 ) Again, ℎ 2 (𝑦0 + 𝑦1) = ℎ 2 [𝑦0 + 𝑦(𝑥0 + ℎ)] = ℎ 2 [𝑦0 + 𝑦(𝑦0) + ℎ𝑦′(𝑥0 ) + ℎ2 2! 𝑦′′(𝑥0 ) + ⋯ ] = ℎ 2 [𝑦0 + 𝑦0 + ℎ𝑦′ 0 + ℎ2 2! 𝑦′′ 0 + ⋯ ] . . .( 5 ) Using (4) and (5), equation (3) becomes, 𝐸 = ℎ 2 [𝑦0 + ℎ2 2! 𝑦′ 0 + ℎ2 6! 𝑦′′ 0 + ⋯ ] − ℎ 2 [2𝑦0 + ℎ𝑦′ 0 + ℎ2 2! 𝑦′′ 0 + ⋯ ] = − ℎ3 12! 𝑦′′ 0 + ⋯
  • 5. = − ℎ3 12! 𝑓′′(𝑥0) + ⋯ ≅ − ℎ3 12! 𝑓′′(𝜉), ⋯ (𝟔) Where 𝑎 = 𝑥0 < 𝜉 < 𝑥1 = 𝑏. Equation (6) gives the error in the interval [𝑥0,𝑥1]. The total error in the composite rule is 𝐸 = − ℎ3 12 ( 𝑦′′ 0 + 𝑦′′ 1 + ⋯ + 𝑦𝑛−1 𝑛 ) If 𝑦′′(𝜉) is the largest among the n quantities 𝑦′′ 0 , 𝑦′′ 1 , ⋯ , 𝑦𝑛−1 𝑛 then 𝐸 ≤ − 1 12 ℎ3 𝑛𝑦′′(𝜉) = − (𝑏−𝑎) 12 ℎ2 𝑛𝑦′′(𝜉), as 𝑛ℎ = 𝑏 − 𝑎 Note: Trapezoidal rule: The error term shows that if the second and higher order derivatives of 𝑓(𝑥) vanish then the trapezoidal rule gives exact result of the integral. This means, the method gives exact result when 𝑓(𝑥) is linear. Geometrical Interpretation Of Trapezoidal Rule In this rule, the curve 𝑦 = 𝑓(𝑥) is replaced by the line joining the points 𝐴(𝑥0 + 𝑦0) and 𝐵(𝑥1 + 𝑦1) Figure(a). Thus the area bounded by the curve 𝑦 = 𝑓(𝑥), the ordinates 𝑥 = 𝑥0, 𝑥 = 𝑥1 and the x axis is then approximately equivalent to the area of the trapezium (ABCD) bounded by the line AB, 𝑥 = 𝑥0, 𝑥 = 𝑥1 and x axis. Figure(a): Geometrical Interpretation Of Trapezoidal Rule Implementation Of Trapezoidal Rule Via Coding : To The Implement Integral We Used Walfram Mathematica Software.
  • 6. Questions :- Implement the following integrals using the Trapezoidal Rule (i) ∫ 1/𝑥𝑑𝑥 3 2 (ii)∫ 𝑑𝑥 1+𝑥2 1 0 (iii)∫ 𝑐𝑜𝑠2 𝑥𝑑𝑥 0.25 −0.25 Solution 1. f[x_] = 1/x; a = 2; b = 3; exactIn1 = Integrate[f[x],{x, a, b}]; approxiIn1 = (b-a) * ((f[a] + f[b] )/2); error1 = Abs(exactIn1 - apporxiIn1); print["Exact value of integration is: ", N[exactIn1]] print["Integration using Trapezoidal rule is: ", N[approxiIn1]] print["Error in the approximation is: ", N[error1]] Output:- print[ Exact value of integration is: , 0.405465 ] print [ Integration using Trapezoidal Rule is: , 0.416667 ] print [ Error in the Approximation is: , -0.0112016 Abs ] Solution 2. f[x_] = 1/(1+x^2); a = 0;
  • 7. b = 1; exactIn1 = Integrate[f[x],{x, a, b}]; approxiIn1 = (b-a) * ((f[a] + f[b] )/2); error1 = Abs(exactIn1 - apporxiIn1); print["Exact value of integration is: ", N[exactIn1]] print["Integration using Trapezoidal rule is: ", N[approxiIn1]] print["Error in the approximation is: ", N[error1]] output:- print[ Exact value of integration is: , 0.785396 ] print [ Integration using Trapezoidal Rule is: , 0.75] print [ Error in the Approximation is: , Abs( 0. 785396 -1. approxiIn1 ) ] Solution 3. f[x_] = Cos[x]^2; a = -0.25;
  • 8. b = 0.25; exactIn1 = Integrate[f[x],{x, a, b}]; approxiIn1 = (b-a) * ((f[a] + f[b] )/2); error1 = Abs(exactIn1 - apporxiIn1); print["Exact value of integration is: ", N[exactIn1]] print["Integration using Trapezoidal rule is: ", N[approxiIn1]] print["Error in the approximation is: ", N[error1]] output:- print[ Exact value of integration is: , 0.489713 ] print [ Integration using Trapezoidal Rule is: , 0.469396] print [ Error in the Approximation is: , 0. 0203171 Abs ] 1.1. Composite Trapezoidal Rule Let the interval [𝑎, 𝑏] be divided into n equal subintervals by the points 𝑎 = 𝑥0, 𝑥1, 𝑥2, ⋯ , 𝑥𝑛 = 𝑏, where 𝑥𝑖 = 𝑥0 + 𝑖ℎ, 𝑖 = 1, 2, 3, ⋯ , 𝑛. Applying the trapezoidal rule to each of the subintervals, one can find the composite formula as,
  • 9. ∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝑓′(𝑥)𝑑𝑥 + 𝑥1 𝑥0 𝑏 𝑎 ∫ 𝑓(𝑥)𝑑𝑥 + ⋯ + ∫ 𝑓(𝑥)𝑑𝑥 𝑥𝑛 𝑥𝑛−1 𝑥2 𝑥1 ≅ ℎ 2 [𝑦0 + 𝑦1] + ℎ 2 [𝑦1 + 𝑦2] + ℎ 2 [𝑦2 + 𝑦3] + ⋯ + ℎ 2 [𝑦𝑛−1 + 𝑦𝑛] = ℎ 2 [𝑦0 + 2( 𝑦1 + 𝑦2 + 𝑦3 + ⋯ + 𝑦𝑛−1) + 𝑦𝑛] . . . (7) The above equation no 7 is called Composite Trapezoidal Rule Error for Composite Trapezoidal Rule: 𝐸 ≤ − 1 12 ℎ3 𝑛𝑦′′(𝜉) = − (𝑏−𝑎) 12 ℎ2 𝑛𝑦′′(𝜉), as 𝑛ℎ = 𝑏 − 𝑎 Geometrical Interpretation Of Composite Trapezoidal Rule: The geometrical significance of composite trapezoidal rule is that the curve 𝑦 = 𝑓(𝑥) is replaced by n straight lines joining the points (𝑥0, 𝑦0) and (𝑥1, 𝑦1) ; (𝑥1, 𝑦1) 𝑎𝑛𝑑 (𝑥2, 𝑦2); ⋯ , (𝑥𝑛−1, 𝑦𝑛−1) and (𝑥𝑛, 𝑦𝑛). Then the area bounded by the curve 𝑦 = 𝑓(𝑥), the lines 𝑥 = 𝑥0, , 𝑥 = 𝑥𝑛 and the x-axis is then approximately equivalent to the sum of the area of n trapeziums (Figure b). Implementation Of Composite Trapezoidal Rule Via Coding Questions :- Implement the following integrals using the Composite Trapezoidal Rule the indicated values of n. (i)∫ 𝑥𝑙𝑜𝑔(𝑥 + 1)𝑑𝑥 0 −0.5 (ii) ∫ 𝑐𝑜𝑠2 𝑥𝑑𝑥 0.25 −0.25 , n=4 Solution 1.
  • 10. ClearAll[a, b, exactIn, approxiIn, error, f, x, t, n, m] n = 4; f[t_] = 𝑥𝑙𝑜𝑔(𝑥 + 1)𝑑𝑥; a = -0.5; b = 0; h = (b - a) / n; x = Range[a, b, h]; m = Length[x]; exactIn = ∫ 𝑓[𝑡]𝑑𝑡 𝑏 𝑎 approxiIn = (ℎ 2 ⁄ ) ∗ ( 𝑓[𝑥[𝑖]] + 𝑓[𝑥[𝑚]] + 2 ∗ ∑ 𝑓[𝑥[𝑖]] 𝑚−1 𝑖=2 ) error = Abs[exactIn - approxiIn] Print["Exact value of integral is : ", N[exactIn]] Print["Approximate value of integral using trapezoidal rule is : ", N[approxiIn]] Print["Error in the approximation is ", N[error]] Output: Exact value of integral is : 0.0525698 Approximate value of integral using trapezoidal rule is : 0.0535485 Error in the approximation is 0.000978701
  • 11. Solution 2. ClearAll[a, b, exactIn, approxiIn, error, f, x, t, n, m] n = 4; f[t_] = Cos[t]^2; a = -0.25; b = 0.25; h = (b - a) / n; x = Range[a, b, h]; m = Length[x]; exactIn = ∫ 𝑓[𝑡]𝑑𝑡 𝑏 𝑎 approxiIn = (ℎ 2 ⁄ ) ∗ ( 𝑓[𝑥[𝑖]] + 𝑓[𝑥[𝑚]] + 2 ∗ ∑ 𝑓[𝑥[𝑖]] 𝑚−1 𝑖=2 ) error = Abs[exactIn - approxiIn] Print["Exact value of integral is : ", N[exactIn]] Print["Approximate value of integral using trapezoidal rule is : ", N[approxiIn]] Print["Error in the approximation is ", N[error]] Output: Exact value of integral is : 0.489713 Approximate value of integral using trapezoidal rule is : 0.488463 Error in the approximation is 0.00124981
  • 12. 2. Simpson rule: In this formula the interval [𝑎, 𝑏] is divided into two equal subintervals by the points 𝑥0, 𝑥1, 𝑥2, where ℎ = 𝑏−𝑎 2 , 𝑥1 = 𝑥0 + ℎ 𝑎𝑛𝑑 𝑥2 = 𝑥1 + ℎ. This rule is obtained by putting n =2 in (1). In this case, the third and higher order differences do not exist. The equation (1) is simplified as, ∫ 𝑓(𝑥)𝑑𝑥 ≅ 2ℎ [ 𝑦0 + ∆𝑦0 + 1 6 ∆2 𝑦0] 𝑥𝑛 𝑥0 = 2ℎ [ 𝑦0 + (𝑦1 − 𝑦0) + 1 6 (𝑦2 − 2𝑦1 + 𝑦0)] = ℎ 3 [𝑦0 + 4𝑦1 + 𝑦2] . . . . . (8) The above rule is known as Simpson rule. Error in Simpson rule The error in this formula is 𝐸 = ∫ 𝑓(𝑥)𝑑𝑥 − 𝑥𝑛 𝑥0 ℎ 3 (𝑦0 + 4𝑦1 + 𝑦2) Let the function f(x) be continuous in [𝑥0, 𝑥2] and possesses continuous derivatives of all order. Also, let there exists a function F(x) in [𝑥0, 𝑥2], such that F’(x) = f(x). Then, ∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝐹′(𝑥)𝑑𝑥 = 𝐹(𝑥2) − 𝐹(𝑥0) 𝑥2 𝑥0 𝑥2 𝑥0 = 𝐹(𝑥0 + 2ℎ) − 𝐹(𝑥0) = 𝐹(𝑥0) + 2𝐹′(𝑥0) + (2ℎ)2 2! 𝐹′′(𝑥0) + (2ℎ)3 3! 𝐹′′′(𝑥0) + (2ℎ)4 4! 𝐹𝑖𝑣(𝑥0) + (2ℎ)5 5! 𝐹𝑣(𝑥0) + ⋯ − 𝐹(𝑥0) = 2ℎ𝑓(𝑥0) + 2ℎ𝑓′(𝑥0) + 4 3 ℎ3 𝑓′′(𝑥0) + 2 3 ℎ3 𝑓′′′(𝑥0) + 4 15 ℎ3 𝑓𝑖𝑣(𝑥0) + ⋯ . . . . . . . . (9) Again, = ℎ 3 [𝑦0 + 4𝑦1 + 𝑦2] = ℎ 3 [𝑓(𝑥0) + 4𝑓(𝑥0 + ℎ) + 𝑓(𝑥0 + 2ℎ)]
  • 13. = ℎ 3 [ 𝑓(𝑥0) + 4 { 𝑓(𝑥0) + ℎ𝑓′(𝑥0) + ℎ2 2! 𝑓′′(𝑥0) + ℎ3 3! 𝑓′′′(𝑥0) + ℎ4 4! 𝑓𝑖𝑣(𝑥0) + ⋯ } + { 𝑓(𝑥0) + 2ℎ𝑓′(𝑥0) + (2ℎ)2 2! 𝑓′′(𝑥0) + (2ℎ)3 3! 𝑓′′′(𝑥0) + (2ℎ)4 4! 𝑓𝑖𝑣(𝑥0) + ⋯ } ] = 2ℎ𝑓(𝑥0) + 2ℎ2 𝑓′(𝑥0) + 4 3 ℎ3 𝑓′′(𝑥0) + 2 3 ℎ4 𝑓′′′(𝑥0) + 5 4 ℎ5 𝑓𝑖𝑣(𝑥0) + ⋯ . . . . . .. (10) Using eq (9) and (10),equation (8) becomes, 𝐸 = ( 4 15 − 5 18 ) ℎ5 𝑓𝑖𝑣(𝑥0) + ⋯ ≅ − ℎ5 90 𝑓𝑖𝑣(𝜉), ⋯ (𝟏𝟏) Where 𝑥0 < 𝜉 < 𝑥2 This is the error in the interval [𝑥0, 𝑥2] The total error in composite formula is 𝐸 = − ℎ5 90 {𝑓𝑖𝑣(𝑥0) + 𝑓𝑖𝑣(𝑥2) + ⋯ + 𝑓𝑖𝑣(𝑥𝑛−2)} = − ℎ5 90 𝑛 2 𝑓𝑖𝑣(𝜉) = − 𝑛ℎ5 180 𝑓𝑖𝑣(𝜉), ( 𝑤ℎ𝑒𝑟𝑒 𝑓𝑖𝑣(𝜉) 𝑖𝑠 𝑡ℎ𝑒 𝑚𝑎𝑥𝑖𝑚𝑢𝑚 𝑎𝑚𝑜𝑛𝑔 𝑓𝑖𝑣(𝑥0), 𝑓𝑖𝑣(𝑥2), ⋯ , 𝑓𝑖𝑣(𝑥𝑛−2)) = − (𝑏−𝑎) 180 ℎ4 𝑓𝑖𝑣(𝜉), . . . . . . . . (12) Geometrical interpretation of Simpson rule: In Simpson’s 1/3 rule, the curve y = f(x) is replaced by the second degree parabola passing through the points 𝐴(𝑥0, 𝑦0), 𝐵(𝑥1, 𝑦1) 𝑎𝑛𝑑 𝐶(𝑥2, 𝑦2). Therefore, the area bounded by the curve 𝑦 = 𝑓(𝑥), the ordinates 𝑥 = 𝑥0, 𝑥 = 𝑥2 𝑎𝑛𝑑 𝑥 − 𝑎𝑥𝑖𝑠, 𝑖. 𝑒, the area of the shaded region ABCDEA.
  • 14. Implementation of Simpson rule via Coding: Questions :- Implement the following integrals using the Simpson’s 1/3 Rule (i) ∫ 1/𝑥𝑑𝑥 3 2 (ii) ∫ 𝑑𝑥 1+𝑥2 1 0 (iii)∫ 𝑐𝑜𝑠2 𝑥𝑑𝑥 0.25 −0.25 Solution 1. f[x_] = 1/x; a = 2; b = 3; h = (b-a)/2 exactIn1 = Integrate[f[x],{x, a, b}]; approxiIn1 = (h/3) * ( [f[a] + 4*f[(a = b) / 2] + f[b]); error1 = Abs(exactIn1 - apporxiIn1); print["Exact value of integration is: ", N[exactIn1]] print["Integration using Trapezoidal rule is: ", N[approxiIn1]] print["Error in the approximation is: ", N[error1]] Output:- print[ Exact value of integration is: , 0.405465 ]
  • 15. print [ Integration using Trapezoidal Rule is: , 0.583333 ] print [ Error in the Approximation is: , -0.177868 Abs ] Solution 2. f[x_] = 1/(1+x^2); a = 0; b = 1; h = (b-a)/2 exactIn1 = Integrate[f[x],{x, a, b}]; approxiIn1 = (h/3) * ( [f[a] + 4*f[(a = b) / 2] + f[b]); error1 = Abs(exactIn1 - apporxiIn1); print["Exact value of integration is: ", N[exactIn1]] print["Integration using Trapezoidal rule is: ", N[approxiIn1]] print["Error in the approximation is: ", N[error1]] Output:- print[ Exact value of integration is: , 0.785396 ]
  • 16. print [ Integration using Trapezoidal Rule is: , 0.783333] print [ Error in the Approximation is: , 0.00206483Abs ] Solution 3. f[x_] = Cos[x]^2; a = -0.25; b = 0.25; h = (b-a)/2 exactIn1 = Integrate[f[x],{x, a, b}]; approxiIn1 = (h/3) * ( [f[a] + 4*f[(a = b) / 2] + f[b]); error1 = Abs(exactIn1 - apporxiIn1); print["Exact value of integration is: ", N[exactIn1]] print["Integration using Trapezoidal rule is: ", N[approxiIn1]] print["Error in the approximation is: ", N[error1]] Output:-
  • 17. print[ Exact value of integration is: , 0.489713 ] print [ Integration using Trapezoidal Rule is: , 0.484617] print [ Error in the Approximation is: , 0. 00509549 Abs ] Simpson Composite rule Let the interval [𝑎, 𝑏] be divided into n (an even number ) equal subintervals by the points 𝑥0, 𝑥1, 𝑥2, ⋯ , 𝑥𝑛, where 𝑥𝑖 = 𝑥0 + 𝑖ℎ, 𝑖 = 1, 2, ⋯ , 𝑛. Then, ∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝑓(𝑥)𝑑𝑥 + 𝑥1 𝑥0 ∫ 𝑓(𝑥)𝑑𝑥 + ⋯ + ∫ 𝑓(𝑥)𝑑𝑥 𝑥𝑛 𝑥𝑛−2 𝑥4 𝑥2 𝑏 𝑎 = ℎ 3 [𝑦0 + 4𝑦1 + 𝑦2] + ℎ 3 [𝑦2 + 4𝑦3 + 𝑦4] + ⋯ + ℎ 3 [𝑦𝑛−2 + 4𝑦𝑛−1 + 𝑦𝑛] = ℎ 3 [𝑦0 + 4(𝑦1 + 𝑦3 + ⋯ + 𝑦𝑛−1 ) + 2(𝑦2 + 𝑦4 + ⋯ + 𝑦𝑛−2 ) + 𝑦𝑛 ] . . . . . . . (13) This formula is known as Simpson composite rule for numerical integration. Error in Simpson Composite rule 𝑬 = − (𝑏−𝑎) 180 ℎ4 𝑓𝑖𝑣 (𝜉)
  • 18. Geometrical interpretation of Simpson Composite rule: Putting 𝑛 = 2 in (1) above and taking the curve through (𝑥0, 𝑦0), (𝑥1, 𝑦1) 𝑎𝑛𝑑 (𝑥2, 𝑦2) as a parabola (Figure C), i.e., a polynomial of the second order so that differences of order higher than the second vanish, we get (figure C) Implementation of Simpson Composite rule via Coding Questions :- Implement the following integrals using the Simpson’s 1/3 Composite Rule the indicated values of n. (i)∫ 𝑥𝑙𝑜𝑔(𝑥 + 1)𝑑𝑥 0 −0.5 (ii) ∫ 𝑐𝑜𝑠2 𝑥𝑑𝑥 0.25 −0.25 , n=4 Solution 1. ClearAll[a, b, exactIn, approxiIn, error, f, x, t, n, m, h] n = 6; f[t_] = 𝑡 ∗ 𝐿𝑜𝑔[𝑡 + 1]; a = -0.5; b = 0; h = (b - a) / (2*n); x = Range[a, b, h]; m = Length[x]; exactIn = ∫ 𝑓[𝑡]𝑑𝑡 𝑏 𝑎 approxiIn = (ℎ 3 ⁄ ) ∗ ( 𝑓[𝑥[𝑖]] + 4 ∗ ∑ 𝑓[𝑥[2 ∗ 𝑖]] (𝑚−1)/2 𝑖=1 + 2 ∗ ∑ 𝑓[𝑥[2 ∗ (𝑚−1)/2 𝑖=2 𝑖 − 1]] + 𝑓[𝑥[𝑚]]); error = Abs[exactIn - approxiIn] Print["Exact value of integral is : ", N[exactIn]] Print["Approximate value of integral using Simpson’s rule is : ", N[approxiIn]] Print["Error in the approximation is ", N[error]]
  • 19. Output:- print[ Exact value of integral is: , 0.0525698 ] print [ Integration using Trapezoidal Rule is: , 0.343574 ] print [ Error in the Approximation is: , 0.294004 ] Solution 2. ClearAll[a, b, exactIn, approxiIn, error, f, x, t, n, m, h] n = 4; f[t_] = Cos[t]^2; a = -0.25; b = 0.25; h = (b - a) / (2*n); x = Range[a, b, h]; m = Length[x]; exactIn = ∫ 𝑓[𝑡]𝑑𝑡 𝑏 𝑎 approxiIn = (ℎ 3 ⁄ ) ∗ ( 𝑓[𝑥[𝑖]] + 4 ∗ ∑ 𝑓[𝑥[2 ∗ 𝑖]] (𝑚−1)/2 𝑖=1 + 2 ∗ ∑ 𝑓[𝑥[2 ∗ (𝑚−1)/2 𝑖=2 𝑖 − 1]] + 𝑓[𝑥[𝑚]] ); error = Abs[exactIn - approxiIn] Print["Exact value of integral is : ", N[exactIn]] Print["Approximate value of integral using Simpson’s rule is : ", N[approxiIn]]
  • 20. Print["Error in the approximation is ", N[error]] Output:- print[ Exact value of integral is: , 0.489713 ] print [ Integration using Trapezoidal Rule is: , 0.625861 ] print [ Error in the Approximation is: , 0.136148 ] Reasons For Numerical Integration: There are several reasons for carrying out numerical integration. 1. The integrand f(x) may be known only at certain points, such as obtained by sampling. Some embedded system and other computer applications may need numerical integration for this reason. 2. A formula for the integrand may be known, but it may be difficult or impossible to find an antiderivative that is an elementary function. An example of such an integrand is f(x) = exp (−x2), the antiderivative of which (the error function, times a constant) cannot be written in elementary form. 3. It may be possible to find an antiderivative symbolically, but it may be easier to compute a numerical approximation than to compute the antiderivative. That may be the case if the antiderivative is given as an infinite series or product, or if its evaluation requires a special function that is not available.
  • 21. Application Of Integration: It Helps To: ➢ Locate the centroid. ➢ Find the arc length of graph ➢ Find the surface area of solid ➢ Find the volume of a solid figure ➢ Solve for the work done ➢ Solve the moment of inertia ➢ Find the area It is also used to find: ➢ Water plane area ➢ Sectional area ➢ Submerged volume Pros: ➢ Possible to integrate any function ➢ Multidimensional integrals are straightforward ➢ Ability to solve integrals along irregular domains in multidimensional spaces (any shape). ➢ Numerical integration gives you an answer to some problems that analytic techniques don’t. Cons: ➢ There is an intrinsic error in calculation ➢ Numerical integrals are, always, computationally expensive. Summary And References: In numerical analysis, Numerical Integration constitutes a broad family of algorithms for calculating the numerical value of a definite integral, and by extension, the term is also sometimes used to describe the numerical solution of differential equations. This article focuses on calculation of definite integrals. The term numerical quadrature (often abbreviated to quadrature) is more or less a synonym for numerical integration, especially as applied to one-dimensional integrals. Integration has been there since even before the proper use of calculus. In modern day integration has led to some great creations including the Petronas towers and the Sydney opera house.