03 Integration Methods
03 Integration Methods
3
Integrating Numerically Using Trapezoidal and Simpson’s Rules
1. Objective
The activity aims to introduce the Trapezoidal and Simpson’s Rules concepts and application through
computing for getting the integral of equations.
2. Intended Learning Outcomes (ILOs)
The students should be able to:
2.1 Explain the concept of Trapezoidal and Simpson’s rules in integrating systems of equations.
2.2 Create programs through computing tools for trapezoidal and simpson’s rules.
2.3 Perform integration through Trapezoidal and Simpson’s rules.
3. Discussion
The area can be found by adding slices that approach zero in width:
And there are Rules of Integration that help us get the answer.
Notation
The symbol for "Integral" is a stylish "S"
(for "Sum", the idea of summing slices):
After the Integral Symbol we put the function we want to find the integral of (called the Integrand),
and then finish with dx to mean the slices go in the x direction (and approach zero in width).
Definite Integral
A Definite Integral has started and end values: in other words there is an interval (a to b). The
values are put at the bottom and top of the "S", like this:
Indefinite Integral Definite Integral
(no specific values) (from a to b)
We can find the Definite Integral by calculating the Indefinite Integral at points a and b, then subtracting:
Example 1:
The Definite Integral, from 1 to 2, of 2xdx:
Subtract:
(22 + C) − (12 + C)
22 + C − 12 − C
3 −1+C−C=3
4
And "C" gets cancelled out ... so with Definite Integrals we can ignore C.
In fact we can give the answer directly like this:
Example 2:
The Definite Integral, from 0.5 to 1.0, of cos(x)dx:
= sin(1) − sin(0.5)
= 0.841... − 0.479...
= 0.362...
Example 3:
The Definite Integral, from 0 to 1, of sin(x)dx:
The Indefinite Integral is: ∫sin(x) dx = −cos(x) + C. Since we are going from 0, can we just calculate
the area at x=1? −cos(1) = −0.540...What? The Area at x=1 is negative? No, we need to subtract
the integral at x=0. We shouldn't assume that it is zero. So let us do it properly, subtracting one
from the other (and C gets cancelled so we don't need to show it):
= −cos(1) − (−cos(0))
= −0.540... − (−1)
= 0.460...
Example 4:
The Definite Integral, from 1 to 3, of cos(x) dx:
Notice that some of it is positive, and some negative. The definite integral will work out the net
area. The Indefinite Integral is: ∫cos(x) dx = sin(x) + C. So let us do the calculations:
= sin(3) − sin(1)
= 0.141... − 0.841...
= −0.700...
Properties
Reversing the interval
Reversing the direction of the interval gives the negative of the original direction.
When the interval starts and ends at the same place, the result is zero:
Adding intervals
We can also add two adjacent intervals together:
Finding definite integrals of certain equations may vary and may not be accurate. As a resort, numerical
methods were developed by mathematicians. The most common of these methods are the Trapezoidal and
Simpson’s Rules.
Recall that we write "Δx" to mean "a small change in x". Now, the area of a trapezoid (trapezium) is
given by:
ℎ
𝐴𝑟𝑒𝑎 = (𝑝 + 𝑞)
2
So the approximate area under the curve is found by adding the area of the trapezoids. (Our
trapezoids are rotated 90° so that their new base is actually the height. So h = Δx.)
𝑦0 𝑦𝑛
𝐴𝑟𝑒𝑎 ≈ ∆𝑥( + 𝑦1 + 𝑦2 + 𝑦3 + ⋯ + )
2 2
Example 5:
Using n=5, approximate the integral.
1
∫ √𝑥 2 + 1𝑑𝑥
0
Solution to Example 5:
I have joined each of the points at the top of the vertical segments with a straight line. Here, a = 0
and b =1, and the width of each trapezoid is given by:
𝑏−𝑎 1−0
∆𝑥 = = = 0.2
𝑛 5
𝑦0 = 𝑓(𝑎) = 𝑓(0) = √02 + 1 = 1
𝑦1 = 𝑓(𝑎 + ∆𝑥) = 𝑓(0.2) = √0.22 + 1 = 1.0198039
𝑦2 = 𝑓(𝑎 + 2∆𝑥) = 𝑓(0.4) = √0.42 + 1 = 1.0770330
𝑦3 = 𝑓(𝑎 + 3∆𝑥) = 𝑓(0.6) = √0.62 + 1 = 1.1661904
𝑦4 = 𝑓(𝑎 + 4∆𝑥) = 𝑓(0.8) = √0.82 + 1 = 1.2806248
𝑦5 = 𝑓(𝑎 + 5∆𝑥) = 𝑓(1.0) = √1.02 + 1 = 1.4142136
So we have:
Integral ≈
1 1
0.2 ( × 1 + 1.0198039 + 1.0770330 + 1.1661904 + 1.2806248 + × 1.4142136)
2 2
= 𝟏. 𝟏𝟓𝟎
So
1
∫ √𝑥 2 + 1𝑑𝑥 ≈ 1.150
0
We can see in the graph above the trapezoids are very close to the original curve, so our
approximation should be close to the real value. In fact, to 3 decimal places, the integral value is
1.148.
In Simpson’s rule, we will use parabolas to approximate each part of the curve. This proves to be
very efficient since it’s generally more accurate than the other numerical methods we’ve seen.
We divide the area into n equal segments of width ∆x. The approximate area is given by the
following.
𝑏
∆𝑥
𝐴𝑟𝑒𝑎 = ∫ 𝑓(𝑥)𝑑𝑥 ≈ (𝑦0 + 4𝑦1 + 2𝑦2 + 4𝑦3 + 2𝑦4 … + 4𝑦(𝑛 − 1) + 𝑦𝑛); 𝑤ℎ𝑒𝑟𝑒 ∆𝑥
𝑎 3
(𝑏 − 𝑎)
=
𝑛
The above formula might be a little tricky to be memorized. Hence we may simplify it as shown
below.
𝑏
∆𝑥
∫ 𝑓(𝑥)𝑑𝑥 ≈ (𝑦0 + 4(𝑦1 + 𝑦3 + 𝑦5 + ⋯ ) + 2(𝑦2 + 𝑦4 + 𝑦6 + ⋯ ) + 𝑦𝑛)
𝑎 3
𝒃
∆𝒙
∫ 𝒇(𝒙)𝒅𝒙 ≈ (𝑭𝑰𝑹𝑺𝑻 + 𝟒(𝒔𝒖𝒎 𝒐𝒇 𝑶𝑫𝑫𝒔) + 𝟐(𝒔𝒖𝒎 𝒐𝒇 𝑬𝑽𝑬𝑵𝒔) + 𝑳𝑨𝑺𝑻)
𝒂 𝟑
Example 6:
3 𝑑𝑥
Approximate ∫2 using Simpson’s Rule with n=4.
𝑥+1
Answer to Example 6:
𝑏−𝑎 3−2
∆𝑥 = = = 0.25
𝑛 4
1
𝑦0 = 𝑓(𝑎) = 𝑓(2) = = 0.3333333
2+1
1
𝑦1 = 𝑓(𝑎 + ∆𝑥) = 𝑓(2.25) = = 0.3076923
2.25 + 1
1
𝑦2 = 𝑓(𝑎 + 2∆𝑥) = 𝑓(2.5) = = 0.2857142
2.5 + 1
1
𝑦3 = 𝑓(𝑎 + 3∆𝑥) = 𝑓(2.75) = = 0.2666667
2.75 + 1
1
𝑦4 = 𝑓(𝑏) = 𝑓(3) = = 0.25
3+1
So
𝑏
𝐴𝑟𝑒𝑎 = ∫ 𝑓(𝑥)𝑑𝑥
𝑎
0.25
≈ (0.3333333 + 4(0.3076923) + 2(0.2857142)
3
+ 4(0.26666667) + 0.25) = 0.2876831
Notes
1. The actual answer to this problem is 0.287682 (to 6 decimal places) so our Simpson's Rule
approximation has an error of only 0.00036%.
2. In this example, the curve is very nearly parabolic, so the 2 parabolas shown above
1
practically merge with the curve 𝑦 = 𝑥+1.
4. Resources:
The students shall be able to:
4.1 A personal computer with installed operating system
4.2 A Spreadsheet software
4.3 A C/C++ IDE or Matlab (or any equivalent tool)
4.4 Knowledge in C/C++ programming.
5. Procedure:
1. Using either spreadsheet software or any C/C++ IDE, create a program that follows the step-by-
step procedure of solving areas under a curve of certain equation. Instead of using definite
integrals, use Trapezoidal and Simpson’s Rules.
2. After creating the program(s) for Trapezoidal and Simpson’s Rules, solve the following integrals
below:
4
a. Approximate ∫0 𝑥 2 𝑑𝑥 using the Trapezoidal and Simpson’s rule with n=8 and n=4
subintervals.
Simpson’s Rule
**Insert your source code here.**
TO DO: Differentiate the results of Trapezoidal and Simpson Rules based from the output above and
explain briefly in 2-3 sentences.
7. Reflection:
**Insert your reflection here**
8. Assessment:
(Engineering Programs)
Student Outcome (d1): Design and conduct experiments, as well as to analyze, and interpret data, and synthesize information to provide valid conclusions for
Total Score 0
Mean Score = (Total Score/3) 0
Percentage Score = (Total Score / 9) x 100 0
Evaluated by:
Engr. Marwin B. Alejo
_______________________________________ ____________________
QUESTION ANSWER
3. What is your It gives a better approximation of the area under a curve. The approximation becomes more
observation of accurate as the resolution of the partition increases. When the partition has a regular spacing,
Trapezoidal Rule? as is often the case, the formula can be simplified for calculation efficiency.
ℎ
𝐴𝑟𝑒𝑎 = (𝑝 + 𝑞)
2
So the approximate area under the curve is found by adding the area of the
trapezoids. (Our trapezoids are rotated 90° so that their new base is actually the
height. So h = Δx.)
𝑦0 𝑦𝑛
𝐴𝑟𝑒𝑎 ≈ ∆𝑥( + 𝑦1 + 𝑦2 + 𝑦3 + ⋯ + )
2 2
4. Write an equation
of Trapezoidal To find ∆x for the area from x = a to x=b, we use:
Rule? 𝑏−𝑎
∆𝑥 =
𝑛
1 1 2
For definite integrals such as ∫0 √1 − 𝑥 3 𝑑𝑥 or ∫0 𝑒 −𝑥 𝑑𝑥
5. Which formula is The trapezoidal rule is a numerical method that approximates the value of a definite
used in integral. We consider the definite integral
Trapezoidal Rule? 𝑏
∫ 𝑓(𝑥)𝑑𝑥
𝑎
TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES
938 Aurora Boulevard, Cubao, Quezon City
QUESTION ANSWER
1. What is
Simpson's rule is a method for numerical integration, the numerical approximation of definite
Simpson’s 1/3
integrals.
Rule?
Simpson's rule actually gives exact results when approximating integrals of polynomials up to
3. Write an
cubic degree. Simpson's rule gains an extra order because the points at which the integrand is
observation about
evaluated are distributed symmetrically in the interval. The fourth derivative of such a
Simpson’s Rule.
polynomial is zero at all points.
𝑏
∆𝑥
4. Write down ∫ 𝑓(𝑥)𝑑𝑥 ≈ (𝑦0 + 4(𝑦1 + 𝑦3 + 𝑦5 + ⋯ ) + 2(𝑦2 + 𝑦4 + 𝑦6 + ⋯ ) + 𝑦𝑛)
Simpson’s Rule. 𝑎 3
5. Simpson’s Rule is
applied on which End points a and b and the midpoint.
point of parabola?