Trapezoid Rule Examples with Solutions for Beginners
If you are looking for trapezoid rule examples with solutions, you are probably trying to understand more than just a formula. The Trapezoid Rule is a numerical integration method that approximates a definite integral when finding an exact antiderivative is difficult or when you are working with a table of data rather than a function.
In this article, we will introduce the Trapezoid Rule formula, explain the mathematical reasoning behind it, discuss when the method succeeds and when it can fail, and show how to calculate and interpret its error. By the end of the article, you will have the skills needed to use the Trapezoid Rule to approximate definite integrals and understand the accuracy of your answers.
If you need a review of integration before beginning, please refer to the article Basic Integration Problems for Beginners.
What Is the Trapezoid Rule?
The Trapezoid Rule is a numerical integration technique used to approximate the value of a definite integral. Instead of calculating the exact area under a curve, the Trapezoid Rule approximates the area by dividing the interval into smaller subintervals and replacing the curve over each subinterval with a straight line.
The area between a curve and the \( x \)-axis is generally not a simple geometric shape. However, if we choose two points on the curve and connect them with a straight line, the region between the line and the \( x \)-axis forms a trapezoid. Note that the lines formed are secant lines as discussed in the article Secant and Tangent Lines in Calculus: A Complete Beginner’s Guide.
By repeating this process across the entire interval and adding the areas of all the trapezoids, we obtain an approximation of the definite integral. This is similar to the midpoint rule except here we use trapezoids instead of rectangles. To learn more about the midpoint rule, please refer to the article How to Use the Midpoint Rule to Approximate Definite Integrals.
The Basic Idea
Suppose we want to approximate
$$\int_a^b f(x)dx.$$
We begin by dividing the interval \( [a,b] \) into \( n \) equally sized subintervals. The width of each subinterval is
$$h = \frac{b – a}{n}.$$
This gives us the points
$$x_0 = a, x_1= a + h, x_2 = a + 2h, \ldots, x_n=b.$$
On each subinterval \( [x_{i – 1}, x_i] \), we approximate the curve \( y = f(x) \) with a straight line connecting the two endpoints.
The area under that line is a trapezoid. For one subinterval, the approximate area is
$$A_ i = \frac{h}{2}(f(x_{i – 1}) + f(x_i)).$$
Adding these individual trapezoid areas approximates the entire integral.
The Trapezoid Rule Formula
The Trapezoid Rule with \( n \) subintervals is given by
$$T_n = \frac{h}{2}(f(x_0) + 2\sum_{i = 1}^{n – 1} f(x_i) + f(x_n)),$$
where
$$h = \frac{b – a}{n}.$$
Here \( a \) is the lower limit of integration, \( b \) is the upper limit of integration, \( n \) is the number of subintervals, \( h \) is the width of each subinterval, \( x_0, \ldots, x_n \) are the points dividing the interval, \( f(x_i) \) is the value of the function at each point, and \( T_n \) is the Trapezoid Rule approximation of the definite integral.
The notation \( T_n \) indicates that we are using \( n \) subintervals. In general, increasing \( n \) means using more, narrower trapezoids to approximate the curve.
In the next section, we will examine why the Trapezoid Rule works and why using more trapezoids generally leads to a better approximation.
Why Does the Trapezoid Rule Work?
The Trapezoid Rule works because a smooth curve can often be approximated reasonably well by straight-line segments over sufficiently small intervals. Instead of calculating the exact area under the curve, we approximate the curve with a collection of line segments and calculate the area underneath those segments.
For a refresher on smooth functions, please refer to the articles Newton’s Method Explained for Beginners, The Ultimate Resource for Understanding the Secant Method, and Interpolation Using Lagrange Polynomials in Numerical Analysis: A Complete Tutorial.
A curve may be complicated, but over a small enough interval, it behaves approximately like a straight line.
Approximating a Curve with Straight Lines
Consider a function \( f(x) \) defined on an interval \( [a,b] \). If we select two points on the curve, \( ( x_i, f(x_i)) \) and \( (x_{i + 1}, f(x_{i + 1})) \), we can connect them with a straight line.
The region between this line and the \( x \)-axis forms a trapezoid. The area of that trapezoid is
$$A_i = \frac{h}{2}(f(x_i) + f(x_{i + 1})),$$
where \( h = x_{i + 1} – x_i \).
The straight line does not usually lie exactly on the curve. Therefore, the trapezoid does not give the exact area under the curve on that subinterval. It gives an approximation.
If the interval is reasonably small and the function does not change too rapidly, however, the straight line can be very close to the curve. This makes the trapezoid’s area close to the actual area under the curve.
Why Smaller Subintervals Usually Improve the Approximation
For a sufficiently smooth function, decreasing the width \( h \) generally decreases the difference between the curve and the straight-line approximations. As a result, the total area of the trapezoids tends to become closer to the exact value of the integral. This is why increasing the number of subintervals generally improves the accuracy of the Trapezoid Rule.
However, increasing \( n \) does not guarantee that the approximation will be exact. The curve may still have curvature, and the straight-line segments may still differ from the curve. The amount of error depends on the behavior of the function, particularly its second derivative.
We will examine this in greater detail later in the article.
The Trapezoid Rule Is Exact for Linear Functions
There is one particularly important case in which the Trapezoid Rule does not merely approximate the integral; it gives the exact answer.
Suppose \( f(x) \) is a linear function of the form
$$f(x) = mx + b.$$
Because its graph is already a straight line, connecting two points on the graph does not create an approximation. The line segment connecting those points is the curve itself.
Therefore, the area calculated by the trapezoid is exactly equal to the area under the function over that interval.
This explains why the Trapezoid Rule works so well for functions that are approximately linear over each subinterval. The closer the function is to a straight line on each subinterval, the smaller the approximation error tends to be.
The Role of Curvature
The main reason the Trapezoid Rule is not always exact is curvature.
A straight line has no curvature, while a nonlinear function can curve upward or downward. When we replace a curved section of the graph with a straight line, the line may lie above or below the curve.
The amount by which the function curves is related to its second derivative, \( f”(x) \). When the magnitude of \( f”(x) \) is small, the function generally has less curvature, and the Trapezoid Rule tends to perform well. When the magnitude of \( f”(x) \) is large, the function can curve more sharply, potentially increasing the error of the approximation.
For a review of curvature, please refer to the article Concavity of Functions for Beginners: Everything You Need to Know. For a review of derivatives, please refer to the article How to Differentiate a Function Step by Step: A Beginner’s Guide.
In the next section, we will look more closely at when the Trapezoid Rule succeeds, including the types of functions and intervals for which it tends to produce accurate results.
When Does the Trapezoid Rule Succeed?
The Trapezoid Rule can provide a good approximation to a definite integral, but its accuracy depends on the behavior of the function and how the interval is divided. Understanding when the Trapezoid Rule succeeds can help you determine whether an approximation is likely to be accurate before you even perform the calculation.
When the Function Is Smooth
The Trapezoid Rule works well when \( f(x) \) is smooth throughout the interval of integration. A smooth function changes gradually without abrupt jumps, corners, or other irregular behavior. For a smooth function, a straight line connecting two nearby points on the graph is usually a good approximation to the curve between those points.
When the Subintervals Are Small
The Trapezoid Rule becomes more accurate as the width of the subintervals decreases. This lets the straight-line approximations follow the curve more closely.
When the Function Has Little Curvature
The amount of curvature in a function is closely related to its second derivative, \( f”(x) \).
When
$$|f”(x)|$$
is small throughout the interval, the function does not curve very sharply. Consequently, the straight-line segments used by the Trapezoid Rule tend to remain close to the curve.
This does not mean that a function with substantial curvature cannot be approximated accurately. Increasing the number of subintervals can often compensate for greater curvature.
When the Function Is Continuous
The Trapezoid Rule also works best when the function is continuous throughout the interval of integration. A continuous function has no jumps, holes, or breaks within the interval. This allows the straight-line approximations to follow the graph without encountering sudden changes in behavior.
For a review of continuous functions, please refer to the articles A Complete Introduction to the Bisection Method with Worked Examples and Solutions and How to Solve Equations Using Fixed Point Iteration: A Step-by-Step Guide.
In the next section, we will examine when the Trapezoid Rule fails and the situations in which you should be cautious about relying on a trapezoidal approximation.
When Does the Trapezoid Rule Fail?
The Trapezoid Rule can be effective, but it is not guaranteed to produce an accurate approximation in every situation. The method works by replacing a curved function with straight-line segments. When the curve behaves very differently from those straight lines, the resulting approximation can have significant error.
When the Function Has Large Curvature
One of the biggest sources of error for the Trapezoid Rule occurs when the function has significant curvature.
Recall that the Trapezoid Rule replaces each portion of the curve with a straight line. If the function curves sharply between two consecutive points, the straight line may poorly represent the curve.
When the Subintervals Are Too Large
Even a well-behaved function can produce a poor approximation if the subintervals are too wide. Each straight-line segment must approximate the curve over a larger distance, giving the curve more opportunity to move away from the line.
When the Function Is Discontinuous
The Trapezoid Rule is generally not appropriate without additional care when the function has a discontinuity within the interval of integration. When a discontinuity or singularity occurs, the integral may need to be treated as an improper integral, or the interval may need to be divided into separate pieces.
For a review of improper integrals, please refer to the article Examples of Improper Integrals with Solutions: A Beginner’s Guide.
The next section examines error in more detail and shows how to calculate an error bound rather than simply guessing how accurate an approximation is.
Error
The Trapezoid Rule gives an approximation, not an exact value, for most functions. This means that there is generally some difference between the true value of the definite integral and the value obtained using the Trapezoid Rule.
Understanding this difference is important because an approximation is only useful if we have some idea of how accurate it is. Fortunately, the Trapezoid Rule has a well-known error formula that allows us to estimate how large the error can be.
Absolute Error
Suppose the exact value of a definite integral is
$$I = \int_a^b f(x)dx$$
and the Trapezoid Rule approximation using \( n \) subintervals is \( T_n \).
The absolute error is defined as
$$\epsilon = |I – T_n|.$$
The absolute error tells us how far the approximation is from the exact value.
In practice, however, we often do not know the exact value of the integral. This is one reason an error bound is useful.
The Trapezoid Rule Error Bound
If \( f”(x) \) is continuous on the interval \( [a,b] \), the error bound is
$$\epsilon \leq \frac{(b – a)^3}{12n^2} \max_{a \leq x \leq b}|f”(x)|.$$
Where \( a \) and \( b \) are the limits of integration, \( n \) is the number of subintervals, \( f”(x) \) is the second derivative of the function, \( \max |f”(x)| \) represents the maximum absolute value of the second derivative on the interval, and \( \epsilon \) represents the absolute error.
This formula tells us that the absolute error cannot exceed the quantity on the right-hand side, provided the necessary conditions are satisfied. The error bound guarantees that the approximation is within a certain distance of the exact answer.
In the next section, we will put everything together and look at the step-by-step procedure for using the Trapezoid Rule to approximate a definite integral.
Step-by-Step Procedure for Using the Trapezoid Rule
Now that we have discussed what the Trapezoid Rule is, why it works, and how to estimate its error, it is time to put everything together. Using the Trapezoid Rule involves a straightforward sequence of calculations. The following steps provide a reliable procedure for solving a Trapezoid Rule problem.
Step 1: Identify \( a \), \( b \), and \( n \)
Begin by identifying the lower limit \( a \), upper limit \( b \), and number of subintervals \( n \).
Step 2: Calculate the Width of Each Subinterval
Use
$$h = \frac{b – a}{n}.$$
Step 3: Find the \( x \)-Values
Starting with \( x_0 = a \), add \( h \) repeatedly until you reach \( x_n = b \).
Step 4: Evaluate the Function at Each \( x \)-Value
Next, calculate the function value at every point found in the previous step.
Step 5: Apply the Trapezoid Rule Formula
Now substitute the function values into
$$T_n = \frac{h}{2}(f(x_0) + 2\sum_{i = 1}^{n – 1} f(x_i) + f(x_n)),$$
Worked Out Examples
The first example shows how to use the trapezoid rule.
Example 1: Use the trapezoid rule to approximate \( \int_0^4 x^2 dx \). Use 4 subintervals and find the absolute error.
Solution: The width of each subinterval is
$$h = \frac{4 – 0}{4}.$$
Subtracting gives
$$h = \frac{4}{4}.$$
Dividing we obtain
$$h = 1.$$
The x-values are then
$$0, 1, 2, 3, 4.$$
Consider the function
$$f(x) = x^2.$$
Evaluating the function at \( x_0 = 0 \) we obtain
$$f(0) = 0^2.$$
Squaring we find
$$f(0) = 0.$$
Evaluating the function at \( x_1 = 1 \) we obtain
$$f(1) = 1^2.$$
Squaring we find
$$f(1) = 1.$$
Evaluating the function at \( x_2 = 2 \) we obtain
$$f(2) = 2^2.$$
Squaring we find
$$f(2) = 4.$$
Evaluating the function at \( x_3 = 3 \) we obtain
$$f(3) = 3^2.$$
Squaring we find
$$f(3) = 9.$$
Evaluating the function at \( x_4 = 4 \) we obtain
$$f(4) = 4^2.$$
Squaring we find
$$f(4) = 16.$$
By the trapezoid rule, our approximation is then
$$T_4 = \frac{1}{2}(0 + 2(1) + 2(4) + 2(9) + 16).$$
Multiplying gives
$$T_4 = \frac{1}{2}(0 + 2 + 8 + 18 + 16).$$
Adding we get
$$T_4 = \frac{1}{2}(44).$$
Dividing we find
$$T_4 = 0.5(44).$$
Multiplying, we arrive at
$$T_4 = 22.$$
Integrating gives
$$\frac{x^3}{3}|_0^4.$$
Applying the Fundamental Theorem of Calculus, we obtain
$$\frac{4^3}{3} – \frac{0^3}{3}.$$
Cubing we get
$$\frac{64}{3} – \frac{0}{3}.$$
Dividing this is
$$21.333333 – 0.$$
Subtracting gives
$$21.333333.$$
The absolute error is then
$$\epsilon = |21.333333 – 22|.$$
Subtracting gives
$$\epsilon = |-0.666666|.$$
Taking the absolute value, we arrive at a final answer of
$$\epsilon = 0.666666.$$
The next example illustrates one of the primary applications of numerical analysis, namely solving definite integrals without an elementary antiderivative. In this example, we will be using techniques covered in the article How to Find Intervals of Increase and Decrease: A Step-by-Step Guide.
Example 2: Use the trapezoid rule to approximate \( \int_0^2 e^{x^2} dx \). Use 4 subintervals and find the error bound.
Solution: The width of each subinterval is
$$h = \frac{2 – 0}{4}.$$
Subtracting gives
$$h = \frac{2}{4}.$$
Dividing we obtain
$$h = 0.5.$$
The x-values are then
$$0, 0.5, 1, 1.5, 2.$$
Consider the function
$$f(x) = e^{x^2}.$$
Evaluating the function at \( x_0 = 0 \) we obtain
$$f(0) = e^{0^2}.$$
Squaring we find
$$f(0) = e^0.$$
Exponentiating gives
$$f(0) = 1.$$
Evaluating the function at \( x_1 = 0.5 \) we obtain
$$f(0.5) = e^{0.5^2}.$$
Squaring we find
$$f(0.5) = e^{0.25}.$$
Exponentiating gives
$$f(0.5) = 1.284025.$$
Evaluating the function at \( x_2 = 1 \) we obtain
$$f(1) = e^{1^2}.$$
Squaring we find
$$f(1) = e^1.$$
Exponentiating gives
$$f(1) = 2.718281.$$
Evaluating the function at \( x_3 = 1.5 \) we obtain
$$f(1.5) = e^{1.5^2}.$$
Squaring we find
$$f(1.5) = e^{2.25}.$$
Exponentiating gives
$$f(1.5) = 9.487735.$$
Evaluating the function at \( x_2 = 2 \) we obtain
$$f(2) = e^{2^2}.$$
Squaring we find
$$f(2) = e^4.$$
Exponentiating gives
$$f(2) = 54.598150.$$
By the trapezoid rule, our approximation is then
$$T_4 = \frac{0.5}{2}(1 + 2(1.284025) + 2(2.718281) + 2(9.487735) + 54.598150).$$
Multiplying gives
$$T_4 = \frac{0.5}{2}(1 + 2.568050 + 5.436563 + 18.975471 + 54.598150).$$
Adding we get
$$T_4 = \frac{0.5}{2}(82.578236).$$
Dividing we find
$$T_4 = 0.25(82.578236).$$
Multiplying, we arrive at
$$T_4 = 20.644559.$$
Taking the derivative, we get
$$f'(x) = (e^{x^2})’.$$
Using the chain rule, this is
$$f'(x) = (x^2)’e^{x^2}.$$
Taking the derivative, we get
$$f'(x) = 2xe^{x^2}.$$
Taking the derivative again, we get
$$f”(x) = (2xe^{x^2})’.$$
Using the product rule, this is
$$f”(x) = (2x)’e^{x^2} + 2x(e^{x^2})’.$$
Using the chain rule gives
$$f”(x) = (2x)’e^{x^2} + 2x(x^2)’e^{x^2}.$$
Taking the derivatives, we get
$$f”(x) = 2e^{x^2} + 2x(2x)e^{x^2}.$$
Distributing gives
$$f”(x) = 2e^{x^2} + 4x^2e^{x^2}.$$
Factoring out \( e^{x^2} \) this is
$$f”(x) = (2 + 4x^2)e^{x^2}.$$
Taking the derivative once again, we get
$$f”‘(x) = ((2 + 4x^2)e^{x^2})’.$$
Using the product rule, this is
$$f”‘(x) = (2 + 4x^2)’e^{x^2} + (2 + 4x^2)(e^{x^2})’.$$
Using the sum rule and chain rule gives
$$f”‘(x) = ((2)’ + (4x^2)’)e^{x^2} + (2 + 4x^2)(x^2)’e^{x^2}.$$
Taking the derivatives, we get
$$f”‘(x) = (0 + 8x)e^{x^2} + (2 + 4x^2)(2x)e^{x^2}.$$
Adding gives
$$f”‘(x) = 8xe^{x^2} + (2 + 4x^2)(2x)e^{x^2}.$$
Factoring 2 from the first factor in the second term, we obtain
$$f”‘(x) = 8xe^{x^2} + 2(1 + 2x^2)(2x)e^{x^2}.$$
This is equivalent to
$$f”‘(x) = 8xe^{x^2} + 4x(1 + 2x^2)e^{x^2}.$$
Factoring out \( 4xe^{x^2} \) this is
$$f”‘(x) = 4xe^{x^2}(2 + 1 + 2x^2).$$
Simplifying gives
$$f”‘(x) = 4xe^{x^2}(3 + 2x^2).$$
Setting the third derivative equal to 0, we obtain
$$0 = 4xe^{x^2}(3 + 2x^2).$$
Since \( 4e^{x^2}(3 + 2x^2) \) is nonzero for all real x we can divide by it to get
$$0 = x.$$
Evaluating the second derivative at \( x = 0 \) we obtain
$$f”(0) = (2 + 4(0^2))e^{0^2}.$$
Squaring we find
$$f”(0) = (2 + 4(0))e^0.$$
Exponentiating gives
$$f”(0) = (2 + 4(0))1.$$
Multiplying we get
$$f”(0) = (2 + 0)1.$$
Adding we obtain
$$f”(0) = (2)1.$$
Multiplying this is
$$f”(0) = 2.$$
Evaluating the second derivative at \( x = 2 \) we obtain
$$f”(2) = (2 + 4(2^2))e^{2^2}.$$
Squaring we find
$$f”(2) = (2 + 4(4))e^4.$$
Exponentiating gives
$$f”(2) = (2 + 4(4))54.598150.$$
Multiplying we get
$$f”(2) = (2 + 16)54.598150.$$
Adding we obtain
$$f”(2) = (18)54.598150.$$
Multiplying this, we get
$$f”(2) = 982.766700.$$
The error bound is then
$$\epsilon \leq \frac{(2 – 0)^3}{12(4)^2} (982.766700).$$
Subtracting gives
$$\epsilon \leq \frac{(2)^3}{12(4)^2} (982.766700).$$
Cubing and squaring this is
$$\epsilon \leq \frac{8}{12(16)} (982.766700).$$
Multiplying we get
$$\epsilon \leq \frac{8}{192} (982.766700).$$
Dividing we find
$$\epsilon \leq 0.041666(982.766700).$$
Multiplying, we arrive at a final answer of
$$\epsilon \leq 40.948612.$$
Conclusion
The Trapezoid Rule provides a practical way to approximate definite integrals by replacing portions of a curve with trapezoids. Although it does not usually produce the exact value, it can provide highly accurate results when the function is smooth and the interval is divided into sufficiently small subintervals.
In this article, we explored why the Trapezoid Rule works, when it succeeds, and when it can struggle. We also saw that the error depends on the number of subintervals and the function’s curvature. The error bound lets us estimate how accurate our approximation is and determine how many subintervals are needed to achieve a desired level of accuracy. Most importantly, the trapezoid rule examples with solutions in this article demonstrate that the method follows a consistent process.
Further Reading
The Ultimate Step by Step Guide to Solving Integrals Using Substitution  – Integrals with infinite bounds require a substitution before numerical techniques can be applied. This guide shows how to evaluate integrals using substitution.
Finite Difference Method for Numerical Differentiation: A Step-by-Step Guide – The finite difference is very similar to the trapezoid rule. Finite differences are covered in this article
