Integration/3.Trapeziodal rule

Investigating integration from first principles using Excel
𝑏
The definite integral βˆ«π‘Ž 𝑓(π‘₯) 𝑑π‘₯ equals the area between the function 𝑓(π‘₯) and the x-axis (where
𝑏
any area above the x-axis is positive and the area below is negative). This is because βˆ«π‘Ž 𝑓(π‘₯) 𝑑π‘₯ is
defined to be the limit of a sum of the areas of rectangles between the function and the x-axis as the
number of rectangles approaches infinity. There are a few different ways to choose the height of
each rectangle, for example should the left or right corner touch the graph of the function?
1) Above is the graph of 𝑦 = π‘₯ 2 with five rectangles between 0 and 5. Draw the same except
let the left corner of the rectangle touch the graph of the function. Which of these is an
over- or under-estimate to the exact area under the curve?
Given that generally we get an over-estimate from one choice and an underestimate from the other,
it should make sense to take the average of these two areas (to get a better approximation). Taking
the average of the areas of the two rectangles is the same as using the area of the trapezium as
shown below. Recall that the area of a trapezium is the base length times the average of the heights.
With a finite number of rectangles or trapezia you will usually only get an approximation for the area
under a curve, to get better accuracy you need to increase the number of rectangles or trapezia (this
means the width of each rectangle/trapezia has to decrease too).
2) In the figures below which is a better approximation for the area under the curve, 4
rectangles or 8?
The more rectangles/trapezia we use the closer we get to the true area under the curve. We would
like to choose the biggest number we know and used that; we would like to use infinity if we could!
We can examine what happens to the area as the number of rectangles/trapezia approaches infinity
(i.e. gets larger and larger), this should settle to a limit.
Open the Excel file β€˜Trapezoidal rule’.
This spreadsheet is currently set up to use the trapezoidal rule to approximate the area under 𝑦 =
π‘₯ 3 between a start point (a) and an end point (b) with 10 trapezia. First change the start and end
point values and the number of trapezia to see what changes.
Notice the list changes length as you change the number of trapezia. To get
this to happen the spreadsheet uses a lot of IF() statements, these work in the
following way:
IF(β€œa logic statement that could be true or false”, β€œvalue if true”, β€œvalue if
false”)
A cubic function
3) The design of this spreadsheet means that you should not ask for more than 10 000 trapezia.
What happens when more than 10 000 is used?
4) Use the spreadsheet to get a good approximation to the area between 𝑦 = π‘₯ 3 and the x-axis
when x is between 0 and 1.
1
5) If you know how to integrate, calculate ∫0 π‘₯ 3 𝑑π‘₯ and compare this to your answer above.
6) Integration is defined in such a way that swapping the limits of integration will change the
𝑏
π‘Ž
sign of the integral, i.e. βˆ«π‘Ž 𝑓(π‘₯) 𝑑π‘₯ = βˆ’ βˆ«π‘ 𝑓(π‘₯) 𝑑π‘₯ . Can this be seen using the
spreadsheet?
7) Integration is defined in such a way that if the limits of integration are the same the integral
π‘Ž
will be zero, i.e. βˆ«π‘Ž 𝑓(π‘₯) 𝑑π‘₯ = 0. Can this be seen using the spreadsheet?
A polynomial function
Let’s change the function we are numerically integrating to 𝑦 = βˆ’2π‘₯ 4 + 4π‘₯ 3 βˆ’ π‘₯ + 3. Before you
have made any changes, the formula in the D6 cell should be =IF(A6>0,B6^3,0). Here B6 is our input
or x value, and the ^3 gives us π‘₯ 3 as required.
Step 1: Since B6 is our x, in the cell D6 we replace B6^3 with -2*B6^4+4*B6 ^3-B6+3 and hit enter.
Step 2: Click back onto D6, and to fill down, double click on the bottom right corner of the D6 cell.
Step 3: The above steps must be repeated for E6, except this function’s input or x value is C6.
1
8) Approximate βˆ«βˆ’1 βˆ’2π‘₯ 4 + 4π‘₯ 3 βˆ’ π‘₯ + 3 𝑑π‘₯ for n trapezia and fill in the following table
n
Approx
1
10
100
1 000
10 000
1
9) From the above what do you think the integral βˆ«βˆ’1 βˆ’2π‘₯ 4 + 4π‘₯ 3 βˆ’ π‘₯ + 3 𝑑π‘₯ should evaluate
to? Check your answer if you know how to integrate.
10) Play around with the start and end points. There are two x intercepts for this polynomial.
You will not be able to find them exactly but try to find an approximation for them by
noticing when the area starts to decrease. To get a better approximation use more trapezia.
Other functions
Excel has other functions programmed into it, for example the exponential
EXP(), the natural logarithm LN(), the base ten log LOG10(), the log of base b
LOG() , sine SIN(), cosine COS(), tangent TAN(), just to name a few that you
should know.
Change the formulas for the left and right heights to return EXP(x), where x is B6 or C6, as discussed
in the above three steps.
1
11) Fill out the following to approximate ∫0 𝑒 π‘₯ 𝑑π‘₯ and compare this to the exact answer.
n
Approx
1
10
100
1 000
10 000
Change the formulas for the left and right heights to return COS(x), where x is B6 or C6, as discussed
in the above three steps.
πœ‹
12) Find an approximation for ∫0 cos(π‘₯) 𝑑π‘₯ does this agree with your thoughts? Recall πœ‹ is
written in Excel as =PI().
In the above question it is necessary to type the equals sign. The
equals sign forces Excel to interpret the input as an equation or a
number instead of just text.
13) Find a good approximation for
πœ‹
2
∫ cos(π‘₯) 𝑑π‘₯
πœ‹
–2
Teacher Resource
Investigating integration from first principles using Excel
1. The rectangles that touch on the left corner will be an underestimate of the area under the
curve and the rectangles that touch on the right will be an over-estimate.
2. Eight rectangles is a closer fit to the curve, there is less white space between the rectangles
and the curve when we use larger numbers and hence eight rectangles give a better
approximation that four.
3. Each trapezium that is added after 10 000 reduces the area given away from its true value
and approaches 0. Notice with one million trapezia the area given is quite close to zero.
4. Approximately 0.250000003
5. The integral evaluates to be 0.25 which is quite close to the above.
6. Yes
7. Yes
8. The first x-intercept is around -0.87669 and the second is around 2.05451 (students should
NOT try to get this level of accuracy though)
9.
n
1
10
100
1 000
10 000
5.199466688
5.199994667
5.199999947
Approx
2
5.14688
10. It appears to converge to 5.2 and integration confirms this.
11.
n
1
10
100
1 000
10 000
Approx
1.859140914 1.719713491 1.718296147 1.718281972 1.71828183
1
Since ∫0 𝑒 π‘₯ 𝑑π‘₯ = 𝑒 βˆ’ 1 β‰ˆ 1.7182818284590I think Excel gave us a good approximation.
12. Excel will tell you the area is zero for small numbers of trapezia and return numbers very
close to zero for larger numbers of trapezia. From a graph of cosine it is clear the area above
the x-axis and the area below the x-axis are the same, and hence the integral evaluates to
zero.
13. It appears the area is converging to 2 square units. Which I think is quite nice!