Professional Documents
Culture Documents
Course ID EEE-314L
Student ID 1711396
Experiment No: 07
Experiment Name: Study on finding the value of a definite integral using the trapezoidal rule.
Objectives:
➢ To get introduced with basic MATLAB commands for approximating the definite integral using the
trapezoidal rule.
➢ Performing the algorithm on given examples.
➢ Verify MATLAB output with the theoretical hand calculations.
Apparatus:
➢ MATLAB
• Definite Integral
Equations:
𝒃 𝑁
ℎ
∫ 𝑓(𝑥) 𝑑𝑥 = ∑(𝑓(𝑥𝑘−1 ) + 𝑓(𝑥𝑘 ))
𝒂 2
𝑘=1
ℎ
= (𝑓(𝑥0 ) + 2𝑓(𝑥1 ) + 2𝑓(𝑥2 ) + 2𝑓(𝑥3 ) + ⋯ + 2𝑓(𝑥𝑁−1 ) + 𝑓(𝑥𝑁 ))
2
𝑓(𝑥𝑁 ) + 𝑓(𝑥0 )
= ℎ (𝑓(𝑥1 ) + 𝑓(𝑥2 ) + 𝑓(𝑥3 ) + ⋯ + 𝑓(𝑥𝑁−1 ) + ( ))
2
𝑁−1
𝑓(𝑥𝑁 ) + 𝑓(𝑥0 )
= ℎ (∑ 𝑓(𝑥𝑘 ) + )
2
𝑘=1
Here,
𝑏−𝑎
h = Step size = 𝑁
N = Number of Steps
MATLAB Code:
Experiments:
Write down appropriate MATLAB code to Find the value of the following Integrals using the trapezoidal rule.
a) 𝑦 = 𝑥𝑠𝑖𝑛𝑥
b) 𝑦 = 𝑥 + 𝑐𝑜𝑠𝑥
c) 𝑦 = 3𝑥 2 +𝑥 5
d) 𝑦 = 4𝑥 3
Limits 0 to 4 and points, N = 5, 20, 100
a) y=xsinx
N=5
N=20
N=100
b) y=x+cosx
N=5
N=20
N=100
c) y=3x2+x5
N=5
N=20
N=100
d) y=4x3
N=5
N=20
N=100
Calculation:
Do the handwritten calculation for all the equations when N = 5.
Result:
266.24 266.24 0%
Discussion:
The conventional command for the trapezoid rule in MATLAB differs slightly from the standard
expression. In conventional mathematics, the endpoints are the X coordinates that are used to
locate the points Y. The Trapezoid equation is then used to integrate all of the points to produce
the area.
The function of y is initially denoted by the integrals of y in MATLAB commands. Limits are
then stated with N points, and step size h is determined using them. "X" represents the endpoints
that begin at a and end at b. The trapezoid equation with integral solutions for the a and b points
is denoted by the letter "T." Beginning the subsequent for loop, MATLAB automatically handles
shifting the value of I to the next member of the vector by indicating it with a limit. "T" in a for
loop corresponds to the answers for the I loop's modifying y and T before. The first endpoint of a
limit in the I loop is x0(i).
Trapezodial_integral gives the solution for actual area which we find theoretically and
Exact_integral gives the actual area of integration. We can also verify our coded answers with
MATLAB default Trapezoid function.
LAB REPORT RUBRICS
Result and Analyzed and Intermediate The results are Intermediate The results are
analysis (25%) interpreted the results between analyzed to some between novice analyzed poorly
properly using the developing extent according and developing. due to
converter parameters. and to specified incomplete
accomplished. requirements. simulation.
Sub Total 80
Deduction for late
submission / any
other issue
Total (100%)
10% of Total