# Lesson Video: Numerical Integration: The Trapezoidal Rule Mathematics • Higher Education

In this video, we will learn how to approximate definite integrals using the trapezoidal rule and estimate the error when using it.

15:37

### Video Transcript

In this video, we’ll learn how to approximate definite integrals using the trapezoidal rule and estimate the error when using it. You’ve probably already seen that the exact area between a curve and the 𝑥-axis can be found by performing a definite integral of the function that describes that curve between the two points you’re interested in. When approximating the integrals and therefore the area, we commonly use rectangles. These are known as midpoint sums and Riemann sums. In this video, we’re going to investigate how using trapezoids can actually often give a better approximation than rectangular sums that use the same number of subdivisions. And then derive a formula for what is commonly known as the trapezoidal rule.

Let’s imagine we’re wanting to approximate the area between the curve given by the function 𝑓 of 𝑥 equals eight minus two 𝑥 squared plus three 𝑥 and the 𝑥-axis. Bounded by the lines given by 𝑥 equals zero and 𝑥 equals two. At this point, we have a few different methods. We might use a midpoint sum, whereby we break the area up into rectangles. Let’s say two of these and to find the height of the rectangle as the value of the function at the midpoint of each interval. Well, that is one method. But let’s consider the shape of the curve. Wouldn’t it make sense to choose a different shape than a rectangle? Well, we can actually try trapezoids.

Let’s assume we want to use four subintervals now. Our trapezoids would look a little something like this. Notice that this does indeed appear to give a better approximation than using rectangles. And we can use the formula for the area of the trapezoid to calculate the total area between the curve and the 𝑥-axis. This is a half times 𝑎 plus 𝑏 times ℎ. Where 𝑎 and 𝑏 are the lengths of the parallel sides of the trapezoid. And ℎ is the height between them. We can see by observation that the height of each of our trapezoids is equal to the width of the subinterval. Here, that’s 0.5 units.

We can use the equation of our curve to work out the lengths of each of the parallel sides. And it can be useful to include a table at this stage. Somewhat counterintuitively with four subintervals, we’ll have five columns. And in fact, that’s always the case. We will always have one more column than the number of subintervals. The length of the first parallel side in the first trapezoid is given by 𝑓 of zero. That’s eight minus two times zero squared plus three times zero, which is eight. The second parallel side in this first trapezoid is eight minus two times 0.5 squared plus three times 0.5, which is nine. 𝑓 of one is eight minus two times one squared plus three times one, which, despite a poorly drawn graph, is also nine. And in a similar way, we obtain 𝑓 of 1.5 to be this height here. And that’s eight. And 𝑓 of two to be this height here. And that’s six.

We’ll now calculate the area of each of the trapezoids. The first trapezoid has an area of a half times eight plus nine times 0.5, which is 4.25 square units. The second has an area of a half times nine plus nine times 0.5, which is 4.5 square units. The third has an area of a half times nine plus eight times 0.5, which is once again 4.25. And our final trapezoid has an area of a half times eight plus six times 0.5, which is 3.5 square units. The sum of these is 16.5. And we know that we commonly use definite integration to evaluate the area under the curve. So we can say that an approximation to the definite integral evaluated between zero and two of eight minus two 𝑥 squared plus three 𝑥 is equal to 16.5. Well, this is all fine and well. But you might be thinking, surely there must be a quicker way of performing this calculation. And you’d be in luck; there is. Let’s take a generic function 𝑓 of 𝑥 and split it into 𝑛 subintervals.

We’ll say that the height of each trapezium is Δ𝑥. We saw that the lengths of the parallel sides of the first trapezoid are found by substituting our first value of 𝑥 and our second value of 𝑥 into the function. So we can say that 𝑎 one is equal to a half times 𝑓 of 𝑥 nought plus 𝑓 of 𝑥 one times Δ𝑥. Similarly, our second trapezoid will have an area of a half times 𝑓 of 𝑥 one plus 𝑓 of 𝑥 two times Δ𝑥. Our third will have an area of a half times 𝑓 of 𝑥 two plus 𝑓 of 𝑥 three times Δ𝑥. And only continue until the 𝑛th trapezoid, which will have an area of a half times 𝑓 of 𝑥 𝑛 minus one plus 𝑓 of 𝑥 𝑛 times Δ𝑥.

The total area under the curve and therefore an estimate for the definite integral of 𝑓 of 𝑥 between the first 𝑥-value and the last 𝑥-value is the sum of these. When finding their sum, we can factor a half and Δ𝑥. And we obtain the total area of the trapezoids to be Δ𝑥 over two times 𝑓 of 𝑥 nought plus 𝑓 of 𝑥 one plus another 𝑓 of 𝑥 one. Plus all the way up to 𝑓 of 𝑥 𝑛 minus one plus another 𝑓 of 𝑥 𝑛 minus one plus 𝑓 of 𝑥 𝑛.

Now we can simplify this a little further to obtain the general formula for the trapezoid rule using 𝑛 subintervals. We combine all the 𝑓 of 𝑥 ones, all the 𝑓 of 𝑥 twos, all the way through to all the 𝑓 of 𝑥 𝑛 minus ones. The rule is Δ𝑥 over two times 𝑓 of 𝑥 nought plus 𝑓 of 𝑥 𝑛 plus two times everything else. 𝑓 of 𝑥 one plus 𝑓 of 𝑥 two all the way through to 𝑓 of 𝑥 𝑛 minus one. And Δ𝑥 can be obtained really easily. It’s 𝑏 minus 𝑎 divided by 𝑛, where 𝑎 and 𝑏 are the beginning and end of our interval. And our values for 𝑥 subscript 𝑖 are found by adding 𝑖 lots of Δ𝑥 to the lower limit of our interval. That’s 𝑎 plus 𝑖Δ𝑥. We’re now going to have a look at the application of this rule.

Use the trapezoidal rule to estimate the definite integral between zero and two of 𝑥 cubed with respect to 𝑥 using four subintervals.

Remember, the trapezoidal rule says that we can find an approximation to the definite integral between the limits of 𝑎 and 𝑏 of 𝑓 of 𝑥 by using the calculation Δ𝑥 over two times 𝑓 of 𝑥 nought plus 𝑓 of 𝑥 𝑛 plus two lots of 𝑓 of 𝑥 one plus 𝑓 of 𝑥 two all the way through to 𝑓 of 𝑥 𝑛 minus one. Where Δ𝑥 is equal to 𝑏 minus 𝑎 over 𝑛. And 𝑥 subscript 𝑖 is equal to 𝑎 plus 𝑖 times Δ𝑥.

Let’s break this down and just begin by working out the value of Δ𝑥. Contextually, Δ𝑥 is the width of each of our subintervals. In this case, we’re working with four subintervals. So we could say that 𝑛 is equal to four. 𝑎 is the lower limit of our integral. So 𝑎 is equal to zero, where 𝑏 is the upper limit. And that’s equal to two. Δ𝑥 is therefore two minus zero over four, which is one-half or 0.5. The values for 𝑓 of 𝑥 nought and 𝑓 of 𝑥 one and so on require a little more work. But we can make this as simple as possible by adding a table.

It’s useful to remember that there will always be 𝑛 plus one columns required in the table. So here, that’s four plus one, which is five. We have five columns in our table. The 𝑥-values run from 𝑎 to 𝑏. That’s zero to two. And the ones in between are found by repeatedly adding Δ𝑥, that’s 0.5, to 𝑎, which is zero. That’s 0.5, one, and 1.5. And that gives us our four strips of width 0.5 units. We’re then simply going to substitute each 𝑥-value into our function. We begin with 𝑓 of zero. That’s zero cubed, which is zero. Next, we have 𝑓 of 0.5. That’s 0.5 cubed, which is 0.125. 𝑓 of one is one cubed, which is still one. And we obtain the final two values in a similar manner. 𝑓 of 1.5 is 3.375. And 𝑓 of two is eight. And that’s the tricky bit done with. All that’s left is to substitute what we know into our formula for the trapezoidal rule.

It’s Δ𝑥 over two, which is 0.5 over two, times the first 𝑓 of 𝑥 value plus the last 𝑓 of 𝑥 value. That’s zero plus eight plus two lots of everything else. That’s two times 0.125 plus one plus 3.375. And that gives us a value of 17 over four. So using four subintervals, the trapezoidal rule gives us the estimate to the definite integral of 𝑥 cubed between zero and two to be 17 over four. Now where possible, this can be checked in a number of ways. You could evaluate a Riemann or midpoint sum or here simply perform the integration.

When we integrate 𝑥 cubed, we get 𝑥 to the fourth power divided by four. Evaluating this between the limits of zero and two gives us two to the fourth power divided by four minus zero to the fourth power divided by four, which is 16 over four. And that’s really close to the answer we got, suggesting we’ve probably performed our calculations correctly.

We’ll now consider an example which involves a consideration on accuracy.

Estimate the definite integral between the limits of one and two of 𝑒 to the power of 𝑥 over 𝑥 d𝑥, using the trapezoidal rule with four subintervals. Approximate your answer to two decimal places.

Remember, the trapezoidal rule says that we can find an estimate for the definite integral of some function 𝑓 of 𝑥 between the limits of 𝑎 and 𝑏 by performing the calculation Δ𝑥 over two times 𝑓 of 𝑥 nought plus 𝑓 of 𝑥 𝑛 plus two times 𝑓 of 𝑥 one plus 𝑓 of 𝑥 two all the way through to 𝑓 of 𝑥 𝑛 minus one. Where Δ𝑥 is 𝑏 minus 𝑎 over 𝑛, where 𝑛 is the number of subintervals. And 𝑥 𝑖 is 𝑎 plus 𝑖 lots of Δ𝑥. We’ll begin then just simply by working out Δ𝑥. Contextually, Δ𝑥 is the width of each of our subinterval. Here we’re working with four subintervals. So 𝑛 is equal to four. 𝑎 is equal to one. And 𝑏 is equal to two. Δ𝑥 is therefore two minus one over four, which is a quarter or 0.25. That’s the perpendicular height of each trapezoid.

The values for 𝑓 of 𝑥 nought and 𝑓 of 𝑥 one and so on require a little more work. But we can make this as simple as possible by including a table. We recall that there will always be one more 𝑓 of 𝑥 value than the number of subintervals. So here, that’s going to be four plus one, which is five 𝑓 of 𝑥 values. The 𝑥-values themselves run from 𝑎 to 𝑏. That’s here from one to two. And the ones in between are found by repeatedly adding Δ𝑥, that’s 0.25, to 𝑎, which is one. So these values are 1.25, 1.5, and 1.75. And that gives us our four strips of width 0.25 units. We’re then going to substitute each 𝑥-value into our function.

Here, we’re going to need to make a decision on accuracy. Whilst the question tells us to use an accuracy of two decimal places, that’s only for our answer. A good rule of thumb is to use at least five decimal places. We begin with 𝑓 of one. That’s 𝑒 to the power of one over one, which is 2.71828, correct to five decimal places. We have 𝑓 of 1.25, which is 𝑒 to the power of 1.25 divided by 1.25. That’s, correct to five decimal places, 2.79227. We repeat this process for 1.5. 𝑓 of 1.5 is 2.98779. 𝑓 of 1.75 is 3.28834. And 𝑓 of two is 3.69453 rounded to five decimal places. All that’s left is to substitute what we know into our formula for the trapezoidal rule. It’s Δ𝑥 over two. That’s 0.25 over two times 𝑓 of one. That’s 2.71828 plus 𝑓 of two. That’s 3.69453 plus two lots of everything else essentially. That’s 2.79227, 2.98779, and 3.28834. That gives us 3.0687, which, correct to two decimal places, is 3.07.

It’s useful to remember that we can check whether this answer is likely to be sensible by using the integration function on our calculator. And when we do, we get 3.06 correct to two decimal places. That’s really close to the answer we got, suggesting we’ve probably performed our calculations correctly. And so an approximation to the integral evaluated between one and two of 𝑒 to the power of 𝑥 over 𝑥 d𝑥 is 3.07.

In our final example, we’re going to look at how to find the error in our approximation. It’s outside the scope of this video to look at where this comes from. But the formula we’ll use is given by. The absolute value of the error is less than or equal to 𝑚 times 𝑏 minus 𝑎 cubed over 12𝑛 squared. And this could be used when the second derivative of the function is continuous. And 𝑚 is an upper bound for the modulus of the second derivative over the closed interval 𝑎 to 𝑏.

a) For 𝑛 equals four, find the error bound for the trapezoidal rule approximation of the definite integral of one over 𝑥 evaluated between one and two. And b) How large should we take 𝑛 in order to guarantee that the trapezoidal rule approximation for the integral of one over 𝑥 between one and two is accurate to within 0.0001?

We can see that we’re going to need to work out 𝑓 double prime of 𝑥, the second derivative of the function one over 𝑥. Let’s alternatively write 𝑓 of 𝑥 as 𝑥 to the power of negative one. Then 𝑓 prime of 𝑥, the first derivative, is negative 𝑥 to the power of negative two. And 𝑓 double prime of 𝑥 is two 𝑥 to the power of negative three or two over 𝑥 cubed. We know that 𝑥 is greater than or equal to one and less than or equal to two. And that tells us that one over 𝑥 must be less than or equal to one.

So let’s consider what this tells us about the absolute value of the second derivative of 𝑓 of 𝑥. Well, it’s the absolute value of two over 𝑥 cubed. So that must be less than or equal to two over one cubed, which we know is two. So we’re going to take 𝑚 as being equal to two since this is the upper bound for the second derivative in this question. 𝑎 is one and 𝑏 equals two. And we’re told in the question that 𝑛 is equal to four. And this means the absolute value of our error is less than or equal to two times two minus one cubed over 12 times four squared, which is roughly equal to 0.01041 and so on. We can therefore say that the absolute value for the error is less than 0.01042, correct to five decimal places.

Then, for part b of this question, we’re going to use what we did in part one. This time though, we’re trying to work out the value of 𝑛. So we say that the absolute value of our error is less than or equal to two times two minus one cubed over 12 times 𝑛 squared, which simplifies to one over six 𝑛 squared. We need this to be less than 0.0001. So we form the inequality one over six 𝑛 squared is less than 0.0001. And we solve for 𝑛. By rearranging, we obtain the inequality 𝑛 squared is greater than one over 0.0006. And then we find the square root of both sides. We don’t here need to worry about the negative square root of one over 0.0006. As we know, by definition, that 𝑛 must be a positive number. So we obtain 𝑛 to be greater than 40.824. For us to be able to guarantee that the approximation is accurate to within 0.0001, we’re going to let 𝑛 be equal to 41.

In this video, we’ve learned that the trapezoidal rule approximation could be used to approximate definite integrals. We obtained the formula for the trapezoidal rule approximation as shown. And we saw that, under certain circumstances, we can establish the error involved in these approximations by using this formula.