# Numerical Integration

We have seen that definite integrals arise in many different areas and that the Fundamental Theorem of Calculus is a powerful tool for evaluating definite integrals. However, it cannot always be applied: there are some functions which do not have an antiderivative which can be expressed in terms of familiar functions such as polynomials, exponentials and trigonometric functions. One such example is ; of course, this is an important function since it is the probability density function for the normal distribution.

In this section, we will demonstrate two tools for approximating a definite integral to any degree of accuracy. These tools can be used to evaluate definite integrals when the integrand has no simple antiderivative. Moreover, we sometimes only have information about a function by making observations at a certain number of points. In that case, we do not have a nice formula for the function we are integrating, but only some data points. Our methods can help us to evaluate a definite integral in this case as well.

The Trapezoidal Rule

In our first method, we will approximate the definite integral by approximating the graph of the function by a straight line. That means that we approximate the area under the graph by the trapezoid formed below.

The area of the trapezoid is just the area of the rectangle plus the area of the triangle. That means our approximation is

Of course, we cannot expect this to be a good approximation. However, we can break the region into many smaller pieces and apply the approximation on each piece. On the smaller pieces, the graph looks more and more like a straight line so the approximation should improve.

Let's choose some positive integer n and break the interval into n equal pieces. The width of each piece is .

We will label the points defined by the sub-intervals by and call . If we the approximate the area under the graph by the area of the trapezoids, we have

Example: We will consider the integral . Of course, we can evaluate this integral directly with the Fundamental Theorem of Calculus: . We now will build the trapezoidal approximation so that we might see explicitly how much of an error we are making.

First, we will consider . In this case, . There are only two points and . Then we have and . Then the trapezoidal rule produces

This means that the Trapezoidal Rule with produces an approximation of to the integral which we know is .

Now let's see what happens when . In this case, we have . The points for us to consider are and . This produces and . Then we have

Clearly, this is a better approximation. The following demonstration will show what happens when we increase n further. Notice that the approximation becomes quite good. The reason for this is clear from the picture: as the size of the intervals becomes very small, the graph is better approximated by a straight line on each interval.

Simpson's Rule

In the example above, you can see that the Trapezoidal Rule provides a reasonable approximation to a definite integral if we take a large number of steps. Notice that the error in the approximation originates in the fact that general graphs are curved and we are approximating them by straight lines. We will now form an approximation which takes into account the curvature of the graph: the result is a more efficient approximation called Simpson's Rule.

Simpson's Rule is formed by approximating a general curve by a parabola.

In this picture, the red graph is a parabola which approximates the blue graph. Remember that a parabola is the graph of a quadratic function and so three pieces of information are required to determine the coefficients , and . This means that we must use three data points and to fix the parabola.

We won't show you how to determine the coefficients for the parabola, but it is fairly straightforward. As before, the width of each of the two intervals is . With a little bit of work, you would find the approximation

This is Simpson's Rule with one step. More generally, we can break the interval into several pieces and apply Simpson's Rule on each interval. For instance, to use n steps, break the interval into pieces, each of width . Call the x coordinates and let . Then we have

This is the same idea as the Trapezoidal Rule but you see that the algorithm is slightly different. Inside the sum, the endpoints are weighted once, while the odd values of are weigted four times and the even values of in the middle are weighted twice.

Examples:

1. First, we'll consider the same example as we studied with the Trapezoidal Rule: .

Let's apply Simpson's Rule with one term: so that . Then and . This means that and .

Now applying Simpson's Rule gives

This means that, with one step, Simpson's Rule gives the correct answer. This shouldn't be too surprising since the Rule uses a parabola to approximate the graph. In this case, the graph we are interested in is already a parabola and so Simpson's Rule will produce the correct answer. In comparing to the Trapezoidal Rule, you can see the savings in effort: there we needed many steps to get a good approximation to the integral.

2. Consider the integral .

You have probably been told for most of your mathematical career that but you have probably never seen where that number comes from. We can use Simpson's Rule to approximate the integral and then use the fact that

to obtain an approximation for .

With , we have and and . This means that and .

Our approximation is then

This gives an approximation for . So with just one step, we have a pretty good approximation for .

With , we have

This produces an approximation With just two steps of Simpson's Rule, we have computed to four decimal places!

The demonstration below will provide approximations for this integral using both the Trapezoidal Rule and Simpson's Rule. You can see how much better Simpson's Rule really is.

3. Of course, the real value of Simpson's Rule is in computing integrals of functions which cannot be antidifferentiated using familiar functions. One such example is

where the approximation is obtained using Simpson's Rule. This integral is needed to determine the probability that a typical sample lies within one standard deviation of the mean in the normal distribution.