Numerical Integration: 1) The Trapezoidal Rule
Numerical Integration: 1) The Trapezoidal Rule
The integral of 𝑃1 𝑥 over [a, b] is the area of the shaded trapezoidal shown in fig. below; it is given by:
𝑓 𝑎 +𝑓(𝑏)
𝑇1 𝑓 = 𝑏 − 𝑎 y
2
x
a b
Example1:
1 𝑑𝑥
Approximate the integral 𝐼 = 0 1+𝑥
.
Solution:
1
The true value is 𝐼 = ln(1 + 𝑥) = 0.69314
0
𝑓 𝑎 + 𝑓(𝑏)
𝑇1 𝑓 = 𝑏 − 𝑎
2
1 1
+
𝑇1 = (1 − 0) 1 + 0 1 + 1
2
1
1+2
𝑇1 =
2
3
𝑇1 = 2
2
𝑇1 = 0.75
The actual error is 𝐼 − 𝑇1 = −0.0569
To improve on the approximation 𝑇1 𝑓 when f(x) is not a nearly linear function on [a, b], break the interval into smaller
𝑓 𝑎 −𝑓(𝑏)
subintervals and apply 𝑇1 𝑓 = 𝑏 − 𝑎 on each subinterval. If the subintervals are small enough, then f(x)
2
4 𝑑𝑥 4
Solution: 𝐼= 0 1+𝑥 2
= tan−1 ( 𝑥)
0
= tan−1 4 − tan−1 0 = 1.325817664
n=2
𝑏−𝑎 4−0
ℎ= 𝑛
= 2
= 2; 𝒙𝟎 = 𝟎, 𝒙𝟏 = 𝟐, 𝒙𝟐 = 𝟒
𝒇 𝒙𝟎 𝒇 𝒙𝒏
𝑻𝒏 𝒇 = 𝒉. + 𝒇 𝒙𝟏 + 𝒇 𝒙𝟐 + ⋯ + 𝒇 𝒙𝒏−𝟏 +
𝟐 𝟐
𝑓 𝑥0 𝑓 𝑥2
𝑇2 𝑓 = 2 + 𝑓 𝑥1 +
2 2
𝑓 0 𝑓 4
𝑇2 𝑓 = 2 +𝑓 2 +
2 2
1 1 1
=2 + + n Actual error
2 5 17 ∗ 2
=1.458823529 2 −1.33005 ∗ 10−1
4 -3.59 ∗ 10−3
Actual error = I - 𝑇2 𝑓 = −0.133005865 = −1.33005 𝑒 − 1
16 1.44 ∗ 10−4
Similarly for n = 4
32 3.6 ∗ 10−5
Actual error = -3.59 e – 3
64 9.01 ∗ 10−6
𝑛 ∝ 𝑎𝑐𝑐𝑢𝑟𝑎𝑐𝑦 128 2.25 ∗ 10−6
1
𝑛∝
𝑎𝑐𝑡𝑢𝑎𝑙 𝑒𝑟𝑟𝑜𝑟