### Learning Objectives

- 3.6.1. Approximate the value of a definite integral by using the midpoint and trapezoidal rules.
- 3.6.2. Determine the absolute and relative error in using a numerical integration technique.
- 3.6.3. Estimate the absolute and relative error using an error-bound formula.
- 3.6.4. Recognize when the midpoint and trapezoidal rules over- or underestimate the true value of an integral.
- 3.6.5. Use Simpson’s rule to approximate the value of a definite integral to a given accuracy.

The antiderivatives of many functions either cannot be expressed or cannot be expressed easily in closed form (that is, in terms of known functions). Consequently, rather than evaluate definite integrals of these functions directly, we resort to various techniques of numerical integration to approximate their values. In this section we explore several of these techniques. In addition, we examine the process of estimating the error in using these techniques.

### The Midpoint Rule

Earlier in this text we defined the definite integral of a function over an interval as the limit of Riemann sums. In general, any Riemann sum of a function $f(x)$ over an interval $[a,b]$ may be viewed as an estimate of ${\int}_{a}^{b}f(x)dx}.$ Recall that a Riemann sum of a function $f(x)$ over an interval $[a,b]$ is obtained by selecting a partition

and a set

The Riemann sum corresponding to the partition $P$ and the set $S$ is given by $\sum _{i=1}^{n}f({x}_{i}^{*})\text{\Delta}{x}_{i}},$ where $\text{\Delta}{x}_{i}={x}_{i}-{x}_{i-1},$ the length of the *i*th subinterval.

The midpoint rule for estimating a definite integral uses a Riemann sum with subintervals of equal width and the midpoints, ${m}_{i},$ of each subinterval in place of ${x}_{i}^{*}.$ Formally, we state a theorem regarding the convergence of the midpoint rule as follows.

#### The Midpoint Rule

Assume that $f(x)$ is continuous on $\left[a,b\right].$ Let *n* be a positive integer and $\text{\Delta}x=\frac{b-a}{n}.$ If $\left[a,b\right]$ is divided into $n$ subintervals, each of length $\text{\Delta}x,$ and ${m}_{i}$ is the midpoint of the *i*th subinterval, set

Then $\underset{n\to \infty}{\text{lim}}{M}_{n}={\displaystyle {\int}_{a}^{b}f\left(x\right)dx}.$

As we can see in Figure 3.13, if $f(x)\ge 0$ over $[a,b],$ then $\sum}_{i=1}^{n}f({m}_{i})\text{\Delta}x$ corresponds to the sum of the areas of rectangles approximating the area between the graph of $f(x)$ and the *x*-axis over $\left[a,b\right].$ The graph shows the rectangles corresponding to ${M}_{4}$ for a nonnegative function over a closed interval $[a,b].$

### Example 3.39

#### Using the Midpoint Rule with ${M}_{4}$

Use the midpoint rule to estimate ${\int}_{0}^{1}{x}^{2}dx$ using four subintervals. Compare the result with the actual value of this integral.

#### Solution

Each subinterval has length $\text{\Delta}x=\frac{1-0}{4}=\frac{1}{4}.$ Therefore, the subintervals consist of

The midpoints of these subintervals are $\left\{\frac{1}{8},\frac{3}{8},\frac{5}{8},\frac{7}{8}\right\}.$ Thus,

Since

we see that the midpoint rule produces an estimate that is somewhat close to the actual value of the definite integral.

### Example 3.40

#### Using the Midpoint Rule with ${M}_{6}$

Use ${M}_{6}$ to estimate the length of the curve $y=\frac{1}{2}{x}^{2}$ on $[1,4].$

#### Solution

The length of $y=\frac{1}{2}{x}^{2}$ on $[1,4]$ is

Since $\frac{dy}{dx}=x,$ this integral becomes ${\int}_{1}^{4}\sqrt{1+{x}^{2}}\phantom{\rule{0.1em}{0ex}}dx}.$

If $[1,4]$ is divided into six subintervals, then each subinterval has length $\text{\Delta}x=\frac{4-1}{6}=\frac{1}{2}$ and the midpoints of the subintervals are $\left\{\frac{5}{4},\frac{7}{4},\frac{9}{4},\frac{11}{4},\frac{13}{4},\frac{15}{4}\right\}.$ If we set $f\left(x\right)=\sqrt{1+{x}^{2}},$

Use the midpoint rule with $n=2$ to estimate ${\int}_{1}^{2}\frac{1}{x}dx}.$

### The Trapezoidal Rule

We can also approximate the value of a definite integral by using trapezoids rather than rectangles. In Figure 3.14, the area beneath the curve is approximated by trapezoids rather than by rectangles.

The trapezoidal rule for estimating definite integrals uses trapezoids rather than rectangles to approximate the area under a curve. To gain insight into the final form of the rule, consider the trapezoids shown in Figure 3.14. We assume that the length of each subinterval is given by $\text{\Delta}x.$ First, recall that the area of a trapezoid with a height of *h* and bases of length ${b}_{1}$ and ${b}_{2}$ is given by $\text{Area}=\frac{1}{2}h({b}_{1}+{b}_{2}).$ We see that the first trapezoid has a height $\text{\Delta}x$ and parallel bases of length $f({x}_{0})$ and $f({x}_{1}).$ Thus, the area of the first trapezoid in Figure 3.14 is

The areas of the remaining three trapezoids are

Consequently,

After taking out a common factor of $\frac{1}{2}\text{\Delta}x$ and combining like terms, we have

Generalizing, we formally state the following rule.

#### The Trapezoidal Rule

Assume that $f(x)$ is continuous over $\left[a,b\right].$ Let *n* be a positive integer and $\text{\Delta}x=\frac{b-a}{n}.$ Let $\left[a,b\right]$ be divided into $n$ subintervals, each of length $\text{\Delta}x,$ with endpoints at $P=\{{x}_{0},{x}_{1},{x}_{2}\text{\u2026},{x}_{n}\}.$ Set

Then, $\underset{n\to \text{+}\infty}{\text{lim}}{T}_{n}={\displaystyle {\int}_{a}^{b}f\left(x\right)dx}.$

Before continuing, let’s make a few observations about the trapezoidal rule. First of all, it is useful to note that

That is, ${L}_{n}$ and ${R}_{n}$ approximate the integral using the left-hand and right-hand endpoints of each subinterval, respectively. In addition, a careful examination of Figure 3.15 leads us to make the following observations about using the trapezoidal rules and midpoint rules to estimate the definite integral of a nonnegative function. The trapezoidal rule tends to overestimate the value of a definite integral systematically over intervals where the function is concave up and to underestimate the value of a definite integral systematically over intervals where the function is concave down. On the other hand, the midpoint rule tends to average out these errors somewhat by partially overestimating and partially underestimating the value of the definite integral over these same types of intervals. This leads us to hypothesize that, in general, the midpoint rule tends to be more accurate than the trapezoidal rule.

### Example 3.41

#### Using the Trapezoidal Rule

Use the trapezoidal rule to estimate ${\int}_{0}^{1}{x}^{2}dx$ using four subintervals.

#### Solution

The endpoints of the subintervals consist of elements of the set $P=\left\{0,\frac{1}{4},\frac{1}{2},\frac{3}{4},1\right\}$ and $\text{\Delta}x=\frac{1-0}{4}=\frac{1}{4}.$ Thus,

Use the trapezoidal rule with $n=2$ to estimate ${\int}_{1}^{2}\frac{1}{x}dx}.$

### Absolute and Relative Error

An important aspect of using these numerical approximation rules consists of calculating the error in using them for estimating the value of a definite integral. We first need to define absolute error and relative error.

### Definition

If $B$ is our estimate of some quantity having an actual value of $A,$ then the absolute error is given by $\left|A-B\right|.$ The relative error is the error as a percentage of the absolute value and is given by $\left|\frac{A-B}{A}\right|=\left|\frac{A-B}{A}\right|\xb7100\text{\%}.$

### Example 3.42

#### Calculating Error in the Midpoint Rule

Calculate the absolute and relative error in the estimate of ${\int}_{0}^{1}{x}^{2}dx$ using the midpoint rule, found in Example 3.39.

#### Solution

The calculated value is $\int}_{0}^{1}{x}^{2}dx=\frac{1}{3$ and our estimate from the example is ${M}_{4}=\frac{21}{64}.$ Thus, the absolute error is given by $\left|\left(\frac{1}{3}\right)-\left(\frac{21}{64}\right)\right|=\frac{1}{192}\approx 0.0052.$ The relative error is

### Example 3.43

#### Calculating Error in the Trapezoidal Rule

Calculate the absolute and relative error in the estimate of ${\int}_{0}^{1}{x}^{2}dx$ using the trapezoidal rule, found in Example 3.41.

#### Solution

The calculated value is $\int}_{0}^{1}{x}^{2}dx=\frac{1}{3$ and our estimate from the example is ${T}_{4}=\frac{11}{32}.$ Thus, the absolute error is given by $\left|\frac{1}{3}-\frac{11}{32}\right|=\frac{1}{96}\approx 0.0104.$ The relative error is given by

In an earlier checkpoint, we estimated ${\int}_{1}^{2}\frac{1}{x}dx$ to be $\frac{24}{35}$ using ${T}_{2}.$ The actual value of this integral is $\text{ln}\phantom{\rule{0.1em}{0ex}}2.$ Using $\frac{24}{35}\approx 0.6857$ and $\text{ln}\phantom{\rule{0.1em}{0ex}}2\approx 0.6931,$ calculate the absolute error and the relative error.

In the two previous examples, we were able to compare our estimate of an integral with the actual value of the integral; however, we do not typically have this luxury. In general, if we are approximating an integral, we are doing so because we cannot compute the exact value of the integral itself easily. Therefore, it is often helpful to be able to determine an upper bound for the error in an approximation of an integral. The following theorem provides error bounds for the midpoint and trapezoidal rules. The theorem is stated without proof.

#### Error Bounds for the Midpoint and Trapezoidal Rules

Let $f(x)$ be a continuous function over $\left[a,b\right],$ having a second derivative $f\text{\u2033}(x)$ over this interval. If $M$ is the maximum value of $\left|f\text{\u2033}(x)\right|$ over $[a,b],$ then the upper bounds for the error in using ${M}_{n}$ and ${T}_{n}$ to estimate ${\int}_{a}^{b}f\left(x\right)dx$ are

and

We can use these bounds to determine the value of $n$ necessary to guarantee that the error in an estimate is less than a specified value.

### Example 3.44

#### Determining the Number of Intervals to Use

What value of $n$ should be used to guarantee that an estimate of ${\int}_{0}^{1}{e}^{{x}^{2}}dx$ is accurate to within 0.01 if we use the midpoint rule?

#### Solution

We begin by determining the value of $M,$ the maximum value of $\left|f\text{\u2033}(x)\right|$ over $[0,1]$ for $f\left(x\right)={e}^{{x}^{2}}.$ Since ${f}^{\prime}\left(x\right)=2x{e}^{{x}^{2}},$ we have

Thus,

From the error-bound Equation 3.12, we have

Now we solve the following inequality for $n\text{:}$

Thus, $n\ge \sqrt{\frac{600e}{24}}\approx 8.24.$ Since $n$ must be an integer satisfying this inequality, a choice of $n=9$ would guarantee that $\left|{\displaystyle {\int}_{0}^{1}{e}^{{x}^{2}}dx-{M}_{n}}\right|<0.01.$

#### Analysis

We might have been tempted to round $8.24$ down and choose $n=8,$ but this would be incorrect because we must have an integer greater than or equal to $8.24.$ We need to keep in mind that the error estimates provide an upper bound only for the error. The actual estimate may, in fact, be a much better approximation than is indicated by the error bound.

Use Equation 3.13 to find an upper bound for the error in using ${M}_{4}$ to estimate ${\int}_{0}^{1}{x}^{2}dx}.$

### Simpson’s Rule

With the midpoint rule, we estimated areas of regions under curves by using rectangles. In a sense, we approximated the curve with piecewise constant functions. With the trapezoidal rule, we approximated the curve by using piecewise linear functions. What if we were, instead, to approximate a curve using piecewise quadratic functions? With Simpson’s rule, we do just this. We partition the interval into an even number of subintervals, each of equal width. Over the first pair of subintervals we approximate ${\int}_{{x}_{0}}^{{x}_{2}}f\left(x\right)dx$ with ${\int}_{{x}_{0}}^{{x}_{2}}p\left(x\right)dx,$ where $p\left(x\right)=A{x}^{2}+Bx+C$ is the quadratic function passing through $({x}_{0},f\left({x}_{0}\right)),$ $({x}_{1},f\left({x}_{1}\right)),$ and $({x}_{2},f\left({x}_{2}\right))$ (Figure 3.16). Over the next pair of subintervals we approximate ${\int}_{{x}_{2}}^{{x}_{4}}f\left(x\right)dx$ with the integral of another quadratic function passing through $({x}_{2},f\left({x}_{2}\right)),$ $({x}_{3},f\left({x}_{3}\right)),$ and $({x}_{4},f\left({x}_{4}\right)).$ This process is continued with each successive pair of subintervals.

To understand the formula that we obtain for Simpson’s rule, we begin by deriving a formula for this approximation over the first two subintervals. As we go through the derivation, we need to keep in mind the following relationships:

${x}_{2}-{x}_{0}=2\text{\Delta}x,$ where $\text{\Delta}x$ is the length of a subinterval.

Thus,

If we approximate ${\int}_{{x}_{2}}^{{x}_{4}}f\left(x\right)dx$ using the same method, we see that we have

Combining these two approximations, we get

The pattern continues as we add pairs of subintervals to our approximation. The general rule may be stated as follows.

#### Simpson’s Rule

Assume that $f(x)$ is continuous over $\left[a,b\right].$ Let *n* be a positive even integer and $\text{\Delta}x=\frac{b-a}{n}.$ Let $\left[a,b\right]$ be divided into $n$ subintervals, each of length $\text{\Delta}x,$ with endpoints at $P=\{{x}_{0},{x}_{1},{x}_{2}\text{,\u2026},{x}_{n}\}.$ Set

Then,

Just as the trapezoidal rule is the average of the left-hand and right-hand rules for estimating definite integrals, Simpson’s rule may be obtained from the midpoint and trapezoidal rules by using a weighted average. It can be shown that ${S}_{2n}=\left(\frac{2}{3}\right){M}_{n}+\left(\frac{1}{3}\right){T}_{n}.$

It is also possible to put a bound on the error when using Simpson’s rule to approximate a definite integral. The bound in the error is given by the following rule:

### Rule: Error Bound for Simpson’s Rule

Let $f(x)$ be a continuous function over $[a,b]$ having a fourth derivative, ${f}^{(4)}(x),$ over this interval. If $M$ is the maximum value of $\left|{f}^{(4)}(x)\right|$ over $[a,b],$ then the upper bound for the error in using ${S}_{n}$ to estimate ${\int}_{a}^{b}f\left(x\right)dx$ is given by

### Example 3.45

#### Applying Simpson’s Rule 1

Use ${S}_{2}$ to approximate ${\int}_{0}^{1}{x}^{3}dx}.$ Estimate a bound for the error in ${S}_{2}.$

#### Solution

Since $[0,1]$ is divided into two intervals, each subinterval has length $\text{\Delta}x=\frac{1-0}{2}=\frac{1}{2}.$ The endpoints of these subintervals are $\left\{0,\frac{1}{2},1\right\}.$ If we set $f\left(x\right)={x}^{3},$ then

${S}_{4}=\frac{1}{3}\xb7\frac{1}{2}\left(f\left(0\right)+4f\left(\frac{1}{2}\right)+f\left(1\right)\right)=\frac{1}{6}\left(0+4\xb7\frac{1}{8}+1\right)=\frac{1}{4}.$ Since ${f}^{\left(4\right)}\left(x\right)=0$ and consequently $M=0,$ we see that

This bound indicates that the value obtained through Simpson’s rule is exact. A quick check will verify that, in fact, ${\int}_{0}^{1}{x}^{3}dx=\frac{1}{4}}.$

### Example 3.46

#### Applying Simpson’s Rule 2

Use ${S}_{6}$ to estimate the length of the curve $y=\frac{1}{2}{x}^{2}$ over $[1,4].$

#### Solution

The length of $y=\frac{1}{2}{x}^{2}$ over $[1,4]$ is ${\int}_{1}^{4}\sqrt{1+{x}^{2}}\phantom{\rule{0.1em}{0ex}}dx}.$ If we divide $[1,4]$ into six subintervals, then each subinterval has length $\text{\Delta}x=\frac{4-1}{6}=\frac{1}{2},$ and the endpoints of the subintervals are $\left\{1,\frac{3}{2},2,\frac{5}{2},3,\frac{7}{2},4\right\}.$ Setting $f\left(x\right)=\sqrt{1+{x}^{2}},$

After substituting, we have

Use ${S}_{2}$ to estimate ${\int}_{1}^{2}\frac{1}{x}dx}.$

### Section 3.6 Exercises

Approximate the following integrals using either the midpoint rule, trapezoidal rule, or Simpson’s rule as indicated. (Round answers to three decimal places.)

${\int}_{0}^{3}\sqrt{4+{x}^{3}}\phantom{\rule{0.1em}{0ex}}dx};$ trapezoidal rule; $n=6$

${\int}_{0}^{12}{x}^{2}dx};$ midpoint rule; $n=6$

Use the midpoint rule with eight subdivisions to estimate ${\int}_{2}^{4}{x}^{2}dx}.$

Find the exact value of ${\int}_{2}^{4}{x}^{2}dx}.$ Find the error of approximation between the exact value and the value calculated using the trapezoidal rule with four subdivisions. Draw a graph to illustrate.

Approximate the integral to three decimal places using the indicated rule.

${\int}_{0}^{3}\frac{1}{1+{x}^{3}}dx};$ trapezoidal rule; $n=6$

${\int}_{0}^{0.8}{e}^{\text{\u2212}{x}^{2}}dx};$ trapezoidal rule; $n=4$

${\int}_{0}^{0.4}\text{sin}({x}^{2})dx};$ trapezoidal rule; $n=4$

${\int}_{0.1}^{0.5}\frac{\text{cos}\phantom{\rule{0.1em}{0ex}}x}{x}dx};$ trapezoidal rule; $n=4$

Evaluate $\int}_{0}^{1}\frac{dx}{1+{x}^{2}$ exactly and show that the result is $\pi \text{/}4.$ Then, find the approximate value of the integral using the trapezoidal rule with $n=4$ subdivisions. Use the result to approximate the value of $\pi .$

Approximate ${\int}_{2}^{4}\frac{1}{\text{ln}\phantom{\rule{0.1em}{0ex}}x}dx$ using the midpoint rule with four subdivisions to four decimal places.

Approximate ${\int}_{2}^{4}\frac{1}{\text{ln}\phantom{\rule{0.1em}{0ex}}x}dx$ using the trapezoidal rule with eight subdivisions to four decimal places.

Use the trapezoidal rule with four subdivisions to estimate ${\int}_{0}^{0.8}{x}^{3}dx$ to four decimal places.

Use the trapezoidal rule with four subdivisions to estimate ${\int}_{0}^{0.8}{x}^{3}dx}.$ Compare this value with the exact value and find the error estimate.

Using Simpson’s rule with four subdivisions, find ${\int}_{0}^{\pi \text{/}2}\text{cos}(x)dx}.$

Show that the exact value of ${\int}_{0}^{1}x{e}^{\text{\u2212}x}dx=1-\frac{2}{e}.$ Find the absolute error if you approximate the integral using the midpoint rule with 16 subdivisions.

Given ${\int}_{0}^{1}x{e}^{\text{\u2212}x}dx=1-\frac{2}{e},$ use the trapezoidal rule with 16 subdivisions to approximate the integral and find the absolute error.

Find an upper bound for the error in estimating ${\int}_{0}^{3}(5x+4)dx$ using the trapezoidal rule with six steps.

Find an upper bound for the error in estimating ${\int}_{4}^{5}\frac{1}{{\left(x-1\right)}^{2}}dx$ using the trapezoidal rule with seven subdivisions.

Find an upper bound for the error in estimating ${\int}_{0}^{3}(6{x}^{2}-1)dx$ using Simpson’s rule with $n=10$ steps.

Find an upper bound for the error in estimating ${\int}_{2}^{5}\frac{1}{x-1}dx$ using Simpson’s rule with $n=10$ steps.

Find an upper bound for the error in estimating ${\int}_{0}^{\pi}2x\phantom{\rule{0.1em}{0ex}}\text{cos}(x)dx$ using Simpson’s rule with four steps.

Estimate the minimum number of subintervals needed to approximate the integral ${\int}_{1}^{4}\left(5{x}^{2}+8\right)dx$ with an error magnitude of less than 0.0001 using the trapezoidal rule.

Determine a value of *n* such that the trapezoidal rule will approximate ${\int}_{0}^{1}\sqrt{1+{x}^{2}}\phantom{\rule{0.1em}{0ex}}dx$ with an error of no more than 0.01.

Estimate the minimum number of subintervals needed to approximate the integral ${\int}_{2}^{3}\left(2{x}^{3}+4x\right)dx$ with an error of magnitude less than 0.0001 using the trapezoidal rule.

Estimate the minimum number of subintervals needed to approximate the integral ${\int}_{3}^{4}\frac{1}{{(x-1)}^{2}}dx$ with an error magnitude of less than 0.0001 using the trapezoidal rule.

Use Simpson’s rule with four subdivisions to approximate the area under the probability density function $y=\frac{1}{\sqrt{2\pi}}{e}^{\text{\u2212}{x}^{2}\text{/}2}$ from $x=0$ to $x=0.4.$

Use Simpson’s rule with $n=14$ to approximate (to three decimal places) the area of the region bounded by the graphs of $y=0,$ $x=0,$ and $x=\pi \text{/}2.$

The length of one arch of the curve $y=3\phantom{\rule{0.1em}{0ex}}\text{sin}(2x)$ is given by $L={\displaystyle {\int}_{0}^{\pi \text{/}2}\sqrt{1+36\phantom{\rule{0.1em}{0ex}}{\text{cos}}^{2}(2x)}\phantom{\rule{0.1em}{0ex}}dx}.$ Estimate *L* using the trapezoidal rule with $n=6.$

The length of the ellipse $x=a\phantom{\rule{0.1em}{0ex}}\text{cos}(t),y=b\phantom{\rule{0.1em}{0ex}}\text{sin}(t),0\le t\le 2\pi $ is given by $L=4a{\displaystyle {\int}_{0}^{\pi \text{/}2}\sqrt{1-{e}^{2}{\text{cos}}^{2}(t)}\phantom{\rule{0.1em}{0ex}}dt},$ where *e* is the eccentricity of the ellipse. Use Simpson’s rule with $n=6$ subdivisions to estimate the length of the ellipse when $a=2$ and $e=1\text{/}3.$

Estimate the area of the surface generated by revolving the curve $y=\text{cos}(2x),0\le x\le \frac{\pi}{4}$ about the *x*-axis. Use the trapezoidal rule with six subdivisions.

Estimate the area of the surface generated by revolving the curve $y=2{x}^{2},$ $0\le x\le 3$ about the *x-*axis. Use Simpson’s rule with $n=6.$

The growth rate of a certain tree (in feet) is given by $y=\frac{2}{t+1}+{e}^{\text{\u2212}{t}^{2}\text{/}2},$ where *t* is time in years. Estimate the growth of the tree through the end of the second year by using Simpson’s rule, using two subintervals. (Round the answer to the nearest hundredth.)

**[T]** Use a calculator to approximate ${\int}_{0}^{1}\text{sin}\left(\pi x\right)dx$ using the midpoint rule with 25 subdivisions. Compute the relative error of approximation.

**[T]** Given ${\int}_{1}^{5}\left(3{x}^{2}-2x\right)dx}=100,$ approximate the value of this integral using the midpoint rule with 16 subdivisions and determine the absolute error.

Given that we know the Fundamental Theorem of Calculus, why would we want to develop numerical methods for definite integrals?

The table represents the coordinates $\left(x,\text{}y\right)$ that give the boundary of a lot. The units of measurement are meters. Use the trapezoidal rule to estimate the number of square meters of land that is in this lot.

x |
y |
x |
y |
---|---|---|---|

0 | 125 | 600 | 95 |

100 | 125 | 700 | 88 |

200 | 120 | 800 | 75 |

300 | 112 | 900 | 35 |

400 | 90 | 1000 | 0 |

500 | 90 |

Choose the correct answer. When Simpson’s rule is used to approximate the definite integral, it is necessary that the number of partitions be____

- an even number
- odd number
- either an even or an odd number
- a multiple of 4

The error formula for Simpson’s rule depends on___.

- $f(x)$
- ${f}^{\prime}(x)$
- ${f}^{(4)}(x)$
- the number of steps