next up previous
Next: About this document ... Up: lab_template Previous: lab_template

Subsections


Numerical Integration

Purpose

The purpose of this lab is to give you some experience with using the trapezoidal rule and Simpson's rule to approximate integrals.

Getting Started

To assist you, there is a worksheet associated with this lab that contains examples and even solutions to some of the exercises. You can copy that worksheet to your home directory with the following command, which must be run in a terminal window, not in Maple.

cp ~bfarr/NumInt_start.mws ~

You can copy the worksheet now, but you should read through the lab before you load it into Maple. Once you have read to the exercises, start up Maple, load the worksheet NumInt_start.mws, and go through it carefully. Then you can start working on the exercises.

Background

In class we have talked about the trapezoidal rule and Simpson's rule for approximating the definite integral

\begin{displaymath}\int_{a}^{b} f(x) \, dx \end{displaymath}

Both methods start by dividing the interval $[a,b]$ into $n$ subintervals of equal length by choosing a partition

\begin{displaymath}a = x_0 < x_1 < x_2 < \ldots < x_n = b \end{displaymath}

satisfying

\begin{displaymath}x_i = a + i h, \mbox{ for $i=0, \ldots, n$} \end{displaymath}

where

\begin{displaymath}h = \frac{b-a}{n} \end{displaymath}

is the length of each subinterval. For the trapezoidal rule, the integral over each subinterval is approximated by the area of a trapezoid. This gives the following approximation to the integral

\begin{displaymath}T_n = \frac{h}{2} \left( f(x_0) + 2 f(x_1) + 2 f(x_2) + \ldots + 2
f(x_{n-1}) + f(x_n) \right) \end{displaymath}

There is also an error term associated with the trapezoidal rule that can be used to estimate the error. More precisely, we have

\begin{displaymath}\int_{a}^{b} f(x) \, dx = T_n + E_n \end{displaymath}

where

\begin{displaymath}E_n = - \frac{(b-a)^3 f''(c)}{12n^2} \end{displaymath}

for some value $c$ between $a$ and $b$.

One way to use this error term is as a way to bound the number of subintervals required to achieve a certain tolerance. That is, suppose $\varepsilon$ is a small number and we want to determine a value of $n$ that guarantees

\begin{displaymath}\mid E_n \mid < \varepsilon \end{displaymath}

If we substitute the error formula from above into this inequality and rearrange it to isolate $n^2$ we get the following.

\begin{displaymath}n^2 > \frac{(b-a)^3}{12 \varepsilon} \mid f''(c) \mid \end{displaymath}

Now, if we let $M$ be the maximum of $\mid f''(x) \mid$ on the interval $[a,b]$, we can take the square root of both sides of the equation to obtain the following estimate for $n$.

\begin{displaymath}n > \sqrt{\frac{(b-a)^3 M}{12 \varepsilon}} \end{displaymath}

The way to think about this result is that it gives a value for $n$ which guarantees that the error of the trapezoidal rule is less than the tolerance $\varepsilon$. It is generally a very conservative result. As you will discover in the exercises, the actual number of subintervals required to satisfy the tolerance is usually much smaller than the number given by the error estimate.

For Simpson's rule, the function is approximated by a parabola over pairs of subintervals. When the areas under the parabolas are computed and summed up, the result is the following approximation.

\begin{displaymath}S_n = \frac{h}{3} \left( f(x_0) + 4 f(x_1) + 2 f(x_2) + \ldots + 4
f(x_{n-1}) + f(x_n) \right) \end{displaymath}

As for the trapezoidal rule, there is an error formula which says that

\begin{displaymath}\int_{a}^{b} f(x) \, dx = S_n + E_n \end{displaymath}

where

\begin{displaymath}E_n = - \frac{(b-a)^5 f^{(4)}(c)}{180n^4} \end{displaymath}

for some value $c$ between $a$ and $b$.

As we did for the trapezoidal rule, we can rearrange this formula to allow us to estimate the number of subintervals required so that we can guarantee

\begin{displaymath}\mid E_n \mid < \varepsilon \end{displaymath}

Using essentially the same steps as we used for the trapezoidal rule, we get the following inequality.

\begin{displaymath}n > \sqrt[4]{\frac{(b-a)^5 M}{180 \varepsilon}} \end{displaymath}

where $M$ is the maximum of $\mid f^{(4)}(x) \mid$ on the interval $[a,b]$.

Exercises

  1. For the following functions and intervals, complete the following steps.
    (i)
    By using Maple's int and, possibly, evalf commands, find a good approximation to the integral of the function over the given interval.
    (ii)
    Use the error estimate for the trapezoidal rule to find a value for $n$, the number of subintervals, that ensures that the error in $T_n$ is less than $0.001$. Compute the value of $T_n$ for the value of $n$ you found and verify that it is within $0.001$ of the value you found in part (i).
    (iii)
    Use the error estimate for Simpson's rule to find a value for $n$, the number of subintervals, that ensures that the error in $S_n$ is less than $0.001$. Compute the value of $T_n$ for the value of $n$ you found and verify that it is within $0.001$ of the value you found in part (i).
    1. $\displaystyle f(x) = \sqrt{x+1} \exp(x/2)$, interval $[0,5]$.
    2. $\displaystyle f(x) = \sqrt{x^4-2x^3+2x+5}$, interval $[-2,3]$.

  2. Consider the polynomial $p(x) = x^3+2x^2+3x+1$. Explain why Simpson's rule gives the exact value of the integral

    \begin{displaymath}\int_{-1}^{1} p(x) \, dx = \frac{10}{3} \end{displaymath}

    independently of the number of subintervals you use. You might want to use the value command instead of the evalf command on the outside of your simpson command so the result is a fraction instead of a floating point number.


next up previous
Next: About this document ... Up: lab_template Previous: lab_template
William W. Farr
2001-09-28