<?xml-stylesheet type="text/xsl" href="../styles/pmathml.xsl"?>
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:dsi="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xml:space="preserve"><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"/><title>D01BAF : NAG Library, Mark 22</title><link rel="stylesheet" href="../styles/libdoc.css" type="text/css"/><script type="text/javascript">
   function showLevel(_levelId){
    var thisLevel = document.getElementById(_levelId);
    var thisplus = document.getElementById( _levelId.concat('plus'));
    var thisminus = document.getElementById( _levelId.concat('minus'));
    if(thisLevel.style.display != "block"){
     thisLevel.style.display = "block";
     thisplus.style.display = "none";
     thisminus.style.display = "inline";
     }
    else{
     thisLevel.style.display = "none";
     thisminus.style.display = "none";
     thisplus.style.display = "inline";
     }
    }
  </script></head><body><hr/><div><a class="rout" href="../../pdf/D01/d01baf.pdf">D01BAF (PDF version)</a></div><div><a class="chap" href="d01conts.xml">D01 Chapter Contents</a></div><div><a class="chapint" href="d01intro.xml">D01 Chapter Introduction</a></div>
<div><a class="htmltoc" href="../FRONTMATTER/manconts.xml">NAG Library Manual</a></div><hr/><h1 class="libdoc">NAG Library Routine Document<br/><br/>D01BAF</h1>
 <div class="paramtext"><div class="header"><b>Note:</b>&#160; before using this routine, please read the Users' Note for your implementation to check the interpretation of <span class="bitalic">bold italicised</span> terms and other implementation-dependent details.</div></div> 
<div class="htmltoc">
<h2 class="htmltoc"><span class="htmltochead" onclick="showLevel('htmltoc');"><span class="htmltocplus" id="htmltocplus">+</span><span class="htmltocminus" id="htmltocminus">&#8722;</span></span>&#160;Contents</h2>
<div class="htmltocitem" id="htmltoc">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#purpose">1&#160;&#160;<b>Purpose</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#specification">2&#160;&#160;<b>Specification</b></a>
</div><div class="htmltoc">
<span class="htmltoc" onclick="showLevel('tocdescription');"><span class="htmltocplus" id="tocdescriptionplus">+</span><span class="htmltocminus" id="tocdescriptionminus">&#8722;</span></span>
<a class="htmltoc" href="#description">3&#160;&#160;<b>Description</b></a>
<div class="htmltocitem" id="tocdescription">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#description1">3.1&#160;&#160;<b>General</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#description2">3.2&#160;&#160;<b>Both Limits Finite</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#description3">3.3&#160;&#160;<b>One Limit Infinite</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#description4">3.4&#160;&#160;<b>Both Limits Infinite</b></a>
</div>
</div>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#references">4&#160;&#160;<b>References</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#parameters">5&#160;&#160;<b>Parameters</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#errors">6&#160;&#160;<b>Error Indicators and Warnings</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#accuracy">7&#160;&#160;<b>Accuracy</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#fcomments">8&#160;&#160;<b>Further Comments</b></a>
</div><div class="htmltoc">
<span class="htmltoc" onclick="showLevel('tocexample');"><span class="htmltocplus" id="tocexampleplus">+</span><span class="htmltocminus" id="tocexampleminus">&#8722;</span></span>
<a class="htmltoc" href="#example">9&#160;&#160;<b>Example</b></a>
<div class="htmltocitem" id="tocexample">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#examtext">9.1&#160;&#160;<b>Program Text</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#examdata">9.2&#160;&#160;<b>Program Data</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#examresults">9.3&#160;&#160;<b>Program Results</b></a>
</div>
</div>
</div>
</div>
</div><h2 class="standard"><a class="sec" name="purpose" id="purpose"/>1&#160;&#160;Purpose</h2>
<div class="paramtext">D01BAF computes an estimate of the definite integral of a function of known analytical form, using a Gaussian quadrature formula with a specified number of abscissae.  Formulae are provided for a finite interval (Gauss&#8211;Legendre), a semi-infinite interval  (Gauss&#8211;Laguerre, Gauss&#8211;Rational), and an infinite interval (Gauss&#8211;Hermite).</div><h2 class="standard"><a class="sec" name="specification" id="specification"/>2&#160;&#160;Specification</h2>
<table class="fspec"><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b>&#160;FUNCTION&#160;D01BAF&#160;(</td><td class="tdfspec2"><a class="arg" href="#D01XXX">D01XXX</a>, <a class="arg" href="#A">A</a>, <a class="arg" href="#B">B</a>, <a class="arg" href="#N">N</a>, <a class="arg" href="#FUN">FUN</a>, <a class="arg" href="#IFAIL">IFAIL</a>)</td></tr><tr><td class="tdfspec1">INTEGER</td><td class="tdfspec2">N, IFAIL</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">A, B, FUN</td></tr><tr><td class="tdfspec1">EXTERNAL</td><td class="tdfspec2">D01XXX, FUN</td></tr></table><h2 class="standard"><a class="sec" name="description" id="description"/>3&#160;&#160;Description</h2><h3 class="standard"><a class="sec" name="description1" id="description1"/>3.1&#160;&#160;General</h3>
<div class="paramtext">D01BAF evaluates an estimate of the definite integral of a function <m:math><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>, over a finite or infinite range, by  <m:math><m:mi>n</m:mi></m:math>-point Gaussian quadrature (see <a class="ref" href="#ref201">Davis and Rabinowitz (1975)</a>, <a class="ref" href="#ref220">Fr&#246;berg (1970)</a>, <a class="ref" href="#ref018">Ralston (1965)</a> or <a class="ref" href="#ref019">Stroud and Secrest (1966)</a>).  The integral is approximated by a summation

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow><m:mi>n</m:mi></m:munderover><m:msub><m:mi>w</m:mi><m:mi>i</m:mi></m:msub><m:mi>f</m:mi><m:mfenced separators=""><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:mfenced>
</m:math></td><td class="formula2"/></tr></table></div>

where the <m:math><m:msub><m:mi>w</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;are called the weights, and the  <m:math><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;the abscissae.  A selection of values of  <m:math><m:mi>n</m:mi></m:math>&#160;is available.  (See <a class="sec" href="#parameters">Section 5</a>.)</div><h3 class="standard"><a class="sec" name="description2" id="description2"/>3.2&#160;&#160;Both Limits Finite</h3>
<div class="paramtext"><div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:munderover><m:mo>&#8747;</m:mo><m:mi>a</m:mi><m:mi>b</m:mi></m:munderover><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mrow><m:mi>d</m:mi><m:mi>x</m:mi></m:mrow><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The Gauss&#8211;Legendre weights and abscissae are used, and the formula is exact for any function of the form:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo> <m:mn>0</m:mn></m:mrow>
  <m:mrow><m:mn>2</m:mn><m:mi>n</m:mi><m:mo>-</m:mo> <m:mn>1</m:mn></m:mrow></m:munderover> <m:msub><m:mi>c</m:mi><m:mi>i</m:mi></m:msub> <m:msup><m:mi>x</m:mi><m:mi>i</m:mi></m:msup><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The formula is appropriate for functions which can be well approximated by such a polynomial over <m:math><m:mfenced separators="" open="[" close="]"><m:mi>a</m:mi><m:mo>,</m:mo><m:mi>b</m:mi></m:mfenced></m:math>.  It is inappropriate for functions with algebraic singularities at one or both ends of the interval,  such as <m:math><m:msup><m:mfenced separators=""><m:mn>1</m:mn><m:mo>+</m:mo><m:mi>x</m:mi></m:mfenced><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn><m:mo>/</m:mo><m:mn>2</m:mn></m:mrow></m:msup></m:math>&#160;on <m:math><m:mfenced separators="" open="[" close="]"><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mo>,</m:mo><m:mn>1</m:mn></m:mfenced></m:math>.</div><h3 class="standard"><a class="sec" name="description3" id="description3"/>3.3&#160;&#160;One Limit Infinite</h3>
<div class="paramtext"><div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:munderover><m:mo>&#8747;</m:mo><m:mi>a</m:mi><m:mi>&#8734;</m:mi></m:munderover><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mrow><m:mi>d</m:mi><m:mi>x</m:mi></m:mrow><m:mtext>&#8195; or &#8195;</m:mtext><m:munderover><m:mo>&#8747;</m:mo><m:mrow><m:mo>-</m:mo><m:mi>&#8734;</m:mi></m:mrow><m:mi>a</m:mi></m:munderover><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mrow><m:mi>d</m:mi><m:mi>x</m:mi></m:mrow><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

Two quadrature formulae are available for these integrals.
<table class="standard-100"><tr>
<td style="width:2.1em;" valign="baseline">(a)</td>
<td valign="top">The Gauss&#8211;Laguerre formula is exact for any function of the form:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:msup><m:mi>e</m:mi><m:mrow><m:mo>-</m:mo><m:mi>b</m:mi><m:mi>x</m:mi></m:mrow></m:msup> <m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo> <m:mn>0</m:mn></m:mrow>
  <m:mrow><m:mn>2</m:mn><m:mi>n</m:mi><m:mo>-</m:mo> <m:mn>1</m:mn></m:mrow></m:munderover> <m:msub><m:mi>c</m:mi><m:mi>i</m:mi></m:msub> <m:msup><m:mi>x</m:mi><m:mi>i</m:mi></m:msup><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

This formula is appropriate for functions decaying exponentially at infinity; the parameter <m:math><m:mi>b</m:mi></m:math>&#160;should be chosen if possible to match the decay rate of the function.</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline">(b)</td>
<td valign="top">The Gauss&#8211;Rational formula is exact for any function of the form:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>2</m:mn></m:mrow>
  <m:mrow><m:mn>2</m:mn><m:mi>n</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:mrow></m:munderover><m:mfrac><m:msub><m:mi>c</m:mi><m:mi>i</m:mi></m:msub><m:msup><m:mfenced separators=""><m:mi>x</m:mi><m:mo>+</m:mo><m:mi>b</m:mi></m:mfenced><m:mi>i</m:mi></m:msup></m:mfrac><m:mo>=</m:mo><m:mfrac><m:mrow><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>0</m:mn></m:mrow>
  <m:mrow><m:mn>2</m:mn><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:munderover><m:msub><m:mi>c</m:mi><m:mrow><m:mn>2</m:mn><m:mi>n</m:mi><m:mo>+</m:mo><m:mn>1</m:mn><m:mo>-</m:mo><m:mi>i</m:mi></m:mrow></m:msub><m:msup><m:mfenced separators=""><m:mi>x</m:mi><m:mo>+</m:mo><m:mi>b</m:mi></m:mfenced><m:mi>i</m:mi></m:msup></m:mrow><m:msup><m:mfenced separators=""><m:mi>x</m:mi><m:mo>+</m:mo><m:mi>b</m:mi></m:mfenced><m:mrow><m:mn>2</m:mn><m:mi>n</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:mrow></m:msup></m:mfrac><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

This formula is likely to be more accurate for functions having only an inverse power rate of decay for large <m:math><m:mi>x</m:mi></m:math>.  Here the choice of a suitable value of <m:math><m:mi>b</m:mi></m:math>&#160;may be more difficult; unfortunately a poor choice of <m:math><m:mi>b</m:mi></m:math>&#160;can make a large difference to the accuracy of the computed integral.</td>
</tr></table>
</div><h3 class="standard"><a class="sec" name="description4" id="description4"/>3.4&#160;&#160;Both Limits Infinite</h3>
<div class="paramtext"><div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:munderover><m:mo>&#8747;</m:mo><m:mrow><m:mo>-</m:mo><m:mi>&#8734;</m:mi></m:mrow>
  <m:mrow><m:mo>+</m:mo><m:mi>&#8734;</m:mi></m:mrow></m:munderover><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mrow><m:mi>d</m:mi><m:mi>x</m:mi></m:mrow><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The Gauss&#8211;Hermite weights and abscissae are used, and the formula is exact for any function of the form:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:msup><m:mi>e</m:mi><m:mrow><m:mo>-</m:mo><m:mi>b</m:mi><m:msup>
<m:mfenced separators=""><m:mi>x</m:mi><m:mo>-</m:mo><m:mi>a</m:mi></m:mfenced>
<m:mn>2</m:mn></m:msup></m:mrow></m:msup> <m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo> <m:mn>0</m:mn></m:mrow>
  <m:mrow><m:mn>2</m:mn><m:mi>n</m:mi><m:mo>-</m:mo> <m:mn>1</m:mn></m:mrow></m:munderover> <m:msub><m:mi>c</m:mi><m:mi>i</m:mi></m:msub> <m:msup><m:mi>x</m:mi><m:mi>i</m:mi></m:msup><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

Again, for general functions not of this exact form, the parameter  <m:math><m:mi>b</m:mi></m:math>&#160;should be chosen to match if possible the decay rate at <m:math><m:mtext/><m:mo>&#177;</m:mo><m:mi>&#8734;</m:mi></m:math>.</div><h2 class="standard"><a class="sec" name="references" id="references"/>4&#160;&#160;References</h2><div class="paramtext"><a name="ref201" id="ref201"/>Davis P J and Rabinowitz P (1975)  <i>Methods of Numerical Integration</i> Academic Press </div>
<div class="paramtext"><a name="ref220" id="ref220"/>Fr&#246;berg C E (1970)  <i>Introduction to Numerical Analysis</i> Addison&#8211;Wesley </div>
<div class="paramtext"><a name="ref018" id="ref018"/>Ralston A (1965)  <i>A First Course in Numerical Analysis</i> pp.&#160;87&#8211;90 McGraw&#8211;Hill </div>
<div class="paramtext"><a name="ref019" id="ref019"/>Stroud A H and Secrest D (1966)  <i>Gaussian Quadrature Formulas</i> Prentice&#8211;Hall </div><h2 class="standard"><a class="sec" name="parameters" id="parameters"/>5&#160;&#160;Parameters</h2>
<dl><dt class="paramhead"><a name="D01XXX" id="D01XXX"/>1: &#160;&#160;&#8194; D01XXX &#8211; SUBROUTINE, supplied by the NAG Library.<span class="pclass">External Procedure</span></dt><dd><div class="paramtext">The name of the routine indicates the quadrature formula:
<ul class="listind"><li class="listind">D01BAZ, for Gauss&#8211;Legendre quadrature on a finite interval;</li><li class="listind">D01BAY, for Gauss&#8211;Rational quadrature on a semi-infinite interval;</li><li class="listind">D01BAX, for Gauss&#8211;Laguerre quadrature on a semi-infinite interval;</li><li class="listind">D01BAW, for Gauss&#8211;Hermite quadrature on an infinite interval.</li></ul>
</div>
<div class="paramtext">The name used must be declared as EXTERNAL in the subroutine from which D01BAF is called.</div></dd><dt class="paramhead"><a name="A" id="A"/>2: &#160;&#160;&#8194; A &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dt class="multi-paramhead"><a name="B" id="B"/>3: &#160;&#160;&#8194; B &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the parameters <m:math><m:mi>a</m:mi></m:math>&#160;and <m:math><m:mi>b</m:mi></m:math>&#160;which occur in the integration formulae: 
<dl>
<dt class="paramval">Gauss&#8211;Legendre:</dt>
<dd><m:math><m:mi>a</m:mi></m:math>&#160;is the lower limit and <m:math><m:mi>b</m:mi></m:math>&#160;is the upper limit of the integral. It is not necessary that <m:math><m:mi>a</m:mi><m:mo>&lt;</m:mo><m:mi>b</m:mi></m:math>.</dd>
<dt class="paramval">Gauss&#8211;Rational:</dt>
<dd><m:math><m:mi>b</m:mi></m:math>&#160;must be chosen so as to make the integrand match as closely as possible the exact form given in <a class="sec" href="#description3">Section 3.3</a>(b). The range of integration is <m:math><m:mfenced open="[" close=")" separators=""><m:mi>a</m:mi><m:mi>&#8734;</m:mi></m:mfenced></m:math>&#160;if <m:math><m:mi>a</m:mi><m:mo>+</m:mo><m:mi>b</m:mi><m:mo>&gt;</m:mo><m:mn>0</m:mn></m:math>, and <m:math><m:mfenced open="(" close="]" separators=""><m:mrow><m:mo>-</m:mo><m:mi>&#8734;</m:mi></m:mrow><m:mi>a</m:mi></m:mfenced></m:math>&#160;if <m:math><m:mi>a</m:mi><m:mo>+</m:mo><m:mi>b</m:mi><m:mo>&lt;</m:mo><m:mn>0</m:mn></m:math>.</dd>
<dt class="paramval">Gauss&#8211;Laguerre:</dt>
<dd><m:math><m:mi>b</m:mi></m:math>&#160;must be chosen so as to make the integrand match as closely as possible the exact form given in <a class="sec" href="#description3">Section 3.3</a>(a). The range of integration is <m:math><m:mfenced open="[" close=")" separators=""><m:mi>a</m:mi><m:mi>&#8734;</m:mi></m:mfenced></m:math>&#160;if <m:math><m:mi>b</m:mi><m:mo>&gt;</m:mo><m:mn>0</m:mn></m:math>, and <m:math><m:mfenced open="(" close="]" separators=""><m:mrow><m:mo>-</m:mo><m:mi>&#8734;</m:mi></m:mrow><m:mi>a</m:mi></m:mfenced></m:math>&#160;is <m:math><m:mi>b</m:mi><m:mo>&lt;</m:mo><m:mn>0</m:mn></m:math>.</dd>
<dt class="paramval">Gauss&#8211;Hermite:</dt>
<dd><m:math><m:mi>a</m:mi></m:math>&#160;and <m:math><m:mi>b</m:mi></m:math>&#160;must be chosen so as to make the integrand match as closely as possible the exact form given in <a class="sec" href="#description4">Section 3.4</a>.</dd></dl>
</div><div class="paramtext"><i>Constraints</i>:
   <div class="paramtext"/><ul class="listcons">
<li class="listcons">Gauss&#8211;Rational: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#A"><m:mi mathcolor="#EE0000" mathvariant="bold">A</m:mi></m:maction><m:mo>+</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#B"><m:mi mathcolor="#EE0000" mathvariant="bold">B</m:mi></m:maction><m:mo>&#8800;</m:mo><m:mn>0</m:mn></m:math>;</li>
<li class="listcons">Gauss&#8211;Laguerre: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#B"><m:mi mathcolor="#EE0000" mathvariant="bold">B</m:mi></m:maction><m:mo>&#8800;</m:mo><m:mn>0</m:mn></m:math>;</li>
<li class="listcons">Gauss&#8211;Hermite: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#B"><m:mi mathcolor="#EE0000" mathvariant="bold">B</m:mi></m:maction><m:mo>&gt;</m:mo><m:mn>0</m:mn></m:math>.</li>
</ul></div></dd><dt class="paramhead"><a name="N" id="N"/>4: &#160;&#160;&#8194; N &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: <m:math><m:mi>n</m:mi></m:math>, the number of abscissae to be used.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math>, <m:math><m:mn>2</m:mn></m:math>, <m:math><m:mn>3</m:mn></m:math>, <m:math><m:mn>4</m:mn></m:math>, <m:math><m:mn>5</m:mn></m:math>, <m:math><m:mn>6</m:mn></m:math>, <m:math><m:mn>8</m:mn></m:math>, <m:math><m:mn>10</m:mn></m:math>, <m:math><m:mn>12</m:mn></m:math>, <m:math><m:mn>14</m:mn></m:math>, <m:math><m:mn>16</m:mn></m:math>, <m:math><m:mn>20</m:mn></m:math>, <m:math><m:mn>24</m:mn></m:math>, <m:math><m:mn>32</m:mn></m:math>, <m:math><m:mn>48</m:mn></m:math>&#160;or <m:math><m:mn>64</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="FUN" id="FUN"/>5: &#160;&#160;&#8194; FUN &#8211; <span class="bitalic">double precision</span> FUNCTION, supplied by the user.<span class="pclass">External Procedure</span></dt><dd><div class="paramtext"><a class="arg" href="#FUN">FUN</a> must return the value of the integrand <m:math><m:mi>f</m:mi></m:math>&#160;at a specified point.</div><div class="subprog">
<div class="paramtext">The specification of <a class="arg" href="#FUN">FUN</a> is:</div><table class="fspec"><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b>&#160;FUNCTION&#160;FUN&#160;(</td><td class="tdfspec2"><a class="arg" href="../D01/d01baf.xml#FUN_X">X</a>)</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">X</td></tr></table>
<dl><dt class="paramhead"><a name="FUN_X" id="FUN_X"/>1: &#160;&#160;&#8194; X &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the point at which the integrand <m:math><m:mi>f</m:mi></m:math>&#160;must be evaluated.</div></dd></dl>
</div>
<div class="paramtext"><a class="arg" href="#FUN">FUN</a> must be declared as EXTERNAL in the (sub)program from which D01BAF is called. Parameters denoted as <span class="italic">Input</span>  must <b>not</b>  be changed by this procedure.</div>
<div class="paramtext">Some points to bear in mind when coding <a class="arg" href="#FUN">FUN</a> are mentioned in  <a class="sec" href="#accuracy">Section 7</a>.</div>
</dd><dt class="paramhead"><a name="IFAIL" id="IFAIL"/>6: &#160;&#160;&#8194; IFAIL &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On entry</i>: <a class="arg" href="#IFAIL">IFAIL</a> must be set to <m:math><m:mn>0</m:mn></m:math>, <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>. If you are unfamiliar with this parameter you should refer to <a class="sec" href="../GENINT/essint.xml#library3">Section 3.3</a> in  the Essential Introduction for details.</div>
<div class="paramtext"><i>On exit</i>: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;unless the routine detects an error (see <a class="sec" href="#errors">Section 6</a>).
<div class="paramtext">For environments where it might be inappropriate to halt program execution when an error is detected, the value <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>&#160;is recommended.  If the output of error messages is undesirable, then the value <m:math><m:mn>1</m:mn></m:math>&#160;is recommended.  Otherwise, because for this routine the values of the output parameters may be useful even if <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>&#8800;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;on exit, the recommended value is <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:math>.  <b>When the value <m:math><m:mrow><m:mo>-</m:mo><m:mn mathvariant="bold">1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>&#160;is used it is essential to test the value of <a class="arg" href="#IFAIL">IFAIL</a> on exit.</b></div>
</div></dd></dl><h2 class="standard"><a class="sec" name="errors" id="errors"/>6&#160;&#160;Error Indicators and Warnings</h2>
<div class="paramtext">If on entry <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;or <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">-1</m:mn></m:maction></m:math>, explanatory error messages are output on the current error message unit (as defined by <a class="rout" href="../X04/x04aaf.xml">X04AAF</a>).</div><div class="paramtext"><b>Note:</b> D01BAF may return useful information for one or more of the following detected errors or warnings.</div><div class="paramtext">Errors or warnings detected by the routine:</div>
<dl class="ifail">
<dt class="errorhead"><a name="IFeq1" id="IFeq1"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math></dt>
<dd>
<div class="paramtext">The N-point rule is not among those stored.  If the soft fail option is used, the answer is evaluated for the largest valid value of <a class="arg" href="#N">N</a> less than the requested value.</div>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq2" id="IFeq2"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn></m:math></dt>
<dd>
<div class="paramtext">The value of <a class="arg" href="#A">A</a> and/or <a class="arg" href="#B">B</a> is invalid.</div>
<div class="paramtext">Gauss&#8211;Rational: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#A"><m:mi mathcolor="#EE0000" mathvariant="bold">A</m:mi></m:maction><m:mo>+</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#B"><m:mi mathcolor="#EE0000" mathvariant="bold">B</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn></m:math>.</div>
<div class="paramtext">Gauss&#8211;Laguerre: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#B"><m:mi mathcolor="#EE0000" mathvariant="bold">B</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn></m:math>.</div>
<div class="paramtext">Gauss&#8211;Hermite: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#B"><m:mi mathcolor="#EE0000" mathvariant="bold">B</m:mi></m:maction><m:mo>&#8804;</m:mo><m:mn>0</m:mn></m:math>.</div>
<div class="paramtext">If the soft fail option is used, the answer is returned as zero.</div>
</dd>
</dl><h2 class="standard"><a class="sec" name="accuracy" id="accuracy"/>7&#160;&#160;Accuracy</h2>
<div class="paramtext">The accuracy depends on the behaviour of the integrand, and on the number of abscissae used.  No tests are carried out in D01BAF to estimate the accuracy of the result.  If such an estimate is required, the routine may be called more than once, with a different number of abscissae each time, and the answers compared.  It is to be expected that for sufficiently smooth functions a larger number of abscissae will give improved accuracy.</div><div class="paramtext">Alternatively, the range of integration may be subdivided, the integral estimated separately for each sub-interval, and the sum of these estimates compared with the estimate over the whole range.</div><div class="paramtext">The coding of <a class="arg" href="#FUN">FUN</a> may also have a bearing on the accuracy.  For example, if a high-order Gauss&#8211;Laguerre formula is used, and the integrand is of the form

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:msup><m:mi>e</m:mi><m:mrow><m:mo>-</m:mo><m:mi>b</m:mi><m:mi>x</m:mi></m:mrow></m:msup><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced>
</m:math></td><td class="formula2"/></tr></table></div>

it is possible that the exponential term may underflow for some large abscissae.  Depending on the machine, this may produce an error, or simply be assumed to be zero.  In any case, it would be better to evaluate the expression as:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:mrow><m:mi>exp</m:mi><m:mfenced separators=""><m:mo>-</m:mo><m:mi>b</m:mi><m:mi>x</m:mi><m:mo>+</m:mo><m:mrow><m:mi>ln</m:mi><m:mo>&#8289;</m:mo><m:mi>g</m:mi></m:mrow><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:mfenced></m:mrow>
</m:math></td><td class="formula2"/></tr></table></div>

Another situation requiring care is exemplified by

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:munderover><m:mo>&#8747;</m:mo><m:mrow><m:mo>-</m:mo><m:mi>&#8734;</m:mi></m:mrow>
  <m:mrow><m:mo>+</m:mo><m:mi>&#8734;</m:mi></m:mrow></m:munderover><m:msup><m:mi>e</m:mi><m:mrow><m:mo>-</m:mo><m:msup><m:mi>x</m:mi><m:mn>2</m:mn></m:msup></m:mrow></m:msup><m:msup><m:mi>x</m:mi><m:mi>m</m:mi></m:msup><m:mrow><m:mi>d</m:mi><m:mi>x</m:mi></m:mrow><m:mo>=</m:mo><m:mn>0</m:mn><m:mtext>, &#8195;</m:mtext><m:mi>m</m:mi><m:mtext>&#8203; odd.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The integrand here assumes very large values; for example, for  <m:math><m:mi>m</m:mi><m:mo>=</m:mo><m:mn>63</m:mn></m:math>, the peak value exceeds <m:math><m:mn>3</m:mn><m:mo>&#215;</m:mo><m:msup><m:mn>10</m:mn><m:mn>33</m:mn></m:msup></m:math>.  Now, if the machine holds floating-point numbers to an accuracy of  <m:math><m:mi>k</m:mi></m:math>&#160;significant decimal digits, we could not expect such terms to cancel in the summation leaving an answer of much less than  <m:math><m:msup><m:mn>10</m:mn><m:mrow><m:mn>33</m:mn><m:mo>-</m:mo><m:mi>k</m:mi></m:mrow></m:msup></m:math>&#160;(the weights being of order unity); that is instead of zero, we obtain a rather large answer through rounding error.  Fortunately, such situations are characterised by great variability in the answers returned by formulae with different values of <m:math><m:mi>n</m:mi></m:math>.  In general, you should be aware of the order of magnitude of the integrand, and should judge the answer in that light.</div><h2 class="standard"><a class="sec" name="fcomments" id="fcomments"/>8&#160;&#160;Further Comments</h2>
<div class="paramtext">The time taken by D01BAF depends on the complexity of the expression for the integrand and on the number of abscissae required.</div><h2 class="standard"><a class="sec" name="example" id="example"/>9&#160;&#160;Example</h2>
<div class="paramtext">This example evaluates the integrals

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:munderover><m:mo>&#8747;</m:mo><m:mn>0</m:mn><m:mn>1</m:mn></m:munderover><m:mfrac><m:mn>4</m:mn><m:mrow><m:mn>1</m:mn><m:mo>+</m:mo><m:msup><m:mi>x</m:mi><m:mn>2</m:mn></m:msup></m:mrow>
 </m:mfrac><m:mrow><m:mi>d</m:mi><m:mi>x</m:mi></m:mrow><m:mo>=</m:mo><m:mi>&#960;</m:mi>
</m:math></td><td class="formula2"/></tr></table></div>

by Gauss&#8211;Legendre quadrature;

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:munderover><m:mo>&#8747;</m:mo><m:mn>2</m:mn><m:mi>&#8734;</m:mi></m:munderover> <m:mfrac><m:mn>1</m:mn><m:mrow><m:msup><m:mi>x</m:mi><m:mn>2</m:mn></m:msup> <m:mrow><m:mi>ln</m:mi><m:mo>&#8289;</m:mo><m:mi>x</m:mi></m:mrow></m:mrow>
 </m:mfrac> <m:mrow><m:mi>d</m:mi><m:mi>x</m:mi></m:mrow> <m:mo>=</m:mo><m:mn>0.378671</m:mn>
</m:math></td><td class="formula2"/></tr></table></div>

by Gauss&#8211;Rational quadrature with <m:math><m:mi>b</m:mi><m:mo>=</m:mo><m:mn>0</m:mn></m:math>;

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:munderover><m:mo>&#8747;</m:mo><m:mn>2</m:mn><m:mi>&#8734;</m:mi></m:munderover><m:mfrac><m:msup><m:mi>e</m:mi><m:mrow><m:mo>-</m:mo><m:mi>x</m:mi></m:mrow></m:msup><m:mi>x</m:mi></m:mfrac><m:mrow><m:mi>d</m:mi><m:mi>x</m:mi></m:mrow><m:mo>=</m:mo><m:mn>0.048901</m:mn>
</m:math></td><td class="formula2"/></tr></table></div>

by Gauss&#8211;Laguerre quadrature with <m:math><m:mi>b</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:math>; and

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:munderover><m:mo>&#8747;</m:mo><m:mrow><m:mo>-</m:mo><m:mi>&#8734;</m:mi></m:mrow>
  <m:mrow><m:mo>+</m:mo><m:mi>&#8734;</m:mi></m:mrow></m:munderover><m:msup><m:mi>e</m:mi><m:mrow><m:mo>-</m:mo><m:mn>3</m:mn><m:mo>&#8290;</m:mo><m:msup><m:mi>x</m:mi><m:mn>2</m:mn></m:msup><m:mo>-</m:mo><m:mn>4</m:mn><m:mi>x</m:mi><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:msup><m:mrow><m:mi>d</m:mi><m:mi>x</m:mi></m:mrow><m:mo>=</m:mo><m:munderover><m:mo>&#8747;</m:mo><m:mrow><m:mo>-</m:mo><m:mi>&#8734;</m:mi></m:mrow>
  <m:mrow><m:mo>+</m:mo><m:mi>&#8734;</m:mi></m:mrow></m:munderover><m:msup><m:mi>e</m:mi><m:mrow><m:mo>-</m:mo><m:mn>3</m:mn><m:mo>&#8290;</m:mo><m:msup>
<m:mfenced separators=""><m:mi>x</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:mfenced>
<m:mn>2</m:mn></m:msup></m:mrow></m:msup><m:msup><m:mi>e</m:mi><m:mrow><m:mn>2</m:mn><m:mi>x</m:mi><m:mo>+</m:mo><m:mn>2</m:mn></m:mrow></m:msup><m:mi>d</m:mi><m:mi>x</m:mi><m:mo>=</m:mo><m:mn>1.428167</m:mn>
</m:math></td><td class="formula2"/></tr></table></div>

by Gauss&#8211;Hermite quadrature with <m:math><m:mi>a</m:mi><m:mo>=</m:mo><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:math>&#160;and <m:math><m:mi>b</m:mi><m:mo>=</m:mo><m:mn>3</m:mn></m:math>.</div><div class="paramtext">The formulae with <m:math><m:mi>n</m:mi><m:mo>=</m:mo><m:mn>4</m:mn><m:mo>,</m:mo><m:mn>8</m:mn><m:mo>,</m:mo><m:mn>16</m:mn></m:math>&#160;are used in each case.</div><h3 class="standard"><a class="sec" name="examtext" id="examtext"/>9.1&#160;&#160;Program Text</h3>
<p><a class="verbatimref" href="../../examples/source/d01bafe.f">Program Text (d01bafe.f)</a></p><h3 class="standard"><a class="sec" name="examdata" id="examdata"/>9.2&#160;&#160;Program Data</h3>
<div class="paramtext">None.</div><h3 class="standard"><a class="sec" name="examresults" id="examresults"/>9.3&#160;&#160;Program Results</h3>
<p><a class="verbatimref" href="../../examples/baseresults/d01bafe.r">Program Results (d01bafe.r)</a></p><hr/><div><a class="rout" href="../../pdf/D01/d01baf.pdf">D01BAF (PDF version)</a></div><div><a class="chap" href="d01conts.xml">D01 Chapter Contents</a></div><div><a class="chapint" href="d01intro.xml">D01 Chapter Introduction</a></div>
<div><a class="htmltoc" href="../FRONTMATTER/manconts.xml">NAG Library Manual</a></div>
<div><hr/><a class="genint" href="../FRONTMATTER/copyright.xml">&#169; The Numerical Algorithms Group Ltd, Oxford, UK. 2009</a></div></body></html>
