$$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\kernel}{\mathrm{null}\,}$$ $$\newcommand{\range}{\mathrm{range}\,}$$ $$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$ $$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}[1]{\| #1 \|}$$ $$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$ $$\newcommand{\Span}{\mathrm{span}}$$

7.6: Numerical Integration

[ "article:topic", "midpoint rule", "authorname:openstax", "relative error", "absolute error", "numerical integration", "license:ccby" ]

$$\newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$

$$\newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$

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 $$\displaystyle f(x)$$ over an interval $$\displaystyle [a,b]$$ may be viewed as an estimate of $$\displaystyle ∫^b_af(x)dx$$. Recall that a Riemann sum of a function $$\displaystyle f(x)$$ over an interval $$\displaystyle [a,b]$$ is obtained by selecting a partition

$$\displaystyle P={x_0,x_1,x_2,…,x_n},$$ where $$\displaystyle a=x_0<x_1<x_2<⋯<x_n=b$$

and a set

$$\displaystyle S={x^*_1,x^*_2,…,x^*_n},$$ where $$\displaystyle x_{i−1}≤x^*_i≤x_i$$ for all $$\displaystyle i$$.

The Riemann sum corresponding to the partition $$\displaystyle P$$ and the set $$\displaystyle S$$ is given by $$\displaystyle n\sum^n_{i=1}f(x^*_i)Δx_i$$, where $$\displaystyle Δx_i=x_i−x_{i−1},$$ the length of the $$\displaystyle i$$th subinterval.

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

The Midpoint Rule

Assume that $$\displaystyle f(x)$$ is continuous on $$\displaystyle [a,b]$$. Let $$\displaystyle n$$ be a positive integer and $$\displaystyle Δx=\frac{b−a}{n}$$. If $$\displaystyle [a,b]$$ is divided into $$\displaystyle n$$ subintervals, each of length $$\displaystyle Δx$$, and $$\displaystyle m_i$$ is the midpoint of the ith subinterval, set

$M_n=\sum_{i=1}^nf(m_i)Δx.$

Then $$\displaystyle \lim_{n→∞}M_n=∫^b_af(x)dx.$$

As we can see in Figure, if $$\displaystyle f(x)≥0$$ over $$\displaystyle [a,b]$$, then $$\displaystyle \sum^n_{i=1}f(m_i)Δx$$ corresponds to the sum of the areas of rectangles approximating the area between the graph of $$\displaystyle f(x)$$ and the x-axis over $$\displaystyle [a,b]$$. The graph shows the rectangles corresponding to $$\displaystyle M_4$$ for a nonnegative function over a closed interval $$\displaystyle [a,b].$$

Figure $$\PageIndex{1}$$: The midpoint rule approximates the area between the graph of $$\displaystyle f(x)$$ and the x-axis by summing the areas of rectangles with midpoints that are points on $$\displaystyle f(x)$$.

Example $$\displaystyle \PageIndex{1}$$:

Using the Midpoint Rule with $$\displaystyle M_4$$

Use the midpoint rule to estimate $$\displaystyle ∫^1_0x^2dx$$ using four subintervals. Compare the result with the actual value of this integral.

Solution: Each subinterval has length $$\displaystyle Δx=\frac{1−0}{4}=\frac{1}{4}.$$ Therefore, the subintervals consist of

$$\displaystyle [0,\frac{1}{4}],[\frac{1}{4},\frac{1}{2}],[\frac{1}{2},\frac{3}{4}],$$ and $$\displaystyle [\frac{3}{4},1].$$

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

$$\displaystyle M_4=\frac{1}{4}f(\frac{1}{8})+\frac{1}{4}f(\frac{3}{8})+\frac{1}{4}f(\frac{5}{8})+\frac{1}{4}f(\frac{7}{8})=\frac{1}{4}⋅\frac{1}{64}+\frac{1}{4}⋅\frac{9}{64}+\frac{1}{4}⋅\frac{25}{64}+\frac{1}{4}⋅\frac{21}{64}=\frac{21}{64}.$$

Since

$$\displaystyle ∫^1_0x^2dx=\frac{1}{3}$$ and $$\displaystyle ∣\frac{1}{3}−\frac{21}{64}∣=\frac{1}{192}≈0.0052,$$

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

Example $$\displaystyle \PageIndex{2}$$:

Using the Midpoint Rule with $$\displaystyle M_6$$

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

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

$$\displaystyle ∫^4_1\sqrt{1+(\sqrt{dy}{dx})^2}dx.$$

Since $$\displaystyle \frac{dy}{dx}=x$$, this integral becomes $$\displaystyle ∫^4_1\sqrt{1+x^2}dx.$$

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

$$\displaystyle M_6=\frac{1}{2}f(\frac{5}{4})+\frac{1}{2}f(\frac{7}{4})+\frac{1}{2}f(\frac{9}{4})+\frac{1}{2}f(\frac{11}{4})+\frac{1}{2}f(\frac{13}{4})+\frac{1}{2}f(\frac{15}{4})$$

$$\displaystyle ≈\frac{1}{2}(1.6008+2.0156+2.4622+2.9262+3.4004+3.8810)=8.1431.$$

Exercise $$\PageIndex{1}$$

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

Hint

$$\displaystyle Δx=\frac{1}{2}, m_1=\frac{5}{4},$$ and $$\displaystyle m_2=\frac{7}{4}.$$

$$\displaystyle \frac{24}{35}$$

The Trapezoidal Rule

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

Figure $$\PageIndex{2}$$: Trapezoids may be used to approximate the area under a curve, hence approximating the definite integral.

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. We assume that the length of each subinterval is given by $$\displaystyle Δx$$. First, recall that the area of a trapezoid with a height of h and bases of length $$\displaystyle b_1$$ and $$\displaystyle b_2$$ is given by $$\displaystyle Area=\frac{1}{2}h(b_1+b_2)$$. We see that the first trapezoid has a height $$\displaystyle Δx$$ and parallel bases of length $$\displaystyle f(x_0)$$ and $$\displaystyle f(x_1)$$. Thus, the area of the first trapezoid in Figure is

$$\displaystyle \frac{1}{2}Δx(f(x_0)+f(x_1))$$.

The areas of the remaining three trapezoids are

$$\displaystyle \frac{1}{2}Δx(f(x_1)+f(x_2)),\frac{1}{2}Δx(f(x_2)+f(x_3)),$$ and $$\displaystyle \frac{1}{2}Δx(f(x_3)+f(x_4)).$$

Consequently,

$$\displaystyle ∫^b_af(x)dx≈\frac{1}{2Δ}x(f(x_0)+f(x_1))+\frac{1}{2}Δx(f(x_1)+f(x_2))+\frac{1}{2}Δx(f(x_2)+f(x_3))+\frac{1}{2}Δx(f(x_3)+f(x_4)).$$

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

$$\displaystyle ∫^b_af(x)dx≈\frac{1}{2}Δx(f(x_0)+2f(x_1)+2f(x_2)+2f(x_3)+f(x_4)).$$

Generalizing, we formally state the following rule.

The Trapezoidal Rule

Assume that $$\displaystyle f(x)$$ is continuous over $$\displaystyle [a,b]$$. Let $$\displaystyle n$$ be a positive integer and $$\displaystyle Δx=\frac{b−a}{n}$$. Let $$\displaystyle [a,b]$$ be divided into $$\displaystyle n$$ subintervals, each of length $$\displaystyle Δx$$, with endpoints at $$\displaystyle P={x_0,x_1,x_2…,x_n}.$$ Set

$$\displaystyle T_n=\frac{1}{2}Δx(f(x_0)+2f(x_1)+2f(x_2)+⋯+2f(x_{n−1})+f(x_n)).$$

Then, $$\displaystyle \lim_{n→+∞}T_n=∫^b_af(x)dx.$$

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

$$\displaystyle T_n=\frac{1}{2}(L_n+R_n)$$ where $$\displaystyle L_n=\sum_{i=1}^nf(x_{i−1})Δx$$ and $$\displaystyle R_n=\sum_{i=1}^nf(x_i)Δx.$$

That is, $$\displaystyle L_n$$ and $$\displaystyle R_n$$ approximate the integral using the left-hand and right-hand endpoints of each subinterval, respectively. In addition, a careful examination of Figure 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.

Figure $$\PageIndex{3}$$:The trapezoidal rule tends to be less accurate than the midpoint rule.

Example $$\displaystyle \PageIndex{3}$$:

Using the Trapezoidal Rule

Use the trapezoidal rule to estimate $$\displaystyle ∫^1_0x^2dx$$ using four subintervals.

Solution

The endpoints of the subintervals consist of elements of the set $$\displaystyle P={0,\frac{1}{4},\frac{1}{2},\frac{3}{4},1}$$ and $$\displaystyle Δx=\frac{1−0}{4}=\frac{1}{4}.$$ Thus,

$$\displaystyle ∫^1_0x^2dx≈\frac{1}{2}⋅\frac{1}{4}(f(0)+2f(\frac{1}{4})+2f(\frac{1}{2})+2f(\frac{3}{4})+f(1))=\frac{1}{8}(0+2⋅\frac{1}{16}+2⋅\frac{1}{4}+2⋅\frac{9}{16}+1)=\frac{11}{32}$$

Exercise $$\PageIndex{2}$$

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

Hint

Set $$\displaystyle Δx=\frac{1}{2}.$$ The endpoints of the subintervals are the elements of the set $$\displaystyle P={1,\frac{3}{2},2}.$$

$$\displaystyle \frac{17}{24}$$

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 $$\displaystyle B$$ is our estimate of some quantity having an actual value of $$\displaystyle A$$, then the absolute error is given by $$\displaystyle |A−B|$$. The relative error is the error as a percentage of the absolute value and is given by $$\displaystyle ∣\frac{A−B}{A}∣=∣\frac{A−B}{A}∣⋅100%.$$

Example $$\displaystyle \PageIndex{4}$$:

Calculating Error in the Midpoint Rule

Calculate the absolute and relative error in the estimate of $$\displaystyle ∫^1_0x^2dx$$ using the midpoint rule, found in Example.

Solutiom: The calculated value is $$\displaystyle ∫^1_0x^2dx=\frac{1}{3}$$ and our estimate from the example is $$\displaystyle M_4=\frac{21}{64}$$. Thus, the absolute error is given by $$\displaystyle ∣(\frac{1}{3})−(\frac{21}{64})∣=\frac{1}{192}≈0.0052.$$ The relative error is

$$\displaystyle \frac{1/192}{1/3}=\frac{1}{64}≈0.015625≈1.6%.$$

Example $$\displaystyle \PageIndex{5}$$:

Calculating Error in the Trapezoidal Rule

Calculate the absolute and relative error in the estimate of $$\displaystyle ∫^1_0x^2dx$$ using the trapezoidal rule, found in Example.

Solution: The calculated value is $$\displaystyle ∫^1_0x^2dx=\frac{1}{3}$$ and our estimate from the example is $$\displaystyle T_4=\frac{11}{32}$$. Thus, the absolute error is given by $$\displaystyle ∣\frac{1}{3}−\frac{11}{32}∣=\frac{1}{96}≈0.0104.$$ The relative error is given by

$$\displaystyle \frac{1/96}{1/3}=0.03125≈3.1%.$$

Exercise $$\PageIndex{3}$$

In an earlier checkpoint, we estimated $$\displaystyle ∫^2_1\frac{1}{x}dx$$ to be $$\displaystyle \frac{24}{35}$$ using $$\displaystyle T_2$$. The actual value of this integral is $$\displaystyle ln2$$. Using $$\displaystyle \frac{24}{35}≈0.6857$$ and $$\displaystyle ln2≈0.6931,$$ calculate the absolute error and the relative error.

Hint

Use the previous examples as a guide.

$$\displaystyle 0.0074, 1.1%$$

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 $$\displaystyle f(x)$$ be a continuous function over $$\displaystyle [a,b]$$, having a second derivative $$\displaystyle f''(x)$$ over this interval. If $$\displaystyle M$$ is the maximum value of $$\displaystyle |f''(x)|$$ over $$\displaystyle [a,b]$$, then the upper bounds for the error in using $$\displaystyle M_n$$ and $$\displaystyle T_n$$ to estimate $$\displaystyle ∫^b_af(x)dx$$ are

$Error inM_n≤\frac{M(b−a)^3}{24n^2}$

and

$Error inT_n≤\frac{M(b−a)^3}{12n^2}$.

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 $$\displaystyle \PageIndex{6}$$:

Determining the Number of Intervals to Use

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

Solution

We begin by determining the value of $$\displaystyle M$$, the maximum value of $$\displaystyle |f''(x)|$$ over $$\displaystyle [0,1]$$ for $$\displaystyle f(x)=e^{x^2}$$. Since $$\displaystyle f′(x)=2xe^{x^2},$$ we have

$$\displaystyle f''(x)=2e^{x^2}+4x^2e^{x^2}$$.

Thus,

$$\displaystyle |f''(x)|=2e^{x^2}(1+2x^2)≤2⋅e⋅3=6e.$$

From the error-bound Equation, we have

$$\displaystyle Error inM_n≤\frac{M(b−a)^3}{24n^2}≤\frac{6e(1−0)^3}{24n^2}=\frac{6e}{24n^2}$$.

Now we solve the following inequality for $$\displaystyle n$$:

$$\displaystyle \frac{6e}{24n^2}≤0.01.$$

Thus, $$\displaystyle n≥\sqrt{\frac{600e}{24}}≈8.24.$$ Since n must be an integer satisfying this inequality, a choice of $$\displaystyle n=9$$ would guarantee that $$\displaystyle ∣∫^1_0e^{x^2}dx−M_n∣<0.01.$$

Analysis

We might have been tempted to round $$\displaystyle 8.24$$ down and choose $$\displaystyle n=8$$, but this would be incorrect because we must have an integer greater than or equal to $$\displaystyle 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.

Exercise $$\PageIndex{4}$$

Use Equation to find an upper bound for the error in using $$\displaystyle M_4$$ to estimate $$\displaystyle ∫^1_0x^2dx.$$

Hint

$$\displaystyle f''(x)=2,$$ so $$\displaystyle M=2.$$

$$\displaystyle \frac{1}{192}$$

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 $$\displaystyle ∫^{x_2}_{x_0}f(x)dx$$ with $$\displaystyle ∫^{x_2}_{x_0}p(x)dx$$, where $$\displaystyle p(x)=Ax^2+Bx+C$$ is the quadratic function passing through $$\displaystyle (x_0,f(x_0)), (x_1,f(x_1)),$$ and $$\displaystyle (x_2,f(x_2))$$ (Figure). Over the next pair of subintervals we approximate $$\displaystyle ∫^{x_4}_{x_2}f(x)dx$$ with the integral of another quadratic function passing through $$\displaystyle (x_2,f(x_2)), (x_3,f(x_3)),$$ and $$\displaystyle (x_4,f(x_4)).$$ This process is continued with each successive pair of subintervals.

Figure $$\PageIndex{4}$$: With Simpson’s rule, we approximate a definite integral by integrating a piecewise quadratic function.

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:

$$\displaystyle f(x_0)=p(x_0)=Ax_0^2+Bx_0+C$$

$$\displaystyle f(x_1)=p(x_1)=Ax_1^2+Bx_1+C$$

$$\displaystyle f(x_2)=p(x_2)=Ax_2^2+Bx_2+C$$

$$\displaystyle x_2−x_0=2Δx$$, where $$\displaystyle Δx$$ is the length of a subinterval.

$$\displaystyle x_2+x_0=2x_1,$$ since $$\displaystyle x_1=\frac{(x_2+x_0)}{2}$$.

Thus,

$$\displaystyle ∫^{x_2}_{x_0}f(x)dx≈∫^{x_2}_{x_0}p(x)dx$$

$$\displaystyle =∫^{x_2}_{x_0}(Ax^2+Bx+C)dx$$

$$\displaystyle =\frac{A}{3}x^3+\frac{B}{2}x^2+Cx∣^{x_2}_{x_0}$$    Find the antiderivative

$$\displaystyle =\frac{A}{3}(x_2^3−x_0^3)+\frac{B}{2}(x_2^2−x_0^2)+C(x_2−x_0)$$    Evaluate the antiderivative.

$$\displaystyle =\frac{A}{3}(x_2−x_0)(x_2^2+x_2x_0+x_0^2)+\frac{B}{2}(x_2−x_0)(x_2+x_0)+C(x_2−x_0)$$

$$\displaystyle =\frac{x_2−x_0}{6}(2A(x_2^2+x_2x_0+x_0^2)+3B(x_2+x_0)+6C)$$    Factor out $$\displaystyle \frac{x_2−x_0}{6}.$$

$$\displaystyle =\frac{Δx}{3}((Ax_2^2+Bx_2+C)+(Ax_0^2+Bx_0+C)+A(x_2^2+2x_2x_0+x_0^2)+2B(x_2+x_0)+4C)$$

$$\displaystyle =\frac{Δx}{3}(f(x_2)+f(x_0)+A(x_2+x_0)^2+2B(x_2+x_0)+4C)$$    Rearrange the terms

Factor and substitute. $$\displaystyle f(x_2)=Ax_0^2+Bx_0+C$$ and $$\displaystyle f(x_0)=Ax_0^2+Bx_0+C.$$

$$\displaystyle =\frac{Δx}{3}(f(x_2)+f(x_0)+A(2x_1)^2+2B(2x_1)+4C)$$    Substitute $$\displaystyle x_2+x_0=2x_1$$.

$$\displaystyle =\frac{Δx}{3}(f(x_2)+4f(x_1)+f(x_0)).$$    Expand and substitute $$\displaystyle f(x_1)=Ax_1^2+Bx_1+.$$

If we approximate $$\displaystyle ∫^{x_4}_{x_2}f(x)dx$$ using the same method, we see that we have

$$\displaystyle ∫^{x^4}_{x_0}f(x)dx≈\frac{Δx}{3}(f(x_4)+4f(x_3)+f(x_2)).$$

Combining these two approximations, we get

$$\displaystyle ∫^{x_4}_{x_0}f(x)dx=\frac{Δx}{3}(f(x_0)+4f(x_1)+2f(x_2)+4f(x_3)+f(x_4)).$$

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 $$\displaystyle f(x)$$ is continuous over $$\displaystyle [a,b]$$. Let n be a positive even integer and $$\displaystyle Δx=\frac{b−a}{n}$$. Let $$\displaystyle [a,b]$$ be divided into n subintervals, each of length $$\displaystyle Δx$$, with endpoints at $$\displaystyle P={x_0,x_1,x_2,…,x_n}.$$ Set

$$\displaystyle S_n=\frac{Δx}{3}(f(x_0)+4f(x_1)+2f(x_2)+4f(x_3)+2f(x_4)+⋯+2f(x_{n−2})+4f(x_{n−1})+f(x_n)).$$

Then,

$\lim_{n→+∞}S_n=∫^b_af(x)dx.$

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 $$\displaystyle S_{2n}=(\frac{2}{3})M_n+(\frac{1}{3})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 $$\displaystyle f(x)$$ be a continuous function over $$\displaystyle [a,b]$$ having a fourth derivative, $$\displaystyle f^{(4)}(x)$$, over this interval. If $$\displaystyle M$$ is the maximum value of $$\displaystyle ∣f^{(4)}(x)∣$$ over $$\displaystyle [a,b]$$, then the upper bound for the error in using $$\displaystyle S_n$$ to estimate $$\displaystyle ∫^b_af(x)dx$$ is given by

$Error in S_n≤\frac{M(b−a)^5}{180n^4}$.

Example $$\displaystyle \PageIndex{7}$$: Applying Simpson’s Rule 1

Use $$\displaystyle S_2$$ to approximate $$\displaystyle ∫^1_0x^3dx$$. Estimate a bound for the error in $$\displaystyle S_2$$.

Solution

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

$$\displaystyle S_4=\frac{1}{3}⋅\frac{1}{2}(f(0)+4f(\frac{1}{2})+f(1))=\frac{1}{6}(0+4⋅\frac{1}{8}+1)=\frac{1}{4}.$$

Since $$\displaystyle f^{(4)}(x)=0$$ and consequently $$\displaystyle M=0,$$ we see that

Error in $$\displaystyle S_2≤\frac{0(1)^5}{180⋅2^4}=0.$$

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

Example $$\displaystyle \PageIndex{8}$$: Applying Simpson’s Rule 2

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

Solution

The length of $$\displaystyle y=\frac{1}{2}x^2$$ over $$\displaystyle [1,4]$$ is $$\displaystyle ∫^4_1\sqrt{1+x^2}dx$$. If we divide $$\displaystyle [1,4]$$ into six subintervals, then each subinterval has length $$\displaystyle Δx=\frac{4−1}{6}=\frac{1}{2}$$, and the endpoints of the subintervals are $$\displaystyle {1,\frac{3}{2},2,\frac{5}{2},3,\frac{7}{2},4}.$$ Setting $$\displaystyle f(x)=\sqrt{1+x^2}$$,

$$\displaystyle S_6=\frac{1}{3}⋅\frac{1}{2}(f(1)+4f(\frac{3}{2})+2f(2)+4f(\frac{5}{2})+2f(3)+4f(\frac{7}{2})+f(4)).$$

After substituting, we have

$$\displaystyle S_6=\frac{1}{6}(1.4142+4⋅1.80278+2⋅2.23607+4⋅2.69258+2⋅3.16228+4⋅3.64005+4.12311)≈8.14594.$$

Exercise $$\PageIndex{5}$$

Use $$\displaystyle S_2$$ to estimate $$\displaystyle ∫^2_1\frac{1}{x}dx.$$

Hint

$$\displaystyle S_2=(\frac{1}{3}Δx(f(x_0)+4f(x_1)+f(x_2))$$

$$\displaystyle \frac{25}{36}$$

Key Concepts

• We can use numerical integration to estimate the values of definite integrals when a closed form of the integral is difficult to find or when an approximate value only of the definite integral is needed.
• The most commonly used techniques for numerical integration are the midpoint rule, trapezoidal rule, and Simpson’s rule.
• The midpoint rule approximates the definite integral using rectangular regions whereas the trapezoidal rule approximates the definite integral using trapezoidal approximations.
• Simpson’s rule approximates the definite integral by first approximating the original function using piecewise quadratic functions.

Key Equations

• Midpoint rule

$$\displaystyle M_n=\sum^n_{i=1}f(m_i)Δx$$

• Trapezoidal rule

$$\displaystyle T_n=\frac{1}{2}Δx(f(x_0)+2f(x_1)+2f(x_2)+⋯+2f(x_{n−1})+f(x_n))$$

• Simpson’s rule

$$\displaystyle S_n=\frac{Δx}{3}(f(x_0)+4f(x_1)+2f(x_2)+4f(x_3)+2f(x_4)+4f(x_5)+⋯+2f(x_{n−2})+4f(x_{n−1})+f(x_n))$$

• Error bound for midpoint rule

Error in $$\displaystyle M_n≤\frac{M(b−a)^3}{24n^2}$$

• Error bound for trapezoidal rule

Error in $$\displaystyle T_n≤\frac{M(b−a)^3}{12n^2}$$

• Error bound for Simpson’s rule

Error in $$\displaystyle S_n≤\frac{M(b−a)^5}{180n^4}$$

Glossary

absolute error
if $$\displaystyle B$$ is an estimate of some quantity having an actual value of $$\displaystyle A$$, then the absolute error is given by $$\displaystyle |A−B|$$
midpoint rule
a rule that uses a Riemann sum of the form $$\displaystyle M_n=\sum^n_{i=1}f(m_i)Δx$$, where $$\displaystyle m_i$$ is the midpoint of the $$\displaystyle i$$th subinterval to approximate $$\displaystyle ∫^b_af(x)dx$$
numerical integration
the variety of numerical methods used to estimate the value of a definite integral, including the midpoint rule, trapezoidal rule, and Simpson’s rule
relative error
error as a percentage of the absolute value, given by $$\displaystyle ∣\frac{A−B}{A}∣=∣\frac{A−B}{A}∣⋅100%$$
Simpson’s rule
a rule that approximates $$\displaystyle ∫^b_af(x)dx$$ using the integrals of a piecewise quadratic function. The approximation $$\displaystyle S_n$$ to $$\displaystyle ∫^b_af(x)dx$$ is given by $$\displaystyle S_n=\frac{Δx}{3}(f(x_0)+4f(x_1)+2f(x_2)+4f(x_3)+2f(x_4)+4f(x_5)+⋯+2f(x_{n−2})+4f(x_{n−1})+f(x_n))$$  trapezoidal rule a rule that approximates $$\displaystyle ∫^b_af(x)dx$$ using trapezoids