<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="standard.css"?>
<!DOCTYPE html SYSTEM "mathml.dtd"
[
<!ENTITY mmlns "http://www.w3.org/1998/Math/MathML">
]>
<html
xmlns:math="http://www.w3.org/1998/Math/MathML"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<!--chapter04.xml from chapter04.tex (TeX4ht, 2000-07-12 16:32:00)-->
<title>chapter04.xml</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css"  href="chapter04.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body marginwidth="100px">
<br /><br />
<a name="x1-2r4"></a>
<h2 class="chapterHead">
Chapter&nbsp;4
<br />
<a name="x1-10004"></a>
<a name="QQ1-1-1"></a>
Integration
</h2>
<!--12-->
<p class="noindent">
In this chapter we show you how to carry out numerical integrations. We will derive
the Simpson and trapezoid rules because they are so easy and give a good idea of
how integration algorithms work, but we will just sketch the other algorithms and
quote some error estimates.
</p>
<h3 class="sectionHead">
4.1
<a name="x1-20004.1"></a>
<a name="QQ1-1-2"></a>
Problem: Integrating a Spectrum
</h3>
<!--20-->
<p class="noindent">
An experiment has measured
<!--l. 20-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>d</mi>
<mi>N</mi>
<mrow>
<mo>(</mo>
<mi>t</mi>
<mo>)</mo>
</mrow>
<mo>/</mo>
<mi>d</mi>
<mi>t</mi>
</mrow>
</math>
,
the number of particles entering a counter, per unit time, as a function of time. Your
<span class="cmbx-10"> problem</span>
is to integrate this spectrum to obtain the number of particles
<!--l. 23-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
</mrow>
</math>
that
entered the counter in the first second:
</p>
<!--l. 24-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-2001r1"  class="label" width="0" />
<mspace class="endlabel" />
<mi>N</mi>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
<mo>=</mo>
<msubsup>
<mo>&int;</mo>
<mrow>
<mn>0</mn>
</mrow>
<mrow>
<mn>1</mn>
</mrow>
</msubsup>
<mi>d</mi>
<mi>N</mi>
<mi>d</mi>
<mi>t</mi>
<mrow>
<mo>(</mo>
<mi>t</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>t</mi>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.1)</mn>
</mrow>
</math>
As an explicit assessment, in
<span class="cmsy-10"> §</span>
<a href="#x1-100004.8"> 4.8</a>
we integrate an exponential spectrum. Nonetheless,
the methods work equally well for integrating a table of numbers.
<h3 class="sectionHead">
4.2
<a name="x1-30004.2"></a>
<a name="QQ1-1-3"></a>
Model: Quadrature, Summing Boxes
</h3>
<!--33-->
<p class="noindent">
The integration of a function may require some cleverness to do analytically,
but it is relatively straightforward on a computer. The Riemann
definition of an integral is the limit of the sum over boxes as the width
<!--l. 36-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>h</mi>
</mrow>
</math>
of the
box approaches zero:
</p>
<!--l. 38-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-3001r2"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>a</mi>
</mrow>
<mrow>
<mi>b</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>=</mo>
<msub>
<mo>lim</mo>
<mrow>
<mi>h</mi>
<mo>&rarr;</mo>
<mn>0</mn>
</mrow>
</msub>
<mfenced open='[' close=']' separators="">
<mi>h</mi>
<msubsup>
<mo>&sum;</mo>
<mrow>
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mrow>
<mrow>
<mo>(</mo>
<mi>b</mi>
<mo>-</mo>
<mi>a</mi>
<mo>)</mo>
</mrow>
<mo>/</mo>
<mi>h</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
</mfenced>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.2)</mn>
</mrow>
</math>
For our problem, the function
<!--l. 41-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
</mrow>
</math>
is
the spectrum as a function of time,
<!--l. 42-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mo>=</mo>
<mi>d</mi>
<mi>N</mi>
<mrow>
<mo>(</mo>
<mi>t</mi>
<mo>)</mo>
</mrow>
<mo>/</mo>
<mi>d</mi>
<mi>t</mi>
</mrow>
</math>
.
   A traditional way to measure the area numerically is to take a piece of graph
paper and count the number of boxes or
<span class="cmti-10"> quadrilaterals</span>
lying below the curve of the
function. For this reason numerical integration is also called
<span class="cmti-10"> numerical quadrature</span>
,
even when it gets beyond the box-counting stage.
<!--51-->
<p class="indent">
The integral of a function
<!--l. 51-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
is approximated numerically by the equivalent of a sum over boxes:
</p>
<!--l. 53-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-3002r3"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>a</mi>
</mrow>
<mrow>
<mi>b</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>&ap;</mo>
<msubsup>
<mo>&sum;</mo>
<mrow>
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mrow>
<mi>N</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.3)</mn>
</mrow>
</math>
In this example,
<!--l. 57-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
</mrow>
</math>
is
evaluated at
<!--l. 57-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
points
in the interval
<!--l. 58-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>[</mo>
<mi>a</mi>
<mo>,</mo>
<mi>b</mi>
<mo>]</mo>
</mrow>
</mrow>
</math>
,
and the function
<!--l. 58-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mi>f</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>&equiv;</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
</mrow>
</math>
are summed with each term in the sum weighted by
<!--l. 60-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
</math>
.
While, in general, the sum in (
<a href="#x1-3002r3"> 4.3</a>
) will give the exact integral only when
<!--l. 61-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
<mo>&rarr;</mo>
<mi>&infin;</mi>
</mrow>
</math>
,
for certain classes of functions it may be exact for finite
<!--l. 63-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
.
   The different integration algorithms amount to different ways of
choosing the points and weights. Generally, the precision increases as
<!--l. 67-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
gets larger, with roundoff error eventually limiting the increase. Because
the &#34;best&#34; approximation depends on the specific behavior of the function
<!--l. 69-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
, there
is no universally best approximation. In fact, some of the automated integration
schemes found in subroutine libraries will switch from one method to another until
they find one that works well.
<a name="x1-30031"></a>
<hr class="float" />
<div align="center" class="float">
<table class="float">
<tr class="float">
<td class="float">
<div class="center"><img src="chapter040x.gif" alt="PIC" /></div>
<div align="center" class="caption">
<table class="caption">
<tr valign="baseline" class="caption">
<td class="id">Figure&nbsp;4.1:</td>
<td class="content">
 The integral
<!--l. 82-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>a</mi>
</mrow>
<mrow>
<mi>b</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
</mrow>
</math>
is the area under the graph of
<!--l. 82-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
from
<!--l. 82-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>a</mi>
</mrow>
</math>
to
<!--l. 82-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>b</mi>
</mrow>
</math>
.
Here we break up the area into four regions of equal widths.
</td>
</tr>
</table>
</div>
<a name="x1-30031"></a>
</td>
</tr>
</table>
</div>
<hr class="endfloat" />
   In the simplest integration schemes, the integrand is approximated by a few terms in the Taylor
series expansion of
<!--l. 86-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
</mrow>
</math>
,
and the terms are integrated. Unless the integrand has some very unusual behaviors
in each interval, successive terms should yield higher and higher precision. In these
so-called Newton-Cotes methods, the total interval is divided into equal subintervals
as shown in Fig.&nbsp;
<a href="#x1-30031"> 4.1</a>
, with the integrand evaluated at equally spaced points
<!--l. 92-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
</math>
.
These algorithms include the trapezoid rule (first-order) and the Simpson rule
(second-order). The corresponding weights are given in Table&nbsp;
<span class="cmbx-10"> ??</span>
. These rules are easy
to apply and are the logical choice if the integrand is tabulated along evenly spaced
points (or if it is tabulated along points that can be mapped onto equally spaced
points).
<!--99-->
<p class="indent">
More accurate integration rules are possible if the points are not constrained to be
equally spaced.
<span class="cmti-10"> Gaussian quadrature</span>
methods have the ingenious ability to
exactly
<a href="chapter042.xml" name="chapter042.xml">
<sup>0</sup>
</a>
integrate the product
of a function times a (
<!--l. 103-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mn>2</mn>
<mi>N</mi>
<mo>-</mo>
<mn>1</mn>
</mrow>
</math>
)
degree polynomial, with only
<!--l. 104-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
function evaluations. This is no harder than evaluating the sum (
<a href="#x1-3002r3"> 4.3</a>
), and explains
why so many computational scientists carry their Gaussian quadrature routines with
them wherever they go.
</p>
<!--109-->
<p class="indent">
In general, results with Gaussian quadrature will be superior to results with
equally spaced points as long as there are no singularities in the integrand or its
derivative. In the latter cases, the use of Simpson's rule may help avoid a
catastrophe, but
</p>
<div class="quote">
<table width="100%" class="quote">
<tr class="quote">
<td class="quote">
<!--114-->
<p class="noindent">
<span class="cmti-10"> you would be better off to remove singularities analytically from your</span>
<span class="cmti-10"> integration before attempting any numerical quadrature</span>
.
</p>
</td>
</tr>
</table>
</div>
<!--118-->
<p class="noindent">
You may be able to do this by breaking the interval down into several subintervals, so
the singularity is at an endpoint where a Gauss point never falls, or by a change of
variable. For example
</p>
<!--l. 121-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<msubsup>
<mo>&int;</mo>
<mrow>
<mo>-</mo>
<mn>1</mn>
</mrow>
<mrow>
<mn>1</mn>
</mrow>
</msubsup>
<mo>|</mo>
<mi>x</mi>
<mo>|</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<msubsup>
<mo>&int;</mo>
<mrow>
<mo>-</mo>
<mn>1</mn>
</mrow>
<mrow>
<mn>0</mn>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mo>-</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>+</mo>
<msubsup>
<mo>&int;</mo>
<mrow>
<mn>0</mn>
</mrow>
<mrow>
<mn>1</mn>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.4)
<malignmark id="x1-3004r4.4"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<msubsup>
<mo>&int;</mo>
<mrow>
<mn>0</mn>
</mrow>
<mrow>
<mn>1</mn>
</mrow>
</msubsup>
<msup>
<mi>x</mi>
<mrow>
<mn>1</mn>
<mo>/</mo>
<mn>3</mn>
</mrow>
</msup>
<mi>d</mi>
<mi>x</mi>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<msubsup>
<mo>&int;</mo>
<mrow>
<mn>0</mn>
</mrow>
<mrow>
<mn>1</mn>
</mrow>
</msubsup>
<mn>3</mn>
<msup>
<mi>y</mi>
<mrow>
<mn>3</mn>
</mrow>
</msup>
<mi>d</mi>
<mi>y</mi>
<mo>,</mo>
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<mrow>
<mo>(</mo>
<mi>y</mi>
<mo>=</mo>
<msup>
<mi>x</mi>
<mrow>
<mn>1</mn>
<mo>/</mo>
<mn>3</mn>
</mrow>
</msup>
<mo>)</mo>
</mrow>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.5)
<malignmark id="x1-3004r4.5"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<msubsup>
<mo>&int;</mo>
<mrow>
<mn>0</mn>
</mrow>
<mrow>
<mn>1</mn>
</mrow>
</msubsup>
<mfrac>
<mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
</mrow>
<mrow>
<msqrt>
<!--
<mi></mi>
   -->
<mn>1</mn>
<mo>-</mo>
<msup>
<mi>x</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</msqrt>
</mrow>
</mfrac>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mn>2</mn>
<msubsup>
<mo>&int;</mo>
<mrow>
<mn>0</mn>
</mrow>
<mrow>
<mn>1</mn>
</mrow>
</msubsup>
<mfrac>
<mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>-</mo>
<msup>
<mi>y</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>y</mi>
</mrow>
<mrow>
<msqrt>
<!--
<mi></mi>
   -->
<mn>2</mn>
<mo>-</mo>
<msup>
<mi>y</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</msqrt>
</mrow>
</mfrac>
<mo>,</mo>
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<mrow>
<mo>(</mo>
<msup>
<mi>y</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
<mo>=</mo>
<mn>1</mn>
<mo>-</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.6)
<malignmark id="x1-3004r4.6"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--129-->
<p class="nopar"></p>
<!--131-->
<p class="indent">
Likewise, if your integrand has a very slow variation in some region, you can
speed up the integration by changing to a variable that compresses that region and
places few points there. Conversely, if your integrand has a very rapid variation in
some region, you may want to change to variables that expand that region to ensure
that no oscillations are missed.
</p>
<h3 class="sectionHead">
4.3
<a name="x1-40004.3"></a>
<a name="QQ1-1-5"></a>
Method: Trapezoid Rule
</h3>
<!--141-->
<p class="noindent">
The trapezoid and Simpson integration rules use values of
<!--l. 141-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
at evenly spaced
values of
<!--l. 142-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>x</mi>
</mrow>
</math>
. They
use
<!--l. 142-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
points
<!--l. 142-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>,</mo>
<mspace class="nbsp" />
<mrow>
<mo>(</mo>
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
<mo>,</mo>
<mi>N</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
, evenly spaced at a
distance
<!--l. 143-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>h</mi>
</mrow>
</math>
apart throughout
the integration region
<!--l. 144-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>[</mo>
<mi>a</mi>
<mo>,</mo>
<mi>b</mi>
<mo>]</mo>
</mrow>
</mrow>
</math>
and
<span class="cmti-10"> include the endpoints</span>
. This means that there are
<!--l. 144-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
<mo>-</mo>
<mn>1</mn>
</mrow>
</math>
intervals
of length
<!--l. 145-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>h</mi>
</mrow>
</math>
:
</p>
<!--l. 146-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<mi>h</mi>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mi>b</mi>
<mo>-</mo>
<mi>a</mi>
</mrow>
<mrow>
<mi>N</mi>
<mo>-</mo>
<mn>1</mn>
</mrow>
</mfrac>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.7)
<malignmark id="x1-4001r4.7"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mi>a</mi>
<mo>+</mo>
<mrow>
<mo>(</mo>
<mi>i</mi>
<mo>-</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
<mi>h</mi>
<mo>,</mo>
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
<mo>,</mo>
<mi>N</mi>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.8)
<malignmark id="x1-4001r4.8"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--149-->
<p class="nopar">
Notice that we start our counting at
<!--l. 150-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
</math>
,
and that Simpson's rule requires an
<span class="cmti-10"> odd</span>
number of points
<!--l. 151-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
.
</p>
<!--153-->
<p class="indent">
In Fig.
<a href="#x1-40032"> 4.2</a>
we see that in the trapezoid rule we take the integration interval
<!--l. 154-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>i</mi>
</mrow>
</math>
and construct a trapezoid
of width
<!--l. 155-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>h</mi>
</mrow>
</math>
in it. This
approximates
<!--l. 155-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
by a straight
line in that interval
<!--l. 156-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>i</mi>
</mrow>
</math>
, and
uses the average height
<!--l. 156-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>(</mo>
<msub>
<mi>f</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>+</mo>
<msub>
<mi>f</mi>
<mrow>
<mi>i</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<mo>/</mo>
<mn>2</mn>
</mrow>
</math>
as the value for
<!--l. 157-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
</mrow>
</math>
.
The area of a single trapezoid is in this way
</p>
<!--l. 158-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-4002r9"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&int;</mo>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>+</mo>
<mi>h</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>&sime;</mo>
<mfrac>
<mrow>
<mi>h</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>f</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>+</mo>
<msub>
<mi>f</mi>
<mrow>
<mi>i</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo>)</mo>
</mrow>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<mo>=</mo>
<mfrac>
<mrow>
<mn>1</mn>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<mi>h</mi>
<msub>
<mi>f</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>+</mo>
<mfrac>
<mrow>
<mn>1</mn>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<mi>h</mi>
<msub>
<mi>f</mi>
<mrow>
<mi>i</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.9)</mn>
</mrow>
</math>
In terms of our standard integration formula (
<a href="#x1-3002r3"> 4.3</a>
), the &#34;rule&#34; in (
<a href="#x1-4002r9"> 4.9</a>
) is for
<!--l. 164-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
<mo>=</mo>
<mn>2</mn>
</mrow>
</math>
points with
weight
<!--l. 164-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>&equiv;</mo>
<mfrac>
<mrow>
<mn>1</mn>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
</mrow>
</math>
.
<a name="x1-40032"></a>
<hr class="float" />
<div align="center" class="float">
<table class="float">
<tr class="float">
<td class="float">
<div class="center"><img src="chapter041x.gif" alt="PIC" /></div>
<div align="center" class="caption">
<table class="caption">
<tr valign="baseline" class="caption">
<td class="id">Figure&nbsp;4.2:</td>
<td class="content">
 (
<span class="cmti-10"> Left</span>
) straight-line sections used for the trapezoid rule; (
<span class="cmti-10"> right</span>
) the
paraboli used in Simpson's rule.
</td>
</tr>
</table>
</div>
<a name="x1-40032"></a>
</td>
</tr>
</table>
</div>
<hr class="endfloat" />
   In order to apply the trapezoid rule to the entire region
<!--l. 180-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>[</mo>
<mi>a</mi>
<mo>,</mo>
<mi>b</mi>
<mo>]</mo>
</mrow>
</mrow>
</math>
, we
add the contributions from each subinterval:
<!--l. 182-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-4004r10"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>a</mi>
</mrow>
<mrow>
<mi>b</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>&ap;</mo>
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<msub>
<mi>f</mi>
<mrow>
<mn>1</mn>
</mrow>
</msub>
<mo>+</mo>
<mi>h</mi>
<msub>
<mi>f</mi>
<mrow>
<mn>2</mn>
</mrow>
</msub>
<mo>+</mo>
<mi>h</mi>
<msub>
<mi>f</mi>
<mrow>
<mn>3</mn>
</mrow>
</msub>
<mo>+</mo>
<mo>&#x22EF;</mo>
<mi>h</mi>
<msub>
<mi>f</mi>
<mrow>
<mi>N</mi>
<mo>-</mo>
<mn>1</mn>
</mrow>
</msub>
<mo>+</mo>
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<msub>
<mi>f</mi>
<mrow>
<mi>N</mi>
</mrow>
</msub>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.10)</mn>
</mrow>
</math>
You will notice that because each internal point gets counted twice, it has a weight of
<!--l. 188-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>h</mi>
</mrow>
</math>
,
whereas the endpoints get counted just once and on that account have weights of
only
<!--l. 189-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>h</mi>
<mo>/</mo>
<mn>2</mn>
</mrow>
</math>
.
In terms of our standard integration rule (
<a href="#x1-8001r39"> 4.39</a>
), we have
<!--l. 191-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-4005r11"  class="label" width="0" />
<mspace class="endlabel" />
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>=</mo>
<mfenced open='{' close='}' separators="">
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<mo>,</mo>
<mi>h</mi>
<mo>,</mo>
<mo>&#x2026;</mo>
<mo>,</mo>
<mi>h</mi>
<mo>,</mo>
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
</mfenced>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.11)</mn>
</mrow>
</math>
<h3 class="sectionHead">
4.4
<a name="x1-50004.4"></a>
<a name="QQ1-1-7"></a>
Method: Simpson's Rule
</h3>
<!--197-->
<p class="noindent">
In Simpson's rule we approximate the function
<!--l. 197-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
by a
parabola
</p>
<!--l. 198-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-5001r12"  class="label" width="0" />
<mspace class="endlabel" />
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mspace class="nbsp" />
<mo>&ap;</mo>
<mspace class="nbsp" />
<mi>&alpha;</mi>
<msup>
<mi>x</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
<mo>+</mo>
<mi>&beta;</mi>
<mi>x</mi>
<mo>+</mo>
<mi>&gamma;</mi>
<mo>,</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.12)</mn>
</mrow>
</math>
for each interval, still keeping the intervals equally spaced. The area of each section is
then the integral of this parabola
<!--l. 203-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-5002r13"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&int;</mo>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>+</mo>
<mi>h</mi>
</mrow>
</msubsup>
<mrow>
<mo>(</mo>
<mi>&alpha;</mi>
<msup>
<mi>x</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
<mo>+</mo>
<mi>&beta;</mi>
<mi>x</mi>
<mo>+</mo>
<mi>&gamma;</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>=</mo>
<msubsup>
<mfenced open='.' close='|' separators="">
<mi>&alpha;</mi>
<msup>
<mi>x</mi>
<mrow>
<mn>3</mn>
</mrow>
</msup>
<mn>3</mn>
<mo>+</mo>
<mi>&beta;</mi>
<msup>
<mi>x</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
<mn>2</mn>
<mo>+</mo>
<mi>&gamma;</mi>
<mi>x</mi>
</mfenced>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>+</mo>
<mi>h</mi>
</mrow>
</msubsup>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.13)</mn>
</mrow>
</math>
This is equivalent to integrating the Taylor series up to the quadratic term. In order to relate
the parameters
<!--l. 209-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>&alpha;</mi>
</mrow>
</math>
,
<!--l. 209-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>&beta;</mi>
</mrow>
</math>
, and
<!--l. 210-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>&gamma;</mi>
</mrow>
</math>
to the function, we
consider an interval from
<!--l. 210-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mo>-</mo>
<mn>1</mn>
</mrow>
</math>
to
<!--l. 211-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mo>+</mo>
<mn>1</mn>
</mrow>
</math>
, in
which case
<!--l. 212-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-5003r14"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&int;</mo>
<mrow>
<mo>-</mo>
<mn>1</mn>
</mrow>
<mrow>
<mn>1</mn>
</mrow>
</msubsup>
<mrow>
<mo>(</mo>
<mi>&alpha;</mi>
<msup>
<mi>x</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
<mo>+</mo>
<mi>&beta;</mi>
<mi>x</mi>
<mo>+</mo>
<mi>&gamma;</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mn>2</mn>
<mi>&alpha;</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<mo>+</mo>
<mn>2</mn>
<mi>&gamma;</mi>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.14)</mn>
</mrow>
</math>
But we notice that
<!--l. 217-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-5004r15"  class="label" width="0" />
<mspace class="endlabel" />
<mtable equalrows='false' equalcolumns='false'>
<mtr>
<mtd class="array"></mtd>
<mtd class="array">
<mi>f</mi>
<mrow>
<mo>(</mo>
<mo>-</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
<mo>=</mo>
<mi>&alpha;</mi>
<mo>-</mo>
<mi>&beta;</mi>
<mo>+</mo>
<mi>&gamma;</mi>
<mo>,</mo>
</mtd>
<mtd class="array">
<mi>f</mi>
<mrow>
<mo>(</mo>
<mn>0</mn>
<mo>)</mo>
</mrow>
<mo>=</mo>
<mi>&gamma;</mi>
<mo>,</mo>
</mtd>
<mtd class="array">
<mi>f</mi>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
<mo>=</mo>
<mi>&alpha;</mi>
<mo>+</mo>
<mi>&beta;</mi>
<mo>+</mo>
<mi>&gamma;</mi>
<mo>,</mo>
</mtd>
</mtr>
<mtr>
<mtd class="array">
<mo>&rArr;</mo>
</mtd>
<mtd class="array">
<mi>&alpha;</mi>
<mo>=</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
<mo>+</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mo>-</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
<mn>2</mn>
<mo>-</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mn>0</mn>
<mo>)</mo>
</mrow>
<mo>,</mo>
</mtd>
<mtd class="array">
<mi>&beta;</mi>
<mo>=</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
<mo>+</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mo>-</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
<mn>2</mn>
<mo>,</mo>
</mtd>
<mtd class="array">
<mi>&gamma;</mi>
<mo>=</mo>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mn>0</mn>
<mo>)</mo>
</mrow>
<mo>.</mo>
</mtd>
</mtr>
<mtr>
<mtd class="array"></mtd>
</mtr>
</mtable>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.15)</mn>
</mrow>
</math>
In this way we can express the integral as the weighted sum over the values of the
function at 3 points:
<!--l. 228-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-5005r16"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&int;</mo>
<mrow>
<mo>-</mo>
<mn>1</mn>
</mrow>
<mrow>
<mn>1</mn>
</mrow>
</msubsup>
<mrow>
<mo>(</mo>
<mi>&alpha;</mi>
<msup>
<mi>x</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
<mo>+</mo>
<mi>&beta;</mi>
<mi>x</mi>
<mo>+</mo>
<mi>&gamma;</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mo>-</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<mo>+</mo>
<mfrac>
<mrow>
<mn>4</mn>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mn>0</mn>
<mo>)</mo>
</mrow>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<mo>+</mo>
<mfrac>
<mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.16)</mn>
</mrow>
</math>
Because 3 values of the function are needed, we generalize this result to our problem
by evaluating the integral over two adjacent intervals, in which case we evaluate the
function at the two endpoints and the middle:
<!--l. 237-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-5006r17"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&int;</mo>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>-</mo>
<mi>h</mi>
</mrow>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>+</mo>
<mi>h</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>=</mo>
<msubsup>
<mo>&int;</mo>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>+</mo>
<mi>h</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>+</mo>
<msubsup>
<mo>&int;</mo>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>-</mo>
<mi>h</mi>
</mrow>
<mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>&sime;</mo>
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<msub>
<mi>f</mi>
<mrow>
<mi>i</mi>
<mo>-</mo>
<mn>1</mn>
</mrow>
</msub>
<mo>+</mo>
<mfrac>
<mrow>
<mn>4</mn>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<msub>
<mi>f</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>+</mo>
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<msub>
<mi>f</mi>
<mrow>
<mi>i</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.17)</mn>
</mrow>
</math>
   Simpson's rule requires the elementary integration to be over
<span class="cmti-10"> pairs</span>
of intervals,
and this requires that the total number of intervals be even or the number of points
<!--l. 246-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
be
odd. In order to apply Simpson's rule to the entire interval, we add up the
contributions from each pair of subintervals, counting all but the first and last
endpoints twice:
<!--l. 250-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-5007r18"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>a</mi>
</mrow>
<mrow>
<mi>b</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>&ap;</mo>
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<msub>
<mi>f</mi>
<mrow>
<mn>1</mn>
</mrow>
</msub>
<mo>+</mo>
<mfrac>
<mrow>
<mn>4</mn>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<msub>
<mi>f</mi>
<mrow>
<mn>2</mn>
</mrow>
</msub>
<mo>+</mo>
<mfrac>
<mrow>
<mn>2</mn>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<msub>
<mi>f</mi>
<mrow>
<mn>3</mn>
</mrow>
</msub>
<mo>+</mo>
<mfrac>
<mrow>
<mn>4</mn>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<msub>
<mi>f</mi>
<mrow>
<mn>4</mn>
</mrow>
</msub>
<mo>+</mo>
<mo>&#x22EF;</mo>
<mo>+</mo>
<mfrac>
<mrow>
<mn>4</mn>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<msub>
<mi>f</mi>
<mrow>
<mi>N</mi>
<mo>-</mo>
<mn>1</mn>
</mrow>
</msub>
<mo>+</mo>
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<msub>
<mi>f</mi>
<mrow>
<mi>N</mi>
</mrow>
</msub>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.18)</mn>
</mrow>
</math>
In terms of our standard integration rule (
<a href="#x1-3002r3"> 4.3</a>
), we have
<!--l. 258-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-5008r19"  class="label" width="0" />
<mspace class="endlabel" />
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>=</mo>
<mfenced open='{' close='}' separators="">
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<mo>,</mo>
<mfrac>
<mrow>
<mn>4</mn>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<mo>,</mo>
<mfrac>
<mrow>
<mn>2</mn>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<mo>,</mo>
<mfrac>
<mrow>
<mn>4</mn>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<mo>,</mo>
<mo>&#x2026;</mo>
<mfrac>
<mrow>
<mn>4</mn>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<mo>,</mo>
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
</mfenced>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.19)</mn>
</mrow>
</math>
The sum of these weights provides a useful check on your integration:
<!--l. 263-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-5009r20"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&sum;</mo>
<mrow>
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mrow>
<mi>N</mi>
</mrow>
</msubsup>
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>=</mo>
<mrow>
<mo>(</mo>
<mi>N</mi>
<mo>-</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
<mi>h</mi>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.20)</mn>
</mrow>
</math>
<span class="cmti-10"> Remember</span>
,
<!--l. 266-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
must be odd.
<h3 class="sectionHead">
4.5
<a name="x1-60004.5"></a>
<a name="QQ1-1-8"></a>
Assessment: Integration Error, Analytic
</h3>
<!--270-->
<p class="noindent">
In general, you want to choose an integration rule that gives an
accurate answer using the least number of integration points. We
obtain a feel for the absolute
<span class="cmti-10"> approximation</span>
or
<span class="cmti-10"> algorithmic error</span>
<!--l. 274-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>E</mi>
</mrow>
</math>
and the
relative error
<!--l. 274-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>&epsi;</mi>
</mrow>
</math>
,
by expanding
<!--l. 274-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
in a Taylor series around the midpoint of the integration
interval. We then multiply that error by the number of intervals
<!--l. 277-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
to estimate the error
for the entire region
<!--l. 278-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>[</mo>
<mi>a</mi>
<mo>,</mo>
<mi>b</mi>
<mo>]</mo>
</mrow>
</mrow>
</math>
.
For the trapezoid and Simpson rules this yields
</p>
<!--l. 280-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>E</mi>
<mrow>
<mi>t</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mi>O</mi>
<mfenced open='(' close=')' separators="">
<mfrac>
<mrow>
<msup>
<mrow>
<mo>[</mo>
<mi>b</mi>
<mo>-</mo>
<mi>a</mi>
<mo>]</mo>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</msup>
</mrow>
<mrow>
<msup>
<mi>N</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
</mfenced>
<msup>
<mi>f</mi>
<mrow>
<mrow>
<mo>(</mo>
<mn>2</mn>
<mo>)</mo>
</mrow>
</mrow>
</msup>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.21)
<malignmark id="x1-6001r4.21"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>E</mi>
<mrow>
<mi>s</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mi>O</mi>
<mfenced open='(' close=')' separators="">
<mfrac>
<mrow>
<msup>
<mrow>
<mo>[</mo>
<mi>b</mi>
<mo>-</mo>
<mi>a</mi>
<mo>]</mo>
</mrow>
<mrow>
<mn>5</mn>
</mrow>
</msup>
</mrow>
<mrow>
<msup>
<mi>N</mi>
<mrow>
<mn>4</mn>
</mrow>
</msup>
</mrow>
</mfrac>
</mfenced>
<msup>
<mi>f</mi>
<mrow>
<mrow>
<mo>(</mo>
<mn>4</mn>
<mo>)</mo>
</mrow>
</mrow>
</msup>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.22)
<malignmark id="x1-6001r4.22"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>t</mi>
<mo>,</mo>
<mi>s</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<msub>
<mi>E</mi>
<mrow>
<mi>t</mi>
<mo>,</mo>
<mi>s</mi>
</mrow>
</msub>
</mrow>
<mrow>
<mi>f</mi>
</mrow>
</mfrac>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.23)
<malignmark id="x1-6001r4.23"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--286-->
<p class="nopar">
We see that the third derivative term in Simpson's rule cancels (much like the
central difference method in differentiation). The equations (
<a href="#x1-6001r4.21"> 4.21</a>
)-(
<a href="#x1-6001r4.22"> 4.22</a>
)
are illuminating by showing how increasing the sophistication of an
integration rule leads to an error that falls off with a higher inverse power of
<!--l. 291-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
,
yet that is also proportional to higher derivatives of
<!--l. 292-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
</mrow>
</math>
. Consequently, for
small intervals and
<!--l. 293-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
functions with well-behaved high derivatives, Simpson's rule should converge more
rapidly than the trapezoid rule.
</p>
<!--296-->
<p class="indent">
To be more specific, we assume that after
<!--l. 296-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
steps
the
<span class="cmti-10"> relative</span>
roundoff error is random and of the form
</p>
<!--l. 298-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-6002r24"  class="label" width="0" />
<mspace class="endlabel" />
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>r</mi>
<mi>o</mi>
</mrow>
</msub>
<mo>&ap;</mo>
<msqrt>
<!--
<mi></mi>
   -->
<mi>N</mi>
</msqrt>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>m</mi>
</mrow>
</msub>
<mo>,</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.24)</mn>
</mrow>
</math>
where
<!--l. 301-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>m</mi>
</mrow>
</msub>
</mrow>
</math>
is the machine
precision (
<!--l. 301-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mo>~</mo>
<mn>1</mn>
<msup>
<mn>0</mn>
<mrow>
<mo>-</mo>
<mn>7</mn>
</mrow>
</msup>
</mrow>
</math>
for
single precision and
<!--l. 302-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mo>~</mo>
<mn>1</mn>
<msup>
<mn>0</mn>
<mrow>
<mo>-</mo>
<mn>1</mn>
<mn>5</mn>
</mrow>
</msup>
</mrow>
</math>
for double precision ). We want to determine an
<!--l. 303-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
that
minimizes the total error, that is, the sum of the approximation and roundoff
error
<!--l. 305-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-6003r25"  class="label" width="0" />
<mspace class="endlabel" />
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>t</mi>
<mi>o</mi>
<mi>t</mi>
</mrow>
</msub>
<mo>=</mo>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>r</mi>
<mi>o</mi>
</mrow>
</msub>
<mo>+</mo>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>a</mi>
<mi>p</mi>
<mi>p</mi>
<mi>r</mi>
<mi>o</mi>
<mi>x</mi>
</mrow>
</msub>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.25)</mn>
</mrow>
</math>
This occurs, approximately, when the two relative errors are of equal magnitude,
which we approximate even further by assuming that the two errors are
equal
<!--l. 311-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-6004r26"  class="label" width="0" />
<mspace class="endlabel" />
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>r</mi>
<mi>o</mi>
</mrow>
</msub>
<mo>=</mo>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>a</mi>
<mi>p</mi>
<mi>p</mi>
<mi>r</mi>
<mi>o</mi>
<mi>x</mi>
</mrow>
</msub>
<mo>=</mo>
<mfrac>
<mrow>
<msub>
<mi>E</mi>
<mrow>
<mi>t</mi>
<mi>r</mi>
<mi>a</mi>
<mi>p</mi>
<mo>,</mo>
<mi>s</mi>
<mi>i</mi>
<mi>m</mi>
<mi>p</mi>
</mrow>
</msub>
</mrow>
<mrow>
<mi>f</mi>
</mrow>
</mfrac>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.26)</mn>
</mrow>
</math>
To continue the search for optimum
<!--l. 315-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
for a general function
<!--l. 315-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
</mrow>
</math>
,
we set the scale of function size by assuming
<!--l. 317-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-6005r27"  class="label" width="0" />
<mspace class="endlabel" />
<mfrac>
<mrow>
<msup>
<mi>f</mi>
<mrow>
<mrow>
<mo>(</mo>
<mi>n</mi>
<mo>)</mo>
</mrow>
</mrow>
</msup>
</mrow>
<mrow>
<mi>f</mi>
</mrow>
</mfrac>
<mo>&ap;</mo>
<mn>1</mn>
<mo>,</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.27)</mn>
</mrow>
</math>
and the scale of length by assuming
<!--l. 321-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-6006r28"  class="label" width="0" />
<mspace class="endlabel" />
<mi>b</mi>
<mo>-</mo>
<mi>a</mi>
<mo>=</mo>
<mn>1</mn>
<mspace class="nbsp" />
<mspace class="nbsp" />
<mo>&rArr;</mo>
<mspace class="nbsp" />
<mspace class="nbsp" />
<mi>h</mi>
<mo>=</mo>
<mn>1</mn>
<mi>N</mi>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.28)</mn>
</mrow>
</math>
   The estimate (
<a href="#x1-6004r26"> 4.26</a>
), when applied to the
<span class="cmbx-10"> trapezoid rule</span>
, yields
<!--l. 327-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<msqrt>
<!--
<mi></mi>
  -->
<mi>N</mi>
</msqrt>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>m</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>&ap;</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<msup>
<mi>f</mi>
<mrow>
<mrow>
<mo>(</mo>
<mn>2</mn>
<mo>)</mo>
</mrow>
</mrow>
</msup>
<msup>
<mrow>
<mo>(</mo>
<mi>b</mi>
<mo>-</mo>
<mi>a</mi>
<mo>)</mo>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</msup>
</mrow>
<mrow>
<mi>f</mi>
<msup>
<mi>N</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mo>=</mo>
<mfrac>
<mrow>
<mn>1</mn>
</mrow>
<mrow>
<msup>
<mi>N</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.29)
<malignmark id="x1-6007r4.29"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<mo>&rArr;</mo>
<mi>N</mi>
</mtd>
<mtd class="eqnarray-2">
<mo>&ap;</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mn>1</mn>
</mrow>
<mrow>
<msup>
<mrow>
<mo>(</mo>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>m</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<mrow>
<mn>2</mn>
<mo>/</mo>
<mn>5</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.30)
<malignmark id="x1-6007r4.30"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--331-->
<p class="nopar">
Because the machine precision
<!--l. 332-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>m</mi>
</mrow>
</msub>
</mrow>
</math>
differs for single- and double-precision calculations, the optimum number of steps
<!--l. 333-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
for
the
<span class="cmbx-10"> trapezoid rule</span>
has the following two values:
</p>
<!--l. 335-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-6008r31"  class="label" width="0" />
<mspace class="endlabel" />
<mi>N</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mn>1</mn>
</mrow>
<mrow>
<mi>h</mi>
</mrow>
</mfrac>
<mo>=</mo>
<mfenced open='{' close='' separators="">
<mtable equalrows='false' equalcolumns='false'>
<mtr>
<mtd class="array">
<msup>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>/</mo>
<mn>1</mn>
<msup>
<mn>0</mn>
<mrow>
<mo>-</mo>
<mn>7</mn>
</mrow>
</msup>
<mo>)</mo>
</mrow>
<mrow>
<mn>2</mn>
<mo>/</mo>
<mn>5</mn>
</mrow>
</msup>
<mo>=</mo>
<mn>6</mn>
<mn>3</mn>
<mn>1</mn>
<mo>,</mo>
</mtd>
<mtd class="array">
<mrow class="mbox">
<mtext>for single precision,</mtext>
</mrow>
</mtd>
</mtr>
<mtr>
<mtd class="array">
<msup>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>/</mo>
<mn>1</mn>
<msup>
<mn>0</mn>
<mrow>
<mo>-</mo>
<mn>1</mn>
<mn>5</mn>
</mrow>
</msup>
<mo>)</mo>
</mrow>
<mrow>
<mn>2</mn>
<mo>/</mo>
<mn>5</mn>
</mrow>
</msup>
<mo>=</mo>
<mn>1</mn>
<msup>
<mn>0</mn>
<mrow>
<mn>6</mn>
</mrow>
</msup>
<mo>,</mo>
</mtd>
<mtd class="array">
<mrow class="mbox">
<mtext>for double precision.</mtext>
</mrow>
</mtd>
</mtr>
</mtable>
</mfenced>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.31)</mn>
</mrow>
</math>
The corresponding errors are
<!--l. 342-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-6009r32"  class="label" width="0" />
<mspace class="endlabel" />
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>r</mi>
<mi>o</mi>
</mrow>
</msub>
<mo>&ap;</mo>
<msqrt>
<!--
<mi></mi>
   -->
<mi>N</mi>
</msqrt>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>m</mi>
</mrow>
</msub>
<mo>=</mo>
<mfenced open='{' close='' separators="">
<mtable equalrows='false' equalcolumns='false'>
<mtr>
<mtd class="array">
<mn>3</mn>
<mo>&times;</mo>
<mn>1</mn>
<msup>
<mn>0</mn>
<mrow>
<mo>-</mo>
<mn>6</mn>
</mrow>
</msup>
<mo>,</mo>
</mtd>
<mtd class="array">
<mrow class="mbox">
<mtext>for single precision,</mtext>
</mrow>
</mtd>
</mtr>
<mtr>
<mtd class="array">
<mn>1</mn>
<msup>
<mn>0</mn>
<mrow>
<mo>-</mo>
<mn>1</mn>
<mn>2</mn>
</mrow>
</msup>
<mo>,</mo>
</mtd>
<mtd class="array">
<mrow class="mbox">
<mtext>for double precision.</mtext>
</mrow>
</mtd>
</mtr>
</mtable>
</mfenced>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.32)</mn>
</mrow>
</math>
   The estimate (
<a href="#x1-6004r26"> 4.26</a>
) when applied to
<span class="cmbx-10"> Simpson's rule</span>
yields
<!--l. 350-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<msqrt>
<!--
<mi></mi>
  -->
<mi>N</mi>
</msqrt>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>m</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<msup>
<mi>f</mi>
<mrow>
<mrow>
<mo>(</mo>
<mn>4</mn>
<mo>)</mo>
</mrow>
</mrow>
</msup>
<msup>
<mrow>
<mo>(</mo>
<mi>b</mi>
<mo>-</mo>
<mi>a</mi>
<mo>)</mo>
</mrow>
<mrow>
<mn>5</mn>
</mrow>
</msup>
</mrow>
<mrow>
<mi>f</mi>
<msup>
<mi>N</mi>
<mrow>
<mn>4</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mo>=</mo>
<mfrac>
<mrow>
<mn>1</mn>
</mrow>
<mrow>
<msup>
<mi>N</mi>
<mrow>
<mn>4</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.33)
<malignmark id="x1-6010r4.33"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<mo>&rArr;</mo>
<mi>N</mi>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mn>1</mn>
</mrow>
<mrow>
<msup>
<mrow>
<mo>(</mo>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>m</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<mrow>
<mn>2</mn>
<mo>/</mo>
<mn>9</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.34)
<malignmark id="x1-6010r4.34"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--354-->
<p class="nopar">For single and double precision, this now yields</p>
<!--l. 356-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-6011r35"  class="label" width="0" />
<mspace class="endlabel" />
<mi>N</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mn>1</mn>
</mrow>
<mrow>
<mi>h</mi>
</mrow>
</mfrac>
<mo>=</mo>
<mfenced open='{' close='' separators="">
<mtable equalrows='false' equalcolumns='false'>
<mtr>
<mtd class="array">
<msup>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>/</mo>
<mn>1</mn>
<msup>
<mn>0</mn>
<mrow>
<mo>-</mo>
<mn>7</mn>
</mrow>
</msup>
<mo>)</mo>
</mrow>
<mrow>
<mn>2</mn>
<mo>/</mo>
<mn>9</mn>
</mrow>
</msup>
<mo>=</mo>
<mn>3</mn>
<mn>6</mn>
<mo>,</mo>
</mtd>
<mtd class="array">
<mrow class="mbox">
<mtext>for single precision,</mtext>
</mrow>
</mtd>
</mtr>
<mtr>
<mtd class="array">
<msup>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>/</mo>
<mn>1</mn>
<msup>
<mn>0</mn>
<mrow>
<mo>-</mo>
<mn>1</mn>
<mn>5</mn>
</mrow>
</msup>
<mo>)</mo>
</mrow>
<mrow>
<mn>2</mn>
<mo>/</mo>
<mn>9</mn>
</mrow>
</msup>
<mo>=</mo>
<mn>2</mn>
<mn>1</mn>
<mn>5</mn>
<mn>4</mn>
<mo>,</mo>
</mtd>
<mtd class="array">
<mrow class="mbox">
<mtext>for double precision.</mtext>
</mrow>
</mtd>
</mtr>
</mtable>
</mfenced>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.35)</mn>
</mrow>
</math>
The corresponding errors are
<!--l. 363-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-6012r36"  class="label" width="0" />
<mspace class="endlabel" />
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>r</mi>
<mi>o</mi>
</mrow>
</msub>
<mo>&ap;</mo>
<msqrt>
<!--
<mi></mi>
   -->
<mi>N</mi>
</msqrt>
<msub>
<mi>&epsi;</mi>
<mrow>
<mi>m</mi>
</mrow>
</msub>
<mo>=</mo>
<mfenced open='{' close='' separators="">
<mtable equalrows='false' equalcolumns='false'>
<mtr>
<mtd class="array">
<mn>6</mn>
<mo>&times;</mo>
<mn>1</mn>
<msup>
<mn>0</mn>
<mrow>
<mo>-</mo>
<mn>7</mn>
</mrow>
</msup>
<mo>,</mo>
</mtd>
<mtd class="array">
<mrow class="mbox">
<mtext>for single precision,</mtext>
</mrow>
</mtd>
</mtr>
<mtr>
<mtd class="array">
<mn>5</mn>
<mo>&times;</mo>
<mn>1</mn>
<msup>
<mn>0</mn>
<mrow>
<mo>-</mo>
<mn>1</mn>
<mn>4</mn>
</mrow>
</msup>
<mo>,</mo>
</mtd>
<mtd class="array">
<mrow class="mbox">
<mtext>for double precision.</mtext>
</mrow>
</mtd>
</mtr>
</mtable>
</mfenced>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.36)</mn>
</mrow>
</math>
These results are illuminating because they show that
<ol type="1" class="enumerate1">
<li class="enumerate">
<a name="x1-6014x1"></a>
Simpson's rule is an improvement over the trapezoid rule.
</li>
<li class="enumerate">
<a name="x1-6016x2"></a>
It is possible to obtain an error close to machine precision with Simpson's
     rule (and with other higher-order integration algorithms).
</li>
<li class="enumerate">
<a name="x1-6018x3"></a>
Obtaining the best numerical approximation to an integral is not obtained
     by letting
<!--l. 380-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
<mo>&rarr;</mo>
<mi>&infin;</mi>
</mrow>
</math>
,
     but with a relatively small
<!--l. 381-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
<mo>
<u class="underline"> &lt;</u>
</mo>
<mn>1</mn>
<mn>0</mn>
<mn>0</mn>
<mn>0</mn>
</mrow>
</math>
.
</li>
</ol>
<h3 class="sectionHead">
4.6
<a name="x1-70004.6"></a>
<a name="QQ1-1-9"></a>
Method: Gaussian Quadrature
</h3>
<!--386-->
<p class="noindent">
It is often useful to rewrite the basic integration formula (
<a href="#x1-3002r3"> 4.3</a>
) such that we separate a weighting
function
<!--l. 389-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>W</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
from the integrand:
</p>
<!--l. 390-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-7001r37"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>&alpha;</mi>
</mrow>
<mrow>
<mi>&beta;</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>&equiv;</mo>
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>&alpha;</mi>
</mrow>
<mrow>
<mi>&beta;</mi>
</mrow>
</msubsup>
<mi>W</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>F</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>&ap;</mo>
<msubsup>
<mo>&sum;</mo>
<mrow>
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mrow>
<mi>N</mi>
</mrow>
</msubsup>
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mi>F</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.37)</mn>
</mrow>
</math>
In the Gaussian quadrature approach to integration, the
<!--l. 395-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
weights
<!--l. 396-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
</math>
are chosen to make the approximation error actually vanish if
<!--l. 397-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
was a
<!--l. 397-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mn>2</mn>
<mi>N</mi>
<mo>-</mo>
<mn>1</mn>
</mrow>
</math>
degree polynomial. To obtain this incredible optimization, the points
<!--l. 398-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
</math>
end up having a very
specific distribution over
<!--l. 399-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>[</mo>
<mi>a</mi>
<mo>,</mo>
<mi>b</mi>
<mo>]</mo>
</mrow>
</mrow>
</math>
.
(If
<!--l. 399-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
</mrow>
</math>
is
only given by an equally spaced table, then a
<span class="cmti-10"> Simpson</span>
or
<span class="cmti-10"> trapezoid rule</span>
is simpler, although any integration algorithm can be used if the table is
interpolated.
<a href="chapter043.xml" name="chapter043.xml">
<sup>1</sup>
</a>
)
   In general, if
<!--l. 404-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
is smooth, or can be made smooth by factoring out some
<!--l. 405-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>W</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
,
Gaussian algorithms produce higher accuracy than lower-order ones, or conversely,
the same accuracy with a fewer number of points. If the function being integrated is
not smooth (for example, if it has some noise in it), then using a higher-order method
such as Gaussian quadrature may well lead to lower accuracy. Sometimes the
function may not be smooth because it has different behaviors in different regions. In
these cases it makes sense to integrate each region separately with a low-order
quadrature rule and then add the answers together. In fact, some of the &#34;smart&#34;
integration subroutines will decide for themselves how many intervals to use and
what rule to use in each interval.
<!--417-->
<p class="indent">
All the rules indicated in Table
<span class="cmbx-10"> ??</span>
are Gaussian with the general form (
<a href="#x1-7001r37"> 4.37</a>
).
We can see that in one case the weighting function is an exponential, in
another a Gaussian, and in several an integrable singularity. In contrast to the
equally-spaced rules, there is never an integration point at the extremes of the
intervals, yet all of the points and weights change as the number of points
<!--l. 423-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
changes.
</p>
<!--425-->
<p class="indent">
The values of
<!--l. 425-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>&alpha;</mi>
</mrow>
</math>
and
<!--l. 425-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>&beta;</mi>
</mrow>
</math>
in (
<a href="#x1-7001r37"> 4.37</a>
)
help define each integration scheme. If the integral you need to evaluate is over the range
<!--l. 427-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>(</mo>
<mi>a</mi>
<mo>,</mo>
<mi>b</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
and this differs
from
<!--l. 427-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>(</mo>
<mi>&alpha;</mi>
<mo>,</mo>
<mi>&beta;</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
, you must
<span class="cmti-10"> map</span>
your
<!--l. 428-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>(</mo>
<mi>a</mi>
<mo>,</mo>
<mi>b</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
onto
<!--l. 428-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>(</mo>
<mi>&alpha;</mi>
<mo>,</mo>
<mi>&beta;</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
,
possibly using one of the methods discussed below.
</p>
<!--431-->
<p class="indent">
Although we will leave it to the references on numerical methods
for the derivation of the Gauss points and weights, we note here
that for ordinary Gaussian (Gauss-Legendre) integration, the points
<!--l. 434-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
</math>
turn out
to be the
<!--l. 434-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
zeros of the Legendre polynomials, with the weights related to the derivatives:
</p>
<!--l. 436-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-7002r38"  class="label" width="0" />
<mspace class="endlabel" />
<msub>
<mi>P</mi>
<mrow>
<mi>N</mi>
</mrow>
</msub>
<mrow>
<mo>(</mo>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<mo>=</mo>
<mn>0</mn>
<mo>,</mo>
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>=</mo>
<mfrac>
<mrow>
<mn>2</mn>
</mrow>
<mrow>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>-</mo>
<msubsup>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</msubsup>
<mo>)</mo>
</mrow>
<msup>
<mrow>
<mo>[</mo>
<msubsup>
<mi>P</mi>
<mrow>
<mi>N</mi>
</mrow>
<mrow>
<mi>'</mi>
</mrow>
</msubsup>
<mrow>
<mo>(</mo>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<mo>]</mo>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.38)</mn>
</mrow>
</math>
Subroutines to generate these points and weights are standard in mathematical
function libraries, are found in tables such as those in [
<span class="cmbx-10"> ?</span>
], or can be computed. The
<span class="cmti-10"> gauss</span>
subroutines we provide on the diskette and the Web also scales the points to a
specified region. As a check that your points are correct, you may want to compare
them to the four-point set we give in Table&nbsp;
<span class="cmbx-10"> ??</span>
.
<h4 class="subsectionHead">
4.6.1
<a name="x1-80004.6.1"></a>
<a name="QQ1-1-10"></a>
Scaling with Integration Rules
</h4>
<!--451-->
<p class="noindent">
Our standard convention (
<a href="#x1-3002r3"> 4.3</a>
) for the general interval
<!--l. 452-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>[</mo>
<mi>a</mi>
<mo>,</mo>
<mi>b</mi>
<mo>]</mo>
</mrow>
</mrow>
</math>
is
</p>
<!--l. 453-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-8001r39"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>a</mi>
</mrow>
<mrow>
<mi>b</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>&ap;</mo>
<msubsup>
<mo>&sum;</mo>
<mrow>
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mrow>
<mi>N</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.39)</mn>
</mrow>
</math>
But when the points and weights,
<!--l. 455-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>(</mo>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>,</mo>
<msubsup>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
<mrow>
<mi>'</mi>
</mrow>
</msubsup>
<mo>)</mo>
</mrow>
</mrow>
</math>
,
are for a fixed integration range (such as Gaussian), the programmer must
<span class="cmti-10"> scale</span>
the Gaussian
interval to
<!--l. 458-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>[</mo>
<mi>a</mi>
<mo>,</mo>
<mi>b</mi>
<mo>]</mo>
</mrow>
</mrow>
</math>
.
Here are some mappings we have found useful in our work (they are in the subroutine
<span class="cmti-10"> gauss</span>
given on the diskette and Web).
   In the scalings below,
<!--l. 462-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>(</mo>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>,</mo>
<msubsup>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
<mrow>
<mi>'</mi>
</mrow>
</msubsup>
<mo>)</mo>
</mrow>
</mrow>
</math>
are the elementary Gaussian points and weights for the interval
<!--l. 463-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mrow>
<mo>[</mo>
<mo>-</mo>
<mn>1</mn>
<mo>,</mo>
<mn>1</mn>
<mo>]</mo>
</mrow>
</mrow>
</math>
, and we want
to scale to
<!--l. 464-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>x</mi>
</mrow>
</math>
.
<dl class="description">
<dt class="description">
<!--l. 466-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mfenced open='[' close=']' separators="">
<mo>-</mo>
<mn>1</mn>
<mo>,</mo>
<mn>1</mn>
</mfenced>
<mo>&rarr;</mo>
<mfenced open='[' close=']' separators="">
<mi>A</mi>
<mo>,</mo>
<mi>B</mi>
</mfenced>
</mrow>
</math>
<span class="cmbx-10"> uniformly,</span>
<!--l. 466-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mfrac>
<mrow>
<mi>A</mi>
<mo>+</mo>
<mi>B</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
</mrow>
</math>
<span class="cmbx-10"> = midpoint:</span>
</dt>
<dd class="description">
<!--l. 467-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mi>B</mi>
<mo>+</mo>
<mi>A</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<mo>+</mo>
<mfrac>
<mrow>
<mi>B</mi>
<mo>-</mo>
<mi>A</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.40)
<malignmark id="x1-8002r4.40"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<mo>&rArr;</mo>
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>A</mi>
</mrow>
<mrow>
<mi>B</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mi>B</mi>
<mo>-</mo>
<mi>A</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<msubsup>
<mo>&int;</mo>
<mrow>
<mo>-</mo>
<mn>1</mn>
</mrow>
<mrow>
<mn>1</mn>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>[</mo>
<mi>x</mi>
<mrow>
<mo>(</mo>
<mi>y</mi>
<mo>)</mo>
</mrow>
<mo>]</mo>
</mrow>
<mi>d</mi>
<mi>y</mi>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.41)
<malignmark id="x1-8002r4.41"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<mo>&rArr;</mo>
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mi>B</mi>
<mo>-</mo>
<mi>A</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<msubsup>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
<mrow>
<mi>'</mi>
</mrow>
</msubsup>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.42)
<malignmark id="x1-8002r4.42"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--472-->
<p class="nopar"></p>
</dd>
<dt class="description">
<!--l. 473-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mfenced open='[' close=']' separators="">
<mn>0</mn>
<mo>&rarr;</mo>
<mi>&infin;</mi>
</mfenced>
</mrow>
</math>
<span class="cmbx-10"> ,</span>
<!--l. 473-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>A</mi>
</mrow>
</math>
<span class="cmbx-10"> = midpoint:</span>
</dt>
<dd class="description">
<!--l. 474-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mi>A</mi>
<mfrac>
<mrow>
<mn>1</mn>
<mo>+</mo>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
<mrow>
<mn>1</mn>
<mo>-</mo>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
</mfrac>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.43)
<malignmark id="x1-8003r4.43"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mn>2</mn>
<mi>A</mi>
</mrow>
<mrow>
<msup>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>-</mo>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<msubsup>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
<mrow>
<mi>'</mi>
</mrow>
</msubsup>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.44)
<malignmark id="x1-8003r4.44"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--477-->
<p class="nopar"></p>
</dd>
<dt class="description">
<!--l. 479-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mfenced open='[' close=']' separators="">
<mo>-</mo>
<mi>&infin;</mi>
<mo>&rarr;</mo>
<mi>&infin;</mi>
</mfenced>
</mrow>
</math>
<span class="cmbx-10"> , scale set by</span>
<!--l. 479-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>A</mi>
</mrow>
</math>
<span class="cmbx-10"> :</span>
</dt>
<dd class="description">
<!--l. 480-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mi>A</mi>
<mfrac>
<mrow>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
<mrow>
<mn>1</mn>
<mo>-</mo>
<msubsup>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.45)
<malignmark id="x1-8004r4.45"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mi>A</mi>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>+</mo>
<msubsup>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</msubsup>
<mo>)</mo>
</mrow>
</mrow>
<mrow>
<msup>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>-</mo>
<msubsup>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</msubsup>
<mo>)</mo>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<msubsup>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
<mrow>
<mi>'</mi>
</mrow>
</msubsup>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.46)
<malignmark id="x1-8004r4.46"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--483-->
<p class="nopar"></p>
</dd>
<dt class="description">
<!--l. 484-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mfenced open='[' close=']' separators="">
<mi>B</mi>
<mo>&rarr;</mo>
<mi>&infin;</mi>
</mfenced>
</mrow>
</math>
<span class="cmbx-10"> ,</span>
<!--l. 484-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>A</mi>
<mo>+</mo>
<mn>2</mn>
<mi>B</mi>
<mo>=</mo>
</mrow>
</math>
<span class="cmbx-10"> midpoint:</span>
</dt>
<dd class="description">
<!--l. 485-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mi>A</mi>
<mo>+</mo>
<mn>2</mn>
<mi>B</mi>
<mo>+</mo>
<mi>A</mi>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
<mrow>
<mn>1</mn>
<mo>-</mo>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
</mfrac>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.47)
<malignmark id="x1-8005r4.47"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mn>2</mn>
<mrow>
<mo>(</mo>
<mi>B</mi>
<mo>+</mo>
<mi>A</mi>
<mo>)</mo>
</mrow>
</mrow>
<mrow>
<msup>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>-</mo>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<msubsup>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
<mrow>
<mi>'</mi>
</mrow>
</msubsup>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.48)
<malignmark id="x1-8005r4.48"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--488-->
<p class="nopar"></p>
</dd>
<dt class="description">
<!--l. 489-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mfenced open='[' close=']' separators="">
<mn>0</mn>
<mo>&rarr;</mo>
<mi>B</mi>
</mfenced>
</mrow>
</math>
<span class="cmbx-10"> ,</span>
<!--l. 489-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>A</mi>
<mi>B</mi>
<mo>/</mo>
<mrow>
<mo>(</mo>
<mi>B</mi>
<mo>+</mo>
<mi>A</mi>
<mo>)</mo>
</mrow>
<mo>=</mo>
</mrow>
</math>
<span class="cmbx-10"> midpoint:</span>
</dt>
<dd class="description">
<!--l. 490-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mi>A</mi>
<mi>B</mi>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>+</mo>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
</mrow>
<mrow>
<mi>B</mi>
<mo>+</mo>
<mi>A</mi>
<mo>-</mo>
<mrow>
<mo>(</mo>
<mi>B</mi>
<mo>-</mo>
<mi>A</mi>
<mo>)</mo>
</mrow>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
</mfrac>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.49)
<malignmark id="x1-8006r4.49"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<mfrac>
<mrow>
<mn>2</mn>
<mi>A</mi>
<msup>
<mi>B</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow>
<msup>
<mrow>
<mo>(</mo>
<mi>B</mi>
<mo>+</mo>
<mi>A</mi>
<mo>-</mo>
<mrow>
<mo>(</mo>
<mi>B</mi>
<mo>-</mo>
<mi>A</mi>
<mo>)</mo>
</mrow>
<msub>
<mi>y</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<msubsup>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
<mrow>
<mi>'</mi>
</mrow>
</msubsup>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.50)
<malignmark id="x1-8006r4.50"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--493-->
<p class="nopar"></p>
</dd>
</dl>
<!--495-->
<p class="noindent">
You can see, that if your integration range extends out to infinity, there will be points at large but
not infinite
<!--l. 496-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>x</mi>
</mrow>
</math>
.
As you keep increasing the number of grid points
<!--l. 497-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
, the
largest
<!--l. 497-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mi>x</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
</mrow>
</math>
moves farther and farther out.
</p>
<!--503-->
<p class="noindent"></p>
<h3 class="sectionHead">
4.7
<a name="x1-90004.7"></a>
<a name="QQ1-1-11"></a>
Implementation: Integration, integ.f (.c)
</h3>
<!--507-->
<p class="noindent">
Write a program to integrate an arbitrary function numerically using the trapezoid
rule, the Simpson rule, and Gaussian quadrature. Use single precision in order to
show more quickly the effects of error. (This may not be possible if your quadrature
routines, such as the ones we supply on the diskette and the Web, are written in only
double precision.)
</p>
<!--514-->
<p class="indent">
For our
<span class="cmbx-10"> problem</span>
we assume exponential decay so that there actually is an
analytic answer:
</p>
<!--l. 516-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<mi>d</mi>
<mi>N</mi>
<mrow>
<mo>(</mo>
<mi>t</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>t</mi>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<msup>
<mi>e</mi>
<mrow>
<mo>-</mo>
<mi>t</mi>
</mrow>
</msup>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.51)
<malignmark id="x1-9001r4.51"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<mo>&rArr;</mo>
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<mi>N</mi>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mo>)</mo>
</mrow>
</mtd>
<mtd class="eqnarray-2">
<mo>=</mo>
</mtd>
<mtd class="eqnarray-3">
<msubsup>
<mo>&int;</mo>
<mrow>
<mn>0</mn>
</mrow>
<mrow>
<mn>1</mn>
</mrow>
</msubsup>
<msup>
<mi>e</mi>
<mrow>
<mo>-</mo>
<mi>t</mi>
</mrow>
</msup>
<mi>d</mi>
<mi>t</mi>
<mo>=</mo>
<mn>1</mn>
<mo>-</mo>
<msup>
<mi>e</mi>
<mrow>
<mo>-</mo>
<mn>1</mn>
</mrow>
</msup>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.52)
<malignmark id="x1-9001r4.52"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--520-->
<p class="nopar"></p>
<h3 class="sectionHead">
4.8
<a name="x1-100004.8"></a>
<a name="QQ1-1-12"></a>
Assessment: Empirical Error Estimate
</h3>
<!--524-->
<p class="noindent">Compare the relative error</p>
<!--l. 526-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-10001r53"  class="label" width="0" />
<mspace class="endlabel" />
<mi>&epsi;</mi>
<mo>=</mo>
<mfenced open='|' close='|' separators="">
<mfrac>
<mrow class="mbox">
<mtext>numeric-exact</mtext>
</mrow>
<mrow class="mbox">
<mtext>exact</mtext>
</mrow>
</mfrac>
</mfenced>
<mo>,</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.53)</mn>
</mrow>
</math>
for the trapezoid rule, Simpson's rule, and Gaussian quadrature.
<ol type="1" class="enumerate1">
<li class="enumerate">
<a name="x1-10003x1"></a>
Make a table of the form
<br class="newline" />
<!--536-->
<p class="noindent"></p>
<!--539-->
<p class="noindent">
Try
<!--l. 539-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
     values of 2, 10, 20, 40, 80, 160, &#x2026;.
</p>
</li>
<li class="enumerate">
<a name="x1-10005x2"></a>
Make a plot like Fig.&nbsp;
<a href="#x1-100103"> 4.3</a>
of
<!--l. 542-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mo>log</mo>
<mrow>
<mn>1</mn>
<mn>0</mn>
</mrow>
</msub>
<mi>&epsi;</mi>
</mrow>
</math>
     versus
<!--l. 542-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msub>
<mo>log</mo>
<mrow>
<mn>1</mn>
<mn>0</mn>
</mrow>
</msub>
<mi>N</mi>
</mrow>
</math>
.
     Note  that  the  ordinate  is  effectively  the  number  of  decimal  places  of
     precision.
</li>
<li class="enumerate">
<a name="x1-10007x3"></a>
Use your plot to determine the power-law dependence of the error on the
     number of points
<!--l. 548-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
.
     (Notice that you may not be able to reach the roundoff error regime for
     the trapezoid rule because the approximation error is so large.)
</li>
<li class="enumerate">
<a name="x1-10009x4"></a>
(
<span class="cmti-10"> Optional</span>
) If possible, see how your answers change for double precision.
</li>
</ol>
<a name="x1-100103"></a>
<hr class="float" />
<div align="center" class="float">
<table class="float">
<tr class="float">
<td class="float">
<div class="center"><img src="chapter042x.gif" alt="PIC" /></div>
<div align="center" class="caption">
<table class="caption">
<tr valign="baseline" class="caption">
<td class="id">Figure&nbsp;4.3:</td>
<td class="content">
 Log-log     plot     of     the     error     in     integration     of
exponential     decay     using     trapezoid     rule,     Simpson's     rule,     and
Gaussian      quadrature,      versus      number      of      integration      points
<!--l. 568-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>N</mi>
</mrow>
</math>
.
Approximately 7 decimal places of precision are attainable with single precision
(shown here) and 15 places with double precision.
</td>
</tr>
</table>
</div>
<a name="x1-100103"></a>
</td>
</tr>
</table>
</div>
<hr class="endfloat" />
<h3 class="sectionHead">
4.9
<a name="x1-110004.9"></a>
<a name="QQ1-1-14"></a>
Assessment: Experimentation
</h3>
<!--579-->
<p class="noindent">Try two integrals for which the answers are less obvious:</p>
<!--l. 580-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-11001r54"  class="label" width="0" />
<mspace class="endlabel" />
<msub>
<mi>F</mi>
<mrow>
<mn>1</mn>
</mrow>
</msub>
<mo>=</mo>
<msubsup>
<mo>&int;</mo>
<mrow>
<mn>0</mn>
</mrow>
<mrow>
<mn>2</mn>
<mi>&pi;</mi>
</mrow>
</msubsup>
<mo>sin</mo>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mn>0</mn>
<mn>0</mn>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>,</mo>
<mspace class="nbsp" />
<mspace class="nbsp" />
<mspace class="nbsp" />
<msub>
<mi>F</mi>
<mrow>
<mn>2</mn>
</mrow>
</msub>
<mo>=</mo>
<msubsup>
<mo>&int;</mo>
<mrow>
<mn>0</mn>
</mrow>
<mrow>
<mn>2</mn>
<mi>&pi;</mi>
</mrow>
</msubsup>
<msup>
<mo>sin</mo>
<mrow>
<mi>x</mi>
</mrow>
</msup>
<mrow>
<mo>(</mo>
<mn>1</mn>
<mn>0</mn>
<mn>0</mn>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.54)</mn>
</mrow>
</math>
Explain why the computer may have trouble with these integrals.
<h3 class="sectionHead">
4.10
<a name="x1-120004.10"></a>
<a name="QQ1-1-15"></a>
Method: Romberg Extrapolation
</h3>
<!--589-->
<p class="noindent">
As in the case of numerical differentiation, we can use the known functional dependence of the error
on interval size
<!--l. 590-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>h</mi>
</mrow>
</math>
to reduce the error in integration. For simple rules like the trapezoid and Simpson's, we have
the analytic estimates (
<a href="#x1-6004r26"> 4.26</a>
), while for others you may have to experiment to determine the
<!--l. 593-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>h</mi>
</mrow>
</math>
dependence.
For example, if
<!--l. 594-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>A</mi>
<mrow>
<mo>(</mo>
<mi>h</mi>
<mo>)</mo>
</mrow>
</mrow>
</math>
and
<!--l. 594-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>A</mi>
<mrow>
<mo>(</mo>
<mi>h</mi>
<mo>/</mo>
<mn>2</mn>
<mo>)</mo>
</mrow>
</mrow>
</math>
are the values of the integral determined with the trapezoid rule using interval
<!--l. 595-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>h</mi>
</mrow>
</math>
and
<!--l. 595-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>h</mi>
<mo>/</mo>
<mn>2</mn>
</mrow>
</math>
,
respectively, we know the integrals have expansions with a leading error term proportional
to
<!--l. 597-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msup>
<mi>h</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</math>
:
</p>
<!--l. 598-->
<math xmlns="&mathml;" mode="display"><mrow>
<mtable class="eqnarray">
<mtr>
<mtd class="eqnarray-1">
<mi>A</mi>
<mrow>
<mo>(</mo>
<mi>h</mi>
<mo>)</mo>
</mrow>
</mtd>
<mtd class="eqnarray-2">
<mo>&ap;</mo>
</mtd>
<mtd class="eqnarray-3">
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>a</mi>
</mrow>
<mrow>
<mi>b</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>+</mo>
<mi>&alpha;</mi>
<msup>
<mi>h</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
<mo>+</mo>
<mi>&beta;</mi>
<msup>
<mi>h</mi>
<mrow>
<mn>4</mn>
</mrow>
</msup>
<mo>+</mo>
<mo>&#x2026;</mo>
<mo>,</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.55)
<malignmark id="x1-12001r4.55"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
<mtr>
<mtd class="eqnarray-1">
<mi>A</mi>
<mrow>
<mo>(</mo>
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<mo>)</mo>
</mrow>
</mtd>
<mtd class="eqnarray-2">
<mo>&ap;</mo>
</mtd>
<mtd class="eqnarray-3">
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>a</mi>
</mrow>
<mrow>
<mi>b</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>+</mo>
<mfrac>
<mrow>
<mi>&alpha;</mi>
<msup>
<mi>h</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow>
<mn>4</mn>
</mrow>
</mfrac>
<mo>+</mo>
<mfrac>
<mrow>
<mi>&beta;</mi>
<msup>
<mi>h</mi>
<mrow>
<mn>4</mn>
</mrow>
</msup>
</mrow>
<mrow>
<mn>1</mn>
<mn>6</mn>
</mrow>
</mfrac>
<mo>+</mo>
<mo>&#x22EF;</mo>
<mo>.</mo>
</mtd>
<mtd class="eqnarray-4">
<mtext class="eqnarray">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.56)
<malignmark id="x1-12001r4.56"  class="label" width="0" />
<malignmark class="endlabel" />
</mtext>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
<!--603-->
<p class="nopar">
Consequently, we make the
<!--l. 604-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msup>
<mi>h</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</math>
term vanish by computing the combination
</p>
<!--l. 605-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-12002r57"  class="label" width="0" />
<mspace class="endlabel" />
<mfrac>
<mrow>
<mn>4</mn>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<mi>A</mi>
<mrow>
<mo>(</mo>
<mfrac>
<mrow>
<mi>h</mi>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
<mo>)</mo>
</mrow>
<mo>-</mo>
<mfrac>
<mrow>
<mn>1</mn>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mfrac>
<mi>A</mi>
<mrow>
<mo>(</mo>
<mi>h</mi>
<mo>)</mo>
</mrow>
<mo>&ap;</mo>
<msubsup>
<mo>&int;</mo>
<mrow>
<mi>a</mi>
</mrow>
<mrow>
<mi>b</mi>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mi>d</mi>
<mi>x</mi>
<mo>-</mo>
<mfrac>
<mrow>
<mi>&beta;</mi>
<msup>
<mi>h</mi>
<mrow>
<mn>4</mn>
</mrow>
</msup>
</mrow>
<mrow>
<mn>4</mn>
</mrow>
</mfrac>
<mo>+</mo>
<mo>&#x22EF;</mo>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.57)</mn>
</mrow>
</math>
Clearly this particular trick (Romberg's extrapolation) works only if the
<!--l. 610-->
<math xmlns="&mathml;" mode="inline"><mrow>
<msup>
<mi>h</mi>
<mrow>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</math>
term dominates the error, and then only if the derivatives of the function
are well behaved. An analogous extrapolation can also be made for other
algorithms.
<h4 class="subsectionHead">
4.10.1
<a name="x1-130004.10.1"></a>
<a name="QQ1-1-16"></a>
Other Closed Newton-Cotes Formulas
</h4>
<!--616-->
<p class="noindent">
In Table&nbsp;
<span class="cmbx-10"> ??</span>
we gave the weights for several equal-interval
rules. Whereas the Simpson rule used two intervals, the
<!--l. 618-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mfrac>
<mrow>
<mn>3</mn>
</mrow>
<mrow>
<mn>8</mn>
</mrow>
</mfrac>
</mrow>
</math>
rule uses three,
and the Milne
<a href="chapter044.xml" name="chapter044.xml">
<sup>3</sup>
</a>
rule four. (These are single-interval rules and must be strung together to obtain a rule
<span class="cmti-10"> extended</span>
over the entire integration range. This means that the points that end one
interval and begin the next get weighted twice.) You can easily determine the number
of elementary intervals integrated over, and check whether you and we have written
the weights right, by summing the weights for any rule. The sum is the integral of
<!--l. 626-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
</mrow>
<mo>=</mo>
<mn>1</mn>
</mrow>
</math>
and must
equal
<!--l. 627-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>h</mi>
</mrow>
</math>
times the number of intervals (which, in turn, equals
<!--l. 628-->
<math xmlns="&mathml;" mode="inline"><mrow>
<mi>b</mi>
<mo>-</mo>
<mi>a</mi>
</mrow>
</math>
):
</p>
<!--l. 628-->
<math xmlns="&mathml;" mode="display"><mrow>
<mspace id="x1-13001r58"  class="label" width="0" />
<mspace class="endlabel" />
<msubsup>
<mo>&sum;</mo>
<mrow>
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mrow>
<mi>N</mi>
</mrow>
</msubsup>
<msub>
<mi>w</mi>
<mrow>
<mi>i</mi>
</mrow>
</msub>
<mo>=</mo>
<mi>h</mi>
<mo>&times;</mo>
<msub>
<mi>N</mi>
<mrow>
<mi>i</mi>
<mi>n</mi>
<mi>t</mi>
<mi>e</mi>
<mi>r</mi>
<mi>v</mi>
<mi>a</mi>
<mi>l</mi>
<mi>s</mi>
</mrow>
</msub>
<mo>=</mo>
<mi>b</mi>
<mo>-</mo>
<mi>a</mi>
<mo>.</mo>
<mn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4.58)</mn>
</mrow>
</math>
<br /><br />
</body>
</html>
