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. The Getting started worksheet contains two proofs of the following result,

    \begin{displaymath}\int_{m-h}^{m+h} f(x) \, dx \approx \frac{h}{3}
(f(m-h)+4f(m)+f(m+h))\end{displaymath}

    which is Simpson's rule applied to the interval $[m-h,m+h]$ using two subintervals. Explain why this result implies the formula given below for Simpson's rule over $n$ subintervals, where $n$ is even.

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

  2. 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)
    Find the minimum number of subintervals required so that $T_n$ satisfies the tolerance

    \begin{displaymath}\mid \int_a^b f(x) \, dx -T_n \mid < 0.001 \end{displaymath}

    Compare this number to the one you would get by using the error estimate for the trapezoidal rule.
    (iii)
    Find the minimum number of subintervals required so that $S_n$ satisfies the tolerance

    \begin{displaymath}\mid \int_a^b f(x) \, dx -S_n \mid < 0.001 \end{displaymath}

    Compare this number to the one you would get by using the error estimate for Simpson's rule.
    1. $\displaystyle f(x) = (x^2+3x+5)^{\frac{3}{2}}$, interval $[0,10]$.
    2. $\displaystyle f(x) = \frac{\cos(x)}{x-1}$, interval $[-1,0.99]$.
  3. Consider the error function

    \begin{displaymath}\mathrm{erf}(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2} \, dt \end{displaymath}

    Use Simpson's rule to approximate $\mathrm{erf}(4)$ to within an accuracy of $0.3$ and determine the minimum number of subintervals required. In a previous lab, you used Taylor polynomials to approximate this same integral. Which method do you think is better? Justify your answer.

  4. Consider the function

    \begin{displaymath}g(x) = \frac{x^3-3x^2-4x-5}{x^2-7x+1} \end{displaymath}

    Using Simpson's rule, find the minimum number of steps required to approximation each of the two integrals below to within $0.001$.

    \begin{displaymath}\int_{-4}^{0} g(x) \, dx \end{displaymath}

    and

    \begin{displaymath}\int_{-4}^{-1} g(x) \, dx \end{displaymath}

    Can you use the error estimate to explain why there is such a big difference between the number of subintervals required?

  5. Simpson's rule usually requires fewer subintervals than the trapezoidal rule for the same accuracy, but this is not always true. Consider the following integral.

    \begin{displaymath}\int_{0}^{4} \left(16-x^2 \right)^{5/2} \, dx \end{displaymath}

    For this integral, you should find that with an equal number of subintervals, the trapezoidal rule gives a more accurate answer. Verify that this is true for several values of $n$, $6 \leq n
\leq 20$. Can you explain this by using the error estimates?


next up previous
Next: About this document ... Up: lab_template Previous: lab_template
William W. Farr
2000-10-06