Numerical Methods Trapezoidal Rule
Numerical Methods Trapezoidal Rule
I would like to extend my sincere gratitude to Dr. Muhammad Jamil for his outstanding
instructions and guidance in the Advanced Mathematical Techniques (MT-441) course.
His clear and insightful lectures have greatly enhanced my understanding of advanced
numerical mathematical concepts.
Dr. Jamil's assignments, including this trapezoidal rule assignment, have been
instrumental in extending my knowledge and refining my problem-solving skills. His
dedication to teaching, expertise and lecture notes in the Advanced Mathematical
Techniques (MT-441) course have been truly inspiring.
2
Contents
Chapter 1: Introduction ................................................................................................................... 3
Numerical Integration ...................................................................................................................... 3
Trapezoidal Rule............................................................................................................................... 3
Generalized Trapezoidal Rule .......................................................................................................... 4
Chapter 2: Proof of Error in Trapezoidal Rule .................................................................................. 7
Error in Trapezoidal Rule.................................................................................................................. 7
Chapter 3: Applications of Trapezoidal Rule .................................................................................. 11
Chapter 4: Applied Engineering Problems ..................................................................................... 12
Problem 1 ....................................................................................................................................... 12
Problem 2 ....................................................................................................................................... 14
Problem 3 ....................................................................................................................................... 16
Conclusion ...................................................................................................................................... 19
References and Resources ............................................................................................................. 20
3
CHAPTER 1: INTRODUCTION
Numerical Integration
Numeric integration means numeric evaluation of definite integrals,
𝑏
𝐼 = ∫ 𝑓(𝑥) 𝑑𝑥
𝑎
Where a and b are the lower and the upper bounds of the function 𝑓(𝑥) and 𝑓(𝑥) is the
function to be integrated usually given empirically or by table of values. Geometrically I
represents the area under the curve given by 𝑓(𝑥) between the interval [𝑎, 𝑏].
We know that if 𝑓(𝑥) is such that we can determine a differentiable function 𝐹(𝑥) whose
derivative is 𝑓(𝑥), then we can evaluate 𝐼 by applying the fundamental principle of integration
𝑏
𝐼 = ∫ 𝑓(𝑥) 𝑑𝑥 = 𝐹(𝑏) − 𝐹(𝑎)
𝑎
Often the real world problems lead to the function whose analytical evaluation would be quite
difficult or even impossible or whose integrand is an empirical function given by table of values.
Numeric integration methods are obtained by the approximation of 𝑓 that can easily be
integrated between the given interval [𝑎, 𝑏].
Trapezoidal Rule
We know that definite integral is the area between curve of 𝑓(𝑥) and the x-axis. This is the
basic principle behind every numerical integration. We divide the distance between the interval
[𝑎, 𝑏] into strips and then sum the area of each strip to compute the numerical integration
of 𝑓(𝑥).
In trapezoidal rule, the area under the curve of 𝑓(𝑥) is approximated by the sequence of
vertical strips slant at the top to resemble a trapezoid.
4
h
a b
It can be observed that the area bounded between 𝑓(𝑥) and [𝑥𝑖 , 𝑥𝑖+1 ] can be given by,
𝑎+𝑏 𝑓(𝑥𝑖+1 ) + 𝑓(𝑥𝑖 )
𝐴𝑟𝑒𝑎 𝑜𝑓 𝑇𝑟𝑎𝑝𝑒𝑧𝑖𝑢𝑚 = ( )ℎ = (𝑥𝑖+1 − 𝑥𝑖 )
2 2
Also the integration of 𝑓(𝑥) between [𝑥𝑖 , 𝑥𝑖+1 ] can be approximated by,
𝑥𝑖+1
𝑓(𝑥𝑖+1 ) + 𝑓(𝑥𝑖 )
∫ 𝑓(𝑥)𝑑𝑥 ≈ (𝑥𝑖+1 − 𝑥𝑖 )
𝑥𝑖 2
5
)
)
)
)
)
)
𝑥5
𝑓(𝑥0 ) + 𝑓(𝑥1 ) 𝑓(𝑥1 ) + 𝑓(𝑥2 ) 𝑓(𝑥2 ) + 𝑓(𝑥3 ) 𝑓(𝑥3 ) + 𝑓(𝑥4 )
∫ 𝑓(𝑥)𝑑𝑥 ≈ ℎ+ ℎ+ ℎ+ ℎ
𝑥0 2 2 2 2
𝑓(𝑥4 ) + 𝑓(𝑥5 )
+ ℎ
2
Here ℎ is the width of each trapezoid,
𝑥5 − 𝑥0
ℎ=
𝑛
In general for 𝑛 sub-intervals, the area between 𝑓(𝑥) and the interval [𝑎, 𝑏] can be computed
by,
𝑥𝑛
∫ 𝑓(𝑥)𝑑𝑥 ≈ 𝐴1 + 𝐴2 +∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ + 𝐴𝑛−1 + 𝐴𝑛
𝑥0
𝑏
𝑓(𝑥0 ) + 𝑓(𝑥1 ) 𝑓(𝑥1 ) + 𝑓(𝑥2 ) 𝑓(𝑥𝑛−1 ) + 𝑓(𝑥𝑛 )
∫ 𝑓(𝑥)𝑑𝑥 ≈ ℎ+ ℎ +∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ + ℎ
𝑎 2 2 2
6
In simplified form,
𝑏
ℎ
∫ 𝑓(𝑥)𝑑𝑥 ≈ [𝑓(𝑥0 ) + 2𝑓(𝑥1 ) + 2𝑓(𝑥2 ) +∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ 2𝑓(𝑥𝑛−1 ) + 𝑓(𝑥𝑛 )]
𝑎 2
The above expression is called generalized Trapezoidal rule for 𝑛 sub-intervals and for 𝑛 + 1
points.
7
CHAPTER 2: PROOF OF ERROR IN TRAPEZOIDAL RULE
Error in Trapezoidal Rule
Consider a single interval, here 𝑎 = 𝑓(𝑥𝑖 ), 𝑏 = 𝑓(𝑥𝑖+1 ), ℎ = 𝑥𝑖+1 − 𝑥𝑖
Error bound for Trapezoidal rule,
∵ |𝑓′′(𝑥)| ≤ 𝑘 𝑓𝑜𝑟 𝑎 ≤ 𝑥 ≤ 𝑏
𝑎+𝑏 𝑓(𝑥𝑖+1 ) + 𝑓(𝑥𝑖 )
𝐴𝑟𝑒𝑎 𝑜𝑓 𝑇𝑟𝑎𝑝𝑒𝑧𝑖𝑢𝑚 = ( )ℎ = (𝑥𝑖+1 − 𝑥𝑖 )
2 2
Exact area underneath the 𝑓(𝑥),
𝑥𝑖+1 h
∫ 𝑓(𝑥)𝑑𝑥 𝑒𝑞(1)
𝑥𝑖 a b
Let 𝑡 = 𝑥 − 𝑥𝑖 , 𝑑𝑡 = 𝑑𝑥
𝑎𝑡 𝑥 = 𝑥𝑖 , 𝑡 = 0
𝑎𝑡 𝑥 = 𝑥𝑖+1 , 𝑡 = 𝑥𝑖+1 − 𝑥𝑖 = ℎ
Substituting the above values in equation 1, equation 1 becomes,
ℎ +
∫ 𝑓(𝑡 + 𝑥𝑖 )𝑑𝑡 𝑒𝑞(2)
0
∵ ∫ 𝑢𝑑𝑣 = 𝑢𝑣 − ∫ 𝑣𝑑𝑢
8
ℎ
(𝑡 + 𝑐1 )2
= 𝑓(𝑡 + 𝑥𝑖 )(𝑡 + 𝑐1 )]ℎ0 −( + 𝑐2 ) 𝑓 ′ (𝑡 + 𝑥𝑖 )|
2 0
ℎ (𝑡
+ 𝑐1 )2
+∫ ( + 𝑐2 ) 𝑓 ′′ (𝑡 + 𝑥𝑖 )𝑑𝑡 𝑒𝑞(4)
0 2
Let’s choose c1 and c2 in such a way that the exact integral is equal to trapezoidal
approximation plus error.
𝑥𝑖+1
∫ 𝑓(𝑥)𝑑𝑥 = 𝑇(𝑖) + 𝐸(𝑖) 𝑒𝑞(𝐴)
𝑥𝑖
Where T(i) is the area of 𝑖 𝑡ℎ trapezoid and the 𝐸(𝑖) is the error in the 𝑖 𝑡ℎ trapezoidal interval.
Here we want,
𝑓(𝑥𝑖+1 ) + 𝑓(𝑥𝑖 )
𝑓(𝑡 + 𝑥𝑖 )(𝑡 + 𝑐1 )]ℎ0 = (𝑥𝑖+1 − 𝑥𝑖 )
2
Substituting the limits,
𝑓(𝑥𝑖+1 ) + 𝑓(𝑥𝑖 ) ℎ𝑓(𝑥𝑖+1 ) ℎ𝑓(𝑥𝑖 )
(ℎ + 𝑐1 )𝑓(ℎ + 𝑥𝑖 ) − 𝑐1 𝑓(𝑥𝑖 ) = (𝑥𝑖+1 − 𝑥𝑖 ) = +
2 2 2
From the above equation upon comparing the terms from LHS and RHS,
ℎ
𝑐1 = −
2
Since we want to minimize the error so considering,
ℎ
(𝑡 + 𝑐1 )2
( + 𝑐2 ) 𝑓 ′ (𝑡 + 𝑥𝑖 )| = 0
2 0
ℎ 2 ℎ 2
(𝑡 − 2) (− 2)
( + 𝑐2 ) 𝑓 ′ (ℎ + 𝑥𝑖 ) − ( + 𝑐2 ) 𝑓 ′ (𝑥𝑖 ) = 0
2 2
Here the coefficients of 𝑓 ′ (ℎ + 𝑥𝑖 ) and the 𝑓 ′ (𝑥𝑖 ) are exactly the same thing, so to make the
above statement true those terms be equal to zero. Here we cannot consider the derivative
values equal to zero because the value of derivative keeps on changing depending upon the
interval.
ℎ 2
(𝑡 − 2)
+ 𝑐2 = 0
2
9
ℎ2
𝑐2 = −
8
Now consider equation (4), equation 4 becomes,
ℎ ℎ (𝑡 − )
ℎ 2
ℎ𝑓(𝑥𝑖+1 ) ℎ𝑓(𝑥𝑖 ) 2 ℎ2
= ∫ 𝑓(𝑡 + 𝑥𝑖 )𝑑𝑡 = + + ∫ ( − ) 𝑓 ′′ (𝑡 + 𝑥𝑖 )𝑑𝑡
0 2 2 0 2 8
ℎ 2
ℎ (𝑡 − 2) ℎ2
𝐸=∫ ( − ) (𝑓 ′′ (𝑡 + 𝑥0 ) + 𝑓 ′′ (𝑡 + 𝑥1 ) + ⋯ ⋯ ⋯ + 𝑓 ′′ (𝑡 + 𝑥𝑛−1 ))𝑑𝑡
0 2 8
ℎ 2
ℎ (𝑡 − 2) ℎ2
|𝐸| = ∫ | − | (|𝑓 ′′ (𝑡 + 𝑥0 )| + |𝑓 ′′ (𝑡 + 𝑥1 )| + ⋯ ⋯ ⋯ + |𝑓 ′′ (𝑡 + 𝑥𝑛−1 )|)𝑑𝑡 𝑒𝑞(5)
0 2 8
ℎ 3 ℎ 3
(ℎ − 2) ℎ 3 (− )
|𝐸| ≤ | − − [ 2 ]|
6 8 6
ℎ3 ℎ3 ℎ3
|𝐸| ≤ | − + |
48 8 48
10
2ℎ3 6ℎ3
|𝐸| ≤ | − |
48 48
𝑏−𝑎 3
ℎ3 ( 𝑛 )
|𝐸| ≤ 𝑛𝑘 = 𝑛𝑘
12 12
𝑘(𝑏 − 𝑎)3
|𝐸| ≤
12𝑛2
Error in Trapezoidal approximation can be calculated using the above formula. Where k is some
constant value representing second derivative of term in error function, b and a are the upper
and lower limits respectively and n is the number of sub- intervals.
11
CHAPTER 3: APPLICATIONS OF TRAPEZOIDAL RULE
In Engineering
Estimating the area under stress-strain curves to determine the modulus of toughness
of a material.
Calculating fluid flow in pipes and channels by numerically integrating the velocity
profile over the cross-sectional area.
Estimating the amount of heat transferred over time by integrating the heat flux rate
curve.
Estimating the work done of a thermodynamic process by numerically integrating the
pressure - volume curve.
In Physics
Determining the work done by a variable force.
Calculating the displacement of an object under a variable acceleration.
In Medicine
Analyzing the concentration of a drug in the bloodstream over time.
Estimating the blood flow of high blood pressure patients before and after some drug.
In Nuclear Physics
Estimating the energy produced by radioactive decay over time.
Estimating the radiation dose absorbed by materials or biological tissues by integrating
the dose rate over time and/or space.
12
CHAPTER 4: APPLIED ENGINEEERING PROBLEMS
1. Suppose that the upward force of air resistance on a falling object is proportional to the
square of the velocity. For this case, the velocity can be computed as
𝑔𝑚 𝑔𝑐𝑑
𝑣(𝑡) = √( ) 𝑡𝑎𝑛ℎ (√ 𝑡)
𝑐𝑑 𝑚
Data
For 𝑛 = 20, 𝑎 = 0 𝑎𝑛𝑑 𝑏 = 10
Step size,
10 − 0
ℎ= = 0.5
20
𝑔 = 9.81 𝑚/𝑠 2
𝑚 = 68.1 𝑘𝑔
𝑐𝑑 = 0.25 𝑘𝑔/𝑚
Solution
𝑔𝑚 𝑔𝑐𝑑
𝑣(𝑡) = √( ) 𝑡𝑎𝑛ℎ (√ 𝑡) 𝑒𝑞(1)
𝑐𝑑 𝑚
t 5.50 6.00 6.50 7.00 7.50 8.00 8.50 9.00 9.50 10.00
𝐭 𝐭 𝟐 𝐭 𝟑 𝐭 𝟒 𝐭 𝟓 𝐭 𝟔 𝐭 𝟕 𝐭 𝟖 𝐭 𝟗 𝐭 𝟐𝟎
v (t) 40.30 42.08 43.61 44.91 46.02 46.95 47.74 48.40 48.95 49.41
𝐯 𝐯𝟐 𝐯𝟑 𝐯𝟒 𝐯𝟓 𝐯𝟔 𝐯𝟕 𝐯𝟖 𝐯𝟗 𝐯𝟐𝟎
13
Applying Trapezoidal Rule
𝑏
ℎ
∫ 𝑓(𝑥)𝑑𝑥 ≈ [𝑓(𝑥0 ) + 2𝑓(𝑥1 ) + 2𝑓(𝑥2 ) +∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ 2𝑓(𝑥𝑛−1 ) + 𝑓(𝑥𝑛 )]
𝑎 2
10
𝑠(𝑡) = ∫ 51.67 tanh(0.19𝑡) 𝑑𝑡
0
0.5
= [0.00 + 2(4.89 + 9.70 + 14.34 + 18.74 + 22.85 + 26.63 + 30.06
2
+ 33.12 + 35.84 + 38.22 + 40.30 + 42.08 + 43.61 + 44.91 + 46.02
+ 46.95 + 47.74 + 48.40 + 48.95) + 49.41]
10
0.5
𝑣(𝑡) = ∫ 51.67 tanh(0.19𝑡) 𝑑𝑡 = [0.00 + 1286.711 + 49.41] = 334.03 meters
0 2
14
2. An 11-m beam is subjected to a load, and the shear force follows the equation
𝑉 = 5 + 0.25𝑥 2
where V is the shear force and x is length in distance along the beam. We know that
𝑑𝑀
𝑉=
𝑑𝑥
and M is the bending moment. Integration yields the relationship
𝑥
𝑀 = 𝑀0 + ∫ 𝑉𝑑𝑥
0
if 𝑀0 = 0 and 𝑥 = 11, calculate M using numeric integration (Trapezoidal Rule) for the
increment of 1 meter.
Data
For 𝑛 = 11, 𝑎 = 0 𝑎𝑛𝑑 𝑏 = 11
Step size,
11 − 0
ℎ= =1
11
Solution
Here 𝑀0 = 0
𝑏
ℎ
∫ 𝑓(𝑥)𝑑𝑥 ≈ [𝑓(𝑥0 ) + 2𝑓(𝑥1 ) + 2𝑓(𝑥2 ) +∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ 2𝑓(𝑥𝑛−1 ) + 𝑓(𝑥𝑛 )]
𝑎 2
𝐱 (𝐦) 0 1 2 3 4 5 6 7 8 9 10 11
𝐱𝟎 𝐱 𝐱𝟐 𝐱𝟑 𝐱𝟒 𝐱𝟓 𝐱𝟔 𝐱𝟕 𝐱𝟖 𝐱𝟗 𝐱 𝟎 𝐱
𝐕 (𝐍) 5.00 5.25 6.00 7.25 9.00 11.25 14.00 17.25 21.00 25.25 30.00 35.25
𝐕𝟎 𝐕 𝐕𝟐 𝐕𝟑 𝐕𝟒 𝐕𝟓 𝐕𝟔 𝐕𝟕 𝐕𝟖 𝐕𝟗 𝐕𝟎 𝐕
11
M = M0 + ∫ (5 + 0.25x 2 )dx
0
1
= [5.00 + 2(5.25 + 6.00 + 7.25 + 9.00 + 11.25 + 14.00 + 17.25 + + 21.00 + 25.25
2
+ 30.00) + 35.25]
11
1
M = M0 + ∫ (5 + 0.25x 2 )dx = [5.00 + 292.5 + 35.25] = 166.375 𝑁𝑚
0 2
15
Percentage Error in Trapezoidal Rule
16
3. A cross section of a racing sailboat is shown. Wind forces (f) exerted per foot of mast
from the sails vary as a function of distance above the deck of the boat (z). Calculate the
tensile force T in the left mast support cable, assuming that the right support cable is
completely slack and the mast joins the deck in a manner that transmits horizontal or
vertical forces but no moments. Assume that the mast remains vertical.
Data
For 𝑛 = 10, 𝑎 = 0𝑓𝑡 𝑎𝑛𝑑 𝑏 = 30𝑓𝑡
Step size,
30 − 0
ℎ= =2
15
Solution
The total force exerted on the mast can be expressed as the integral of continuous function,
30 30
𝑧 −2𝑧
𝐹𝑅 (𝑧) = ∫ 𝑓(𝑧)𝑑𝑧 = ∫ 200 ( ) 𝑒 30 𝑑𝑧
0 0 5+𝑧
17
𝐳 0 2 4 6 8 10 12 14
(𝐟𝐭) 𝐳𝟎 𝐳 𝐳𝟐 𝐳𝟑 𝐳𝟒 𝐳𝟓 𝐳𝟔 𝐳𝟕
𝐟 (𝐥𝐛/𝐟𝐭) 0.00 50.01 68.08 73.13 72.20 68.46 63.43 57.95
𝐟𝟎 𝐟 𝐟𝟐 𝐟𝟑 𝐟𝟒 𝐟𝟓 𝐟𝟔 𝐟𝟕
𝑭 0.00 100.02 272.33 438.75 577.62 684.56 761.22 811.32
(𝒍𝒃) 𝐅𝟎 𝐅 𝐅𝟐 𝐅𝟑 𝐅𝟒 𝐅𝟓 𝐅𝟔 𝐅𝟕
𝐳 16 18 20 22 24 26 28 30
(𝐟𝐭) 𝐳𝟖 𝐳𝟗 𝐳 𝟎 𝐳 𝐳 𝟐 𝐳 𝟑 𝐳 𝟒 𝐳 𝟓
𝐟 (𝐥𝐛/𝐟𝐭) 52.44 47.14 42.18 37.59 33.42 29.64 26.24 23.20
𝐟𝟖 𝐟𝟗 𝐟𝟎 𝐟 𝐟𝟐 𝐟𝟑 𝐟𝟒 𝐟𝟓
𝑭 839.0 848.58 843.51 827.08 802.02 770.62 734.77 696.01
(𝒍𝒃) 8 𝐅𝟗 𝐅𝟎 𝐅 𝐅𝟐 𝐅𝟑 𝐅𝟒 𝐅𝟓
𝐅𝟖
Applying the principle of moments at the base of the mast for the moment caused by the wind
force,
↷ + (𝑀𝑅 ) = ∑ 𝑀
30
𝑑̅ 𝐹𝑅 = ∫ 𝑧𝑓(𝑧)𝑑𝑧
0
30
∫0 𝑧𝑓(𝑧)𝑑𝑧
𝑑̅ = 30 𝑒𝑞 (1)
∫0 𝑓(𝑧)𝑑𝑧
30
𝐹𝑜𝑟 ∫ 𝑓(𝑧)𝑑𝑧,
0
18
Percentage Error in Trapezoidal Rule
|𝑽𝑻 − 𝑽𝑨 | | 𝟒𝟖𝟎. 𝟓𝟕 − 𝟒𝟔𝟕. 𝟎𝟑|
𝑬𝒑 = × 𝟎𝟎 = × 𝟎𝟎 = 𝟎. 𝟗 %
𝑽𝑻 𝟒𝟖𝟎. 𝟓𝟕
30
𝐹𝑜𝑟 ∫ 𝑧𝑓(𝑧)𝑑𝑧,
0
30 30
Substituting the values of ∫0 𝑧𝑓(𝑧)𝑑𝑧 and ∫0 𝑓(𝑧)𝑑𝑧 in equation (1)
∑ +→ 𝐹𝑥 = 𝐹 − 𝑇𝑠𝑖𝑛𝜃 − 𝐻 = 0 𝑒𝑞(2)
∑ +↑ 𝐹𝑦 = 𝑉 − 𝑇𝑐𝑜𝑠𝜃 = 0 𝑒𝑞(3)
19
Where H, V, T and F are support reactions, tension in the cable and
wind force respectively.
3
𝜃 = tan−1 ( ) = 0.1ᵒ
30
From eq (4),
Conclusion
From the above three applied engineering problems it can be concluded that the exact
integrals of respective problems can successfully be approximated by Trapezoidal rule of
numerical integration.
The percentage error in the approximation is
The accuracy in the answer can be increased if the number of n-sub intervals increases
or the h-width of sub intervals decreases.
20
References and Resources
Applied Numerical Analysis Book by Curtis Gerald and Patrick O. Wheatley 7th Edition
Numerical Methods for Engineers Book by Raymond P. Canale and Steven C. Chapra 7th
edition
21