Lec #5 (Numerical Integration)
Lec #5 (Numerical Integration)
By
(NUMERICAL INTEGRATION)
Lec # 5
1
OBJECTIVES
2
NUMERICAL INTEGRATION
1 1
𝑥2
ධ 𝑒 𝑑𝑥 ධ 1 + 𝑥 3 𝑑𝑥
0 −1
Or
𝑏
𝑏−𝑎
න 𝑓 𝑥 𝑑𝑥 = 𝑓 𝑥0 + 2𝑓 𝑥1 + 2𝑓 𝑥2 + ⋯ + 2𝑓 𝑥𝑛−1 + 𝑓 𝑥𝑛
2𝑛
𝑎
𝑏
𝑏−𝑎
න 𝑓 𝑥 𝑑𝑥 = 𝑓 𝑥0 + 2(𝑓 𝑥1 + 𝑓 𝑥2 + ⋯ + 𝑓 𝑥𝑛−1 ) + 𝑓 𝑥𝑛
2𝑛
𝑎
5
NOTE:
TRAPEZIUM:
Two sides are parallel and other two sides are not parallel then it is
trapezium. If 4 sides are parallel, then it is parallelogram.
AREA OF TRAPEZIUM:
Area of trapezium = ½ (sum of parallel sides) (shortest distance between them)
1
𝒂 𝒉 𝒃 𝐴= 𝑎+𝑏 ℎ
2
6
Proof:
𝑓 𝑥0 +𝑓 𝑥1
𝐴𝑟𝑒𝑎 𝑜𝑓 𝑡𝑟𝑎𝑝𝑒𝑧𝑖𝑢𝑚 = ℎ
2
𝑥1
𝑓 𝑥0 + 𝑓 𝑥1
න 𝑓 𝑥 𝑑𝑥 = ℎ
2
𝑥0
ℎ 𝑓0 + 𝑓1
=
2 2
𝑓(𝑥1 )
𝑓(𝑥0 )
𝑥1 − 𝑥0 = ℎ
𝑎 = 𝑥0 𝑏 = 𝑥1
7
𝑥2
𝑓 𝑥0 + 𝑓 𝑥1 𝑓 𝑥1 + 𝑓 𝑥2
න 𝑓 𝑥 𝑑𝑥 = ℎ+ ℎ
2 2
𝑥0
ℎ
= 𝑓 𝑥0 + 𝑓 𝑥1 + 𝑓 𝑥1 + 𝑓 𝑥2
2
ℎ
= 𝑓 𝑥0 + 2𝑓 𝑥1 + 𝑓 𝑥2
2
𝑥2
ℎ 𝑓(𝑥2 )
න 𝑓 𝑥 𝑑𝑥 = 𝑓0 + 2𝑓1 + 𝑓2 𝑓(𝑥0 )
2
𝑥0
𝑥1 − 𝑥0 𝑥2 − 𝑥1
𝑥0 ℎ 𝑥1 ℎ 𝑥2
8
𝑥3
𝑓 𝑥0 + 𝑓 𝑥1 𝑓 𝑥1 + 𝑓 𝑥2 𝑓 𝑥2 + 𝑓 𝑥3
න 𝑓 𝑥 𝑑𝑥 = ℎ+ ℎ+ ℎ
2 2 2
𝑥0
ℎ
= 𝑓 𝑥0 + 𝑓 𝑥1 + 𝑓 𝑥1 + 𝑓 𝑥2 + 𝑓 𝑥2 + 𝑓 𝑥3
2
ℎ (𝑥3 , 𝑓 𝑥3
= 𝑓 𝑥0 + 2𝑓 𝑥1 + 2𝑓 𝑥2 + 𝑓 𝑥3
2
𝑥3
ℎ
න 𝑓 𝑥 𝑑𝑥 = 𝑓 + 2𝑓1 + 2𝑓2 + 𝑓3
2 0
𝑓(𝑥3 )
𝑥0
𝑓(𝑥2 )
𝑓(𝑥0 )
𝑥1 − 𝑥0 𝑥2 − 𝑥1 𝑥3 − 𝑥2
𝑥0 ℎ 𝑥1 ℎ 𝑥2 ℎ 𝑥3
9
In general, trapezoidal rule is defined as
𝑥𝑛
ℎ
න 𝑓 𝑥 𝑑𝑥 = 𝑓 𝑥0 + 2(𝑓 𝑥1 + 𝑓 𝑥2 + ⋯ + 𝑓 𝑥𝑛−1 ) + 𝑓 𝑥𝑛
2
𝑥0
where
𝑏−𝑎
ℎ=
𝑛
10
EXAMPLE: Use the trapezoidal rule with 𝑛 = 4 to approximate.
4
𝐼 = න 𝑥 2 + 1 𝑑𝑥
0
SOLUTION:
𝑏−𝑎 4−0 4
ℎ= = = =1
𝑛 4 4
𝑥𝑛
ℎ
න 𝑓 𝑥 𝑑𝑥 = 𝑓 𝑥0 + 2(𝑓 𝑥1 + 𝑓 𝑥2 + 𝑓 𝑥3 ) + 𝑓 𝑥4
2
𝑥0
𝑥0 = 0
𝑥𝑛 𝑓(𝑥𝒏 ) 𝑥1 = 𝑥0 + ℎ
𝑥0 = 0 𝑓 𝑥𝟎 = 𝑥0 2 + 1 = 0 + 1 = 1 𝑥1 = 0 + 1 = 1
𝑥1 = 1 𝑓 𝑥𝟏 = 𝑥1 2 + 1 = 1 + 1 = 1.41421 𝑥2 = 𝑥1 + ℎ = 𝑥0 + 2ℎ
𝑥2 = 2 𝑓 𝑥𝟐 = 𝑥2 2 + 1 = 22 + 1 = 2.23607 =1+1=2
𝑥3 = 3 𝑓 𝑥𝟑 = 𝑥3 2 + 1 = 32 + 1 = 3.16228 𝑥3 = 𝑥2 + ℎ = 2 + 1 = 3
𝑥4 = 4 𝑓 𝑥𝟒 = 𝑥4 2 + 1 = 42 + 1 = 4.12311 𝑥4 = 𝑥3 + ℎ = 3 + 1 = 4
11
𝑥𝑛
ℎ
න 𝑓 𝑥 𝑑𝑥 = 𝑓 𝑥0 + 2(𝑓 𝑥1 + 𝑓 𝑥2 + 𝑓 𝑥3 ) + 𝑓 𝑥4
2
𝑥0
4
1
න 𝑥2 + 1 𝑑𝑥 = 1 + 2(1.41421 + 2.23607 + 3.16228) + 4.12311
2
0
1 18.74823
= 1 + 2(6.81256) + 4.12311 =
2 2
4
න 𝑥 2 + 1 𝑑𝑥 = 9.37412
0
The exact value of the integral can be found as
4 4
2
𝑥 1 1
𝐼 =න 𝑥 +1= 𝑥 + 1 + ln(𝑥 + 𝑥 2 + 1)
2 = 2 17 + ln(4 + 17)
2 2 0
2
0
= 8.24621 + 0.04736 = 9.29357
4
The approximation 9.37412 of I = ධ 𝑥 2 + 1𝑑𝑥 found by the trapezoidal rule
0
differ from the true value by 0.08054. The error would be reduced if the number of
subintervals partitioning [0, 4] is increased.
12
EXAMPLE: Use the trapezoidal rule with 𝑛 = 6 to estimate.
2
𝑑𝑥
ln 2 = න
𝑥
1
SOLUTION: Here length of each subintervals is
𝑏−𝑎 2−1 1
ℎ= = =
𝑛 6 6
The interval is
𝑥0 = 1
1 6+1 7 7 1 8
𝑥1 = 𝑥0 + ℎ = 1 + = = , 𝑥2 = 𝑥1 + ℎ = + =
6 6 6 6 6 6
8 1 9 9 1 10
𝑥3 = 𝑥2 + ℎ = + = , 𝑥4 = 𝑥3 + ℎ = + =
6 6 6 6 6 6
10 1 11 11 1 12
𝑥5 = 𝑥4 + ℎ = + = , 𝑥6 = 𝑥5 + ℎ = + = =2
6 6 6 6 6 6
13
EXAMPLE: Use the trapezoidal rule with 𝑛 = 6 to estimate.
2
𝑑𝑥
ln 2 = න
𝑥
1
SOLUTION: Here length of each subintervals is
𝑏−𝑎 2−1 1
ℎ= = =
𝑛 6 6
The interval is
𝑥0 = 1
1 6+1 7 7 1 8
𝑥1 = 𝑥0 + ℎ = 1 + = = , 𝑥2 = 𝑥1 + ℎ = + =
6 6 6 6 6 6
8 1 9 9 1 10
𝑥3 = 𝑥2 + ℎ = + = , 𝑥4 = 𝑥3 + ℎ = + =
6 6 6 6 6 6
10 1 11 11 1 12
𝑥5 = 𝑥4 + ℎ = + = , 𝑥6 = 𝑥5 + ℎ = + = =2
6 6 6 6 6 6
14
𝒙𝒏 𝟏
𝒇 𝒙𝒏 =
𝒙
𝑥0 = 1 1 1
𝑓 𝑥𝟎 = = =1
𝑥𝟎 1
7 1 1
𝑥1 = 𝑓 𝑥𝟏 = = = 0.85714
6 𝑥𝟏 7/6
8 1 1
𝑥2 = 𝑓 𝑥𝟐 = = = 0.75
6 𝑥𝟐 8/6
9 1 1
𝑥3 = 𝑓 𝑥𝟑 = = = 0.66667
6 𝑥𝟑 9/6
10 1 1
𝑥4 = 𝑓 𝑥𝟒 = = = 0.6
6 𝑥𝟒 10/6
11 1 1
𝑥5 = 𝑓 𝑥𝟓 = = = 0.54545
6 𝑥𝟓 11/6
𝑥6 = 2 1 1
𝑓 𝑥𝟔 = = = 0.5
𝑥𝟔 2
15
𝑥6
ℎ
න 𝑓 𝑥 𝑑𝑥 = 𝑓 𝑥0 + 2(𝑓 𝑥1 + 𝑓 𝑥2 + 𝑓 𝑥3 + 𝑓 𝑥4 + 𝑓 𝑥5 ) + 𝑓 𝑥6
2
𝑥0
1
= 1 + 2(0.85714 + 0.75 + 0.66667 + 0.6 + 0.54545) + 0.5
12
1 8.33852
= 1 + 6.83852 + 0.5 = = 0.69487
12 12
By calculator, ln 2 = 0.69487
16
THEOREM: SIMPSON’S 1/3 rule
If a function 𝑓 𝑥 be continuous on [𝑎, 𝑏] and let [𝑎, 𝑏] be partitioned
into an even number "𝑛“ equal subintervals
𝑎 = 𝑥0 , 𝑥1 , 𝑥1 , 𝑥2 , 𝑥2 , 𝑥1 , … , 𝑥𝑛−1 , 𝑥𝑛 = 𝑏 then
𝑏 𝑓 𝑥0 + 4(𝑓 𝑥1 + 𝑓 𝑥3 + 𝑓 𝑥5 + ⋯ + 𝑓 𝑥𝑛−1 )
ℎ
න 𝑓 𝑥 𝑑𝑥 =
3
𝑎 +2(𝑓 𝑥2 + 𝑓 𝑥4 + 𝑓 𝑥6 … + 𝑓 𝑥𝑛−2 ) + 𝑓 𝑥𝑛
𝑏 𝑓0 + 𝑓𝑛 + 4 𝑓1 + 𝑓3 + 𝑓5 + ⋯ + 𝑓𝑛−1
ℎ
න 𝑓 𝑥 𝑑𝑥 =
3
𝑎 +2 𝑓2 + 𝑓4 + 𝑓6 + ⋯ + 𝑓𝑛−2
𝑏−𝑎
Where, ℎ=
𝑛
17
PROOF: The trapezoidal rule tries to
simplify integration by approximating the
function to be integrated by a straight line or a
series of line segments.
In Simpson's rule, we try to approximate by a
series of parabolic segments hoping that the
parabola will move closely match the given
curve f(x) then would the straight line in
trapezoidal rule.
To estimate
𝑥2
I = න 𝑓 𝑥 𝑑𝑥
𝑥0
Passing through
𝑥0 , 𝑓 𝑥0 , 𝑥1 , 𝑓 𝑥1 , 𝑥2 , 𝑓 𝑥2 𝑥0 𝑥2
𝑥1
That is 18
2
𝑓 𝑥0 = 𝑎 + 𝑏𝑥0 + 𝑐𝑥0
2
𝑓 𝑥1 = 𝑎 + 𝑏𝑥1 + 𝑐𝑥1
2
𝑓 𝑥2 = 𝑎 + 𝑏𝑥2 + 𝑐𝑥2
But if 𝑥0 = 0, 𝑥1 = 𝑥0 + ℎ = 0 + ℎ = ℎ, 𝑥2 = 𝑥0 + 2ℎ = 0 + 2ℎ = 2ℎ
2
𝑓 𝑥0 = 𝑎 + 𝑏𝑥0 + 𝑐𝑥0
=𝑎+𝑏 0 +𝑐 0 =𝑎 ⇒ 𝑓0 = 𝑎 Eq. (2)
I = න 𝑓 𝑥 𝑑𝑥 = න 𝑎 + 𝑏𝑥 + 𝑐𝑥 2 𝑑𝑥
𝑥0 0
2ℎ
4𝑓1 − 𝑓2 − 3𝑓0 𝑓0 − 2𝑓1 + 𝑓2 2
I = 𝑓0 + 𝑥+ 2
𝑥 𝑑𝑥
2ℎ 2ℎ
0
2ℎ 2ℎ 2ℎ
4𝑓1 − 𝑓2 − 3𝑓0 𝑓0 − 2𝑓1 + 𝑓2 2 𝑑𝑥
I = 𝑓0 න 𝑑𝑥 + න 𝑥 𝑑𝑥 + න 𝑥
2ℎ 2ℎ2
0 0 0
න 𝑓 𝑥 𝑑𝑥 = න 𝑓 𝑥 𝑑𝑥
𝑥0 𝑥0
𝑥2 𝑥4 𝑥6 𝑥2𝑚
= න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥 + ⋯ + න 𝑓 𝑥 𝑑𝑥
𝑥0 𝑥2 𝑥4 𝑥2𝑚−2
ℎ ℎ ℎ
= 𝑓0 + 4𝑓1 + 𝑓2 + 𝑓2 + 4𝑓3 + 𝑓4 + 𝑓4 + 4𝑓5 + 𝑓6 + ⋯
3 3 3
ℎ
+ 𝑓2𝑚−2 + 4𝑓2𝑚−1 + 𝑓2𝑚
3
ℎ
= 𝑓0 + 4 𝑓1 + 𝑓3 + 𝑓5 + ⋯ + 𝑓2𝑚−1 + 2 𝑓2 + 𝑓4 + 𝑓6 + ⋯ + 𝑓2𝑚−2 + 𝑓2𝑚
3
𝑥𝑛
ℎ
න 𝑓 𝑥 𝑑𝑥 = 𝑓0 + 4 𝑓1 + 𝑓3 + 𝑓5 + ⋯ + 𝑓𝑛−1 + 2 𝑓2 + 𝑓4 + 𝑓6 + ⋯ + 𝑓𝑛−2 + 𝑓𝑛
3
𝑥0
21
EXAMPLE: Use the Simpson’s 1/3 rule with 𝑛 = 4 to approximate.
1
𝑑𝑥
න
1 + 𝑥2
0
SOLUTION: Here length of each subintervals is
𝑏−𝑎 1−0 1
ℎ= = =
𝑛 4 4
The interval is
𝑥0 = 0
1 1 1 1 1
𝑥1 = 𝑥0 + ℎ = 0 + = , 𝑥2 = 𝑥1 + ℎ = + =
4 4 4 4 2
1 1 3 3 1
𝑥3 = 𝑥2 + ℎ = + = , 𝑥4 = 𝑥3 + ℎ = + = 1
2 4 4 4 4
So, Simpson’s 1/3 rule is
1
𝑑𝑥 ℎ
න 2
= 𝑓0 + 4 𝑓1 + 𝑓3 + 2𝑓2 + 𝑓4
1+𝑥 3
0 22
𝑥𝑛 1
𝑓 𝑥𝑛 =
1 + 𝑥𝑛 2
𝑥0 = 0 1 1
𝑓 𝑥𝟎 = = =1
1 + 𝑥0 2 1 + 0
1 1 1 1
𝑥1 = 𝑓 𝑥𝟏 =𝑓 = = = 0.941176
4 4 1 + 𝑥1 2 1 + 1
16
1 1 1 1
𝑥2 = 𝑓 𝑥2 = 𝑓 = = = 0.8
2 2 1 + 𝑥2 2 1 + 1
4 As we know that
3 3 1 1
𝑥3 = 𝑓 𝑥3 = 𝑓 = = = 0.64 1
4 4 1 + 𝑥3 2 1 + 9 𝑑𝑥 𝜋
16 න = 𝑎𝑟𝑐 tan 1 =
1+𝑥 2 4
0
𝑥4 = 1 1 1 1
𝑓 𝑥4 =𝑓 1 = = = = 0.5 = 0.7854
1 + 𝑥4 2 1 + 1 2
1
𝑑𝑥 ℎ
න 2
= 𝑓0 + 4 𝑓1 + 𝑓3 + 2𝑓2 + 𝑓4
1+𝑥 3
0
ℎ ℎ 1
= (1 + 4 0.941176 + 0.64 + 2 0.8 + 0.5) = 9.424704 = 9.424704
3 3 12
= 0.785392 = 0.7854 23
THEOREM: SIMPSON’S 3/8 rule
To apply this rule, the number of intervals “ 𝑛 ” must be a multiple of
3. The formula is
𝑏
න 𝑓 𝑥 𝑑𝑥
𝑎
𝑓 𝑥0 + 3(𝑓 𝑥1 + 𝑓 𝑥2 + 𝑓 𝑥4 + 𝑓 𝑥5 + 𝑓 𝑥7 + 𝑓 𝑥8 + ⋯ + 𝑓 𝑥𝑛−1 )
3ℎ
=
8
+2(𝑓 𝑥3 + 𝑓 𝑥6 + 𝑓 𝑥9 … + 𝑓 𝑥𝑛−3 ) + 𝑓 𝑥𝑛
𝑏 𝑓0 + 𝑓𝑛 + 3 𝑓1 + 𝑓2 + 𝑓4 + 𝑓5 + 𝑓7 + 𝑓8 … + 𝑓𝑛−1
3ℎ
න 𝑓 𝑥 𝑑𝑥 =
8
𝑎 +2 𝑓3 + 𝑓6 + 𝑓9 + ⋯ + 𝑓𝑛−3
𝑏−𝑎
Where, ℎ=
𝑛
HINT: To Proof this rule use cubic polynomial 𝑓 𝑥 = 𝑎𝑥 3 +𝑏𝑥 2 +𝑐𝑥 + 𝑑 and
adopt similar procedure as done in Simpson’s 1/3 rule.
(Try yourself)
24
NOTE:
1. In trapezoidal rule, 𝑓 𝑥 is a linear function of 𝑥, i.e., of the form
𝑓 𝑥 = 𝑎𝑥 + 𝑏. It is the simplest rule but least accurate.
25
EXAMPLE: Use the Simpson’s 3/8 rule to find the integral of
−𝑥 2
𝑓 𝑥 =𝑒 between the limits of 𝑎 = 0.2 and 𝑏 = 1.5. Taking
𝑛 = 3, 6, 9 𝑎𝑛𝑑 12.
SOLUTION: For 𝑛 = 3,
𝑏 − 𝑎 1.5 − 0.2 1.3 13 13
ℎ= = = = =
𝑛 3 3 3 × 10 30
2 1
𝑥0 = 0.2 = =
10 5
1 13 6 + 13 19 19 13 32
𝑥1 = 𝑥0 + ℎ = + = = , 𝑥2 = 𝑥1 + ℎ = + =
5 30 30 30 30 30 30
32 13 45
𝑥3 = 𝑥2 + ℎ = + = = 1.5
30 30 30
So, Simpson’s 3/8 rule is
1.5
−𝑥 2
3ℎ
න 𝑒 𝑑𝑥 = 𝑓0 + 3 𝑓1 + 𝑓2 + 𝑓3
8
0.2 26
2
𝑥𝑛 𝑓 𝑥𝑛 = ⅇ−𝑥𝑛
2 2
1 𝑓 𝑥𝟎 = 𝑒 −𝑥0 = 𝑒 −(0.2) = 0.960789
𝑥0 =
5
19 19 2
𝑥1 = 𝑓 𝑥𝟏 =𝑓 = 𝑒 −𝑥1 = 0.669575659
30 30
32 32
𝑥2 = 𝑓 𝑥2 = 𝑓 = 0.320530521
30 30
𝑥3 = 1.5 𝑓 𝑥3 = 𝑓 1.5 = 0.105399224
1.5
−𝑥 2
3ℎ
න 𝑒 𝑑𝑥 = 𝑓 + 3 𝑓1 + 𝑓2 + 𝑓3
8 0
0.2
3ℎ
= 0.960789 + 3 0.669575659 + 0.320530521 + 0.105399224
8
3 13
= 4.036506766 = 0.65593
8 30
27
For
𝑛=6 Ans 0.65872
𝑛=9 Ans 0.65881
𝑛 = 12 Ans 0.65882
Try yourself
28
EXERCISES
29
30
31
32
33