Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

8.7: Numerical Integration

( \newcommand{\kernel}{\mathrm{null}\,}\)

We have now seen some of the most generally useful methods for discovering antiderivatives, and there are others. Unfortunately, some functions have no simple antiderivatives; in such cases if the value of a definite integral is needed it will have to be approximated. We will see two methods that work reasonably well and yet are fairly simple; in some cases more sophisticated techniques will be needed.

Of course, we already know one way to approximate an integral: if we think of the integral as computing an area, we can add up the areas of some rectangles. While this is quite simple, it is usually the case that a large number of rectangles is needed to get acceptable accuracy. A similar approach is much better: we approximate the area under a curve over a small interval as the area of a trapezoid. In figure 8.6.1 we see an area under a curve approximated by rectangles and by trapezoids; it is apparent that the trapezoids give a substantially better approximation on each subinterval.

Approximating an area with rectangles and with trapezoids.

Figure 8.6.1. Approximating an area with rectangles and with trapezoids.

As with rectangles, we divide the interval into n equal subintervals of length Δx. A typical trapezoid is pictured in figure 8.6.2; it has area f(xi)+f(xi+1)2Δx. If we add up the areas of all trapezoids we get

f(x0)+f(x1)2Δx+f(x1)+f(x2)2Δx++f(xn1)+f(xn)2Δx=(f(x0)2+f(x1)+f(x2)++f(xn1)+f(xn)2)Δx.

This is usually known as the Trapezoid Rule. For a modest number of subintervals this is not too difficult to do with a calculator; a computer can easily do many subintervals.

A single trapezoid.

Figure 8.6.2. A single trapezoid.

In practice, an approximation is useful only if we know how accurate it is; for example, we might need a particular value accurate to three decimal places. When we compute a particular approximation to an integral, the error is the difference between the approximation and the true value of the integral. For any approximation technique, we need an error estimate, a value that is guaranteed to be larger than the actual error. If A is an approximation and E is the associated error estimate, then we know that the true value of the integral is between AE and A+E. In the case of our approximation of the integral, we want E=E(Δx) to be a function of Δx that gets small rapidly as Δx gets small. Fortunately, for many functions, there is such an error estimate associated with the trapezoid approximation.

Theorem 8.6.1: The Trapezoid Approximation

Suppose f has a second derivative f everywhere on the interval [a,b], and |f(x)|M for all x in the interval. With Δx=(ba)/n, an error estimate for the trapezoid approximation is

E(Δx)=ba12M(Δx)2=(ba)312n2M.

Let's see how we can use this.

Had we immediately tried n=13 this would have given us the desired answer.

The trapezoid approximation works well, especially compared to rectangles, because the tops of the trapezoids form a reasonably good approximation to the curve when Δx is fairly small. We can extend this idea: what if we try to approximate the curve more closely, by using something other than a straight line? The obvious candidate is a parabola: if we can approximate a short piece of the curve with a parabola with equation y=ax2+bx+c, we can easily compute the area under the parabola.

There are an infinite number of parabolas through any two given points, but only one through three given points. If we find a parabola through three consecutive points (xi,f(xi)), (xi+1,f(xi+1)), (xi+2,f(xi+2)) on the curve, it should be quite close to the curve over the whole interval [xi,xi+2], as in figure 8.6.3. If we divide the interval [a,b] into an even number of subintervals, we can then approximate the curve by a sequence of parabolas, each covering two of the subintervals.

For this to be practical, we would like a simple formula for the area under one parabola, namely, the parabola through (xi,f(xi)), (xi+1,f(xi+1)), and (xi+2,f(xi+2)). That is, we should attempt to write down the parabola y=ax2+bx+c through these points and then integrate it, and hope that the result is fairly simple. Although the algebra involved is messy, this turns out to be possible. The algebra is well within the capability of a good computer algebra system like Sage, so we will present the result without all of the algebra; you can see how to do it in this Sage worksheet.

To find the parabola, we solve these three equations for a, b, and c:

f(xi)=a(xi+1Δx)2+b(xi+1Δx)+cf(xi+1)=a(xi+1)2+b(xi+1)+cf(xi+2)=a(xi+1+Δx)2+b(xi+1+Δx)+c

Not surprisingly, the solutions turn out to be quite messy. Nevertheless, Sage can easily compute and simplify the integral to get

xi+1+Δxxi+1Δxax2+bx+cdx=Δx3(f(xi)+4f(xi+1)+f(xi+2)).

Now the sum of the areas under all parabolas is

Δx3(f(x0)+4f(x1)+f(x2)+f(x2)+4f(x3)+f(x4)++f(xn2)+4f(xn1)+f(xn))=Δx3(f(x0)+4f(x1)+2f(x2)+4f(x3)+2f(x4)++2f(xn2)+4f(xn1)+f(xn)).

This is just slightly more complicated than the formula for trapezoids; we need to remember the alternating 2 and 4 coefficients. This approximation technique is referred to as Simpson's Rule.

A parabola (dashed) approximating a curve (solid).

Figure 8.6.3. A parabola (dashed) approximating a curve (solid).

As with the trapezoid method, this is useful only with an error estimate:

Theorem 8.6.3: Simpson Approximation Error

Suppose f has a fourth derivative f(4) everywhere on the interval [a,b], and |f(4)(x)|M for all x in the interval. With Δx=(ba)/n, an error estimate for Simpson's approximation is

E(Δx)=ba180M(Δx)4=(ba)5180n4M.

So the true value of the integral is between 0.7468550.0003=0.746555 and 0.746855+0.0003=0.7471555, both of which round to 0.75.

Contributors

David Guichard (Whitman College)

  • Integrated by Justin Marshall.


This page titled 8.7: Numerical Integration is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by David Guichard via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?