<?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>D01APF : 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/d01apf.pdf">D01APF (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/>D01APF</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="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#description">3&#160;&#160;<b>Description</b></a>
</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">D01APF is an adaptive integrator which calculates an approximation to the integral of a function <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mi>w</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;over a finite interval <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>:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
 <m:mi>I</m:mi><m:mo>=</m:mo>
 <m:munderover><m:mo>&#8747;</m:mo><m:mi>a</m:mi><m:mi>b</m:mi></m:munderover>
 <m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced>
 <m:mi>w</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:math></td><td class="formula2"/></tr></table></div>

where the weight function <m:math><m:mi>w</m:mi></m:math>&#160;has end point singularities of algebraico-logarithmic type.</div><h2 class="standard"><a class="sec" name="specification" id="specification"/>2&#160;&#160;Specification</h2>
<table class="fspec"><tr><td class="tdfspec1">SUBROUTINE&#160;D01APF&#160;(</td><td class="tdfspec2"><a class="arg" href="#G">G</a>, <a class="arg" href="#A">A</a>, <a class="arg" href="#B">B</a>, <a class="arg" href="#ALFA">ALFA</a>, <a class="arg" href="#BETA">BETA</a>, <a class="arg" href="#KEY">KEY</a>, <a class="arg" href="#EPSABS">EPSABS</a>, <a class="arg" href="#EPSREL">EPSREL</a>, <a class="arg" href="#RESULT">RESULT</a>, <a class="arg" href="#ABSERR">ABSERR</a>, <a class="arg" href="#W">W</a>, <a class="arg" href="#LW">LW</a>, <a class="arg" href="#IW">IW</a>, <a class="arg" href="#LIW">LIW</a>, <a class="arg" href="#IFAIL">IFAIL</a>)</td></tr><tr><td class="tdfspec1">INTEGER</td><td class="tdfspec2">KEY, LW, IW(LIW), LIW, IFAIL</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">G, A, B, ALFA, BETA, EPSABS, EPSREL, RESULT, ABSERR, W(LW)</td></tr><tr><td class="tdfspec1">EXTERNAL</td><td class="tdfspec2">G</td></tr></table><h2 class="standard"><a class="sec" name="description" id="description"/>3&#160;&#160;Description</h2>
<div class="paramtext">D01APF is based on the QUADPACK routine QAWSE (see <a class="ref" href="#ref010">Piessens <span class="italic">et al.</span> (1983)</a>) and integrates a function of the form <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mi>w</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>, where the weight function <m:math><m:mi>w</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;may have algebraico-logarithmic singularities at the end points <m:math><m:mi>a</m:mi></m:math>&#160;and/or <m:math><m:mi>b</m:mi></m:math>.  The strategy is a modification of that in  <a class="rout" href="../D01/d01akf.xml">D01AKF</a>.  We start by bisecting the original interval and applying modified Clenshaw&#8211;Curtis integration of orders <m:math><m:mn>12</m:mn></m:math>&#160;and <m:math><m:mn>24</m:mn></m:math>&#160;to both halves.  Clenshaw&#8211;Curtis integration is then used on all sub-intervals which have <m:math><m:mi>a</m:mi></m:math>&#160;or <m:math><m:mi>b</m:mi></m:math>&#160;as one of their end points  (see <a class="ref" href="#ref014">Piessens <span class="italic">et al.</span> (1974)</a>).  On the other sub-intervals  Gauss&#8211;Kronrod (<m:math><m:mn>7</m:mn></m:math>&#8211;<m:math><m:mn>15</m:mn></m:math>&#160;point) integration is carried out.</div><div class="paramtext">A &#8216;global&#8217; acceptance criterion (as defined by <a class="ref" href="#ref009">Malcolm and Simpson (1976)</a>) is used.  The local error estimation control is described in <a class="ref" href="#ref010">Piessens <span class="italic">et al.</span> (1983)</a>.</div><h2 class="standard"><a class="sec" name="references" id="references"/>4&#160;&#160;References</h2><div class="paramtext"><a name="ref009" id="ref009"/>Malcolm M A and Simpson R B (1976)  Local versus global strategies for adaptive quadrature <i>ACM Trans. Math. Software</i> <b>1</b> 129&#8211;146 </div>
<div class="paramtext"><a name="ref010" id="ref010"/>Piessens R, de Doncker&#8211;Kapenga E, &#220;berhuber C and Kahaner D (1983)  <i>QUADPACK, A Subroutine Package for Automatic Integration</i> Springer&#8211;Verlag </div>
<div class="paramtext"><a name="ref014" id="ref014"/>Piessens R, Mertens I and Branders M (1974)  Integration of functions having end-point singularities <i>Angew. Inf.</i> <b>16</b> 65&#8211;68 </div><h2 class="standard"><a class="sec" name="parameters" id="parameters"/>5&#160;&#160;Parameters</h2>
<dl><dt class="paramhead"><a name="G" id="G"/>1: &#160;&#160;&#8194; G &#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="#G">G</a> must return the value of the function <m:math><m:mi>g</m:mi></m:math>&#160;at a given point <a class="arg" href="../D01/d01apf.xml#G_X">X</a>.</div><div class="subprog">
<div class="paramtext">The specification of <a class="arg" href="#G">G</a> is:</div><table class="fspec"><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b>&#160;FUNCTION&#160;G&#160;(</td><td class="tdfspec2"><a class="arg" href="../D01/d01apf.xml#G_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="G_X" id="G_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 function <m:math><m:mi>g</m:mi></m:math>&#160;must be evaluated.</div></dd></dl>
</div>
<div class="paramtext"><a class="arg" href="#G">G</a> must be declared as EXTERNAL in the (sub)program from which D01APF is called. Parameters denoted as <span class="italic">Input</span>  must <b>not</b>  be changed by this procedure.</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><dd><div class="paramtext"><i>On entry</i>: <m:math><m:mi>a</m:mi></m:math>, the lower limit of integration.</div></dd><dt class="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>: <m:math><m:mi>b</m:mi></m:math>, the upper limit of integration.</div><div class="paramtext"><i>Constraint</i>:
  <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:maction actiontype="link" dsi:type="simple" dsi:href="#A"><m:mi mathcolor="#EE0000" mathvariant="bold">A</m:mi></m:maction></m:math>.
</div></dd><dt class="paramhead"><a name="ALFA" id="ALFA"/>4: &#160;&#160;&#8194; ALFA &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the parameter <m:math><m:mi>&#945;</m:mi></m:math>&#160;in the weight function.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#ALFA"><m:mi mathcolor="#EE0000" mathvariant="bold">ALFA</m:mi></m:maction><m:mo>&gt;</m:mo><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:math>.
</div></dd><dt class="paramhead"><a name="BETA" id="BETA"/>5: &#160;&#160;&#8194; BETA &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the parameter <m:math><m:mi>&#946;</m:mi></m:math>&#160;in the weight function.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#BETA"><m:mi mathcolor="#EE0000" mathvariant="bold">BETA</m:mi></m:maction><m:mo>&gt;</m:mo><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:math>.
</div></dd><dt class="paramhead"><a name="KEY" id="KEY"/>6: &#160;&#160;&#8194; KEY &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: indicates which weight function is to be used.

<dl>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#KEY"><m:mi mathcolor="#EE0000" mathvariant="bold">KEY</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math></dt>
<dd><m:math><m:mi>w</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:msup><m:mfenced separators=""><m:mi>x</m:mi><m:mo>-</m:mo><m:mi>a</m:mi></m:mfenced><m:mi>&#945;</m:mi></m:msup><m:msup><m:mfenced separators=""><m:mi>b</m:mi><m:mo>-</m:mo><m:mi>x</m:mi></m:mfenced> <m:mi>&#946;</m:mi></m:msup></m:math>.</dd>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#KEY"><m:mi mathcolor="#EE0000" mathvariant="bold">KEY</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn></m:math></dt>
<dd><m:math><m:mi>w</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:msup> <m:mfenced separators=""><m:mi>x</m:mi><m:mo>-</m:mo><m:mi>a</m:mi></m:mfenced> <m:mi>&#945;</m:mi></m:msup><m:msup> <m:mfenced separators=""><m:mi>b</m:mi><m:mo>-</m:mo><m:mi>x</m:mi></m:mfenced> <m:mi>&#946;</m:mi></m:msup><m:mrow><m:mi>ln</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>-</m:mo><m:mi>a</m:mi></m:mfenced></m:mrow></m:math>.</dd>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#KEY"><m:mi mathcolor="#EE0000" mathvariant="bold">KEY</m:mi></m:maction><m:mo>=</m:mo><m:mn>3</m:mn></m:math></dt>
<dd><m:math><m:mi>w</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:msup> <m:mfenced separators=""><m:mi>x</m:mi><m:mo>-</m:mo><m:mi>a</m:mi></m:mfenced> <m:mi>&#945;</m:mi></m:msup><m:msup> <m:mfenced separators=""><m:mi>b</m:mi><m:mo>-</m:mo><m:mi>x</m:mi></m:mfenced> <m:mi>&#946;</m:mi></m:msup><m:mrow><m:mi>ln</m:mi><m:mfenced separators=""><m:mi>b</m:mi><m:mo>-</m:mo><m:mi>x</m:mi></m:mfenced></m:mrow></m:math>.</dd>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#KEY"><m:mi mathcolor="#EE0000" mathvariant="bold">KEY</m:mi></m:maction><m:mo>=</m:mo><m:mn>4</m:mn></m:math></dt>
<dd><m:math><m:mi>w</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:msup> <m:mfenced separators=""><m:mi>x</m:mi><m:mo>-</m:mo><m:mi>a</m:mi></m:mfenced> <m:mi>&#945;</m:mi></m:msup><m:msup> <m:mfenced separators=""><m:mi>b</m:mi><m:mo>-</m:mo><m:mi>x</m:mi></m:mfenced> <m:mi>&#946;</m:mi></m:msup><m:mrow><m:mi>ln</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>-</m:mo><m:mi>a</m:mi></m:mfenced></m:mrow><m:mrow><m:mi>ln</m:mi><m:mfenced separators=""><m:mi>b</m:mi><m:mo>-</m:mo><m:mi>x</m:mi></m:mfenced></m:mrow></m:math>.</dd></dl>
</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#KEY"><m:mi mathcolor="#EE0000" mathvariant="bold">KEY</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>&#160;or <m:math><m:mn>4</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="EPSABS" id="EPSABS"/>7: &#160;&#160;&#8194; EPSABS &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the absolute accuracy required. If <a class="arg" href="#EPSABS">EPSABS</a> is negative, the absolute value is used. See <a class="sec" href="#accuracy">Section 7</a>.</div></dd><dt class="paramhead"><a name="EPSREL" id="EPSREL"/>8: &#160;&#160;&#8194; EPSREL &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the relative accuracy required. If <a class="arg" href="#EPSREL">EPSREL</a> is negative, the absolute value is used. See <a class="sec" href="#accuracy">Section 7</a>.</div></dd><dt class="paramhead"><a name="RESULT" id="RESULT"/>9: &#160;&#160;&#8194; RESULT &#8211; <span class="bitalic">double precision</span><span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: the approximation to the integral <m:math><m:mi>I</m:mi></m:math>.</div></dd><dt class="paramhead"><a name="ABSERR" id="ABSERR"/>10: &#8194; ABSERR &#8211; <span class="bitalic">double precision</span><span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: an estimate of the modulus of the absolute error, which should be an upper bound for <m:math><m:mfenced open="|" close="|" separators=""><m:mi>I</m:mi><m:mo>-</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#RESULT"><m:mi mathcolor="#EE0000" mathvariant="bold">RESULT</m:mi></m:maction></m:mfenced></m:math>.</div></dd><dt class="paramhead"><a name="W" id="W"/>11: &#8194; W(<a class="arg" href="#LW">LW</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: details of the computation, as described in <a class="sec" href="#fcomments">Section 8</a>.</div></dd><dt class="paramhead"><a name="LW" id="LW"/>12: &#8194; LW &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the dimension of the array <a class="arg" href="#W">W</a> as declared in the (sub)program from which D01APF is called. The value of <a class="arg" href="#LW">LW</a> (together with that of <a class="arg" href="#LIW">LIW</a>) imposes a bound on the number of sub-intervals into which the interval of integration may be divided by the routine. The number of sub-intervals cannot exceed <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LW"><m:mi mathcolor="#EE0000" mathvariant="bold">LW</m:mi></m:maction><m:mo>/</m:mo><m:mn>4</m:mn></m:math>. The more difficult the integrand, the larger <a class="arg" href="#LW">LW</a> should be.</div>
<div class="paramtext"><i>Suggested value</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LW"><m:mi mathcolor="#EE0000" mathvariant="bold">LW</m:mi></m:maction><m:mo>=</m:mo><m:mn>800</m:mn></m:math>&#160;to <m:math><m:mn>2000</m:mn></m:math>&#160;is adequate for most problems.

</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LW"><m:mi mathcolor="#EE0000" mathvariant="bold">LW</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>8</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="IW" id="IW"/>13: &#8194; IW(<a class="arg" href="#LIW">LIW</a>) &#8211; INTEGER array<span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#IW"><m:mi mathcolor="#EE0000" mathvariant="bold">IW</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>1</m:mn></m:mfenced></m:mrow></m:math>&#160;contains the actual number of sub-intervals used. The rest of the array is used as workspace.</div></dd><dt class="paramhead"><a name="LIW" id="LIW"/>14: &#8194; LIW &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the dimension of the array <a class="arg" href="#IW">IW</a> as declared in the (sub)program from which D01APF is called. The number of sub-intervals into which the interval of integration may be divided cannot exceed <a class="arg" href="#LIW">LIW</a>.</div>
<div class="paramtext"><i>Suggested value</i>:
  

<m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LIW"><m:mi mathcolor="#EE0000" mathvariant="bold">LIW</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#LW"><m:mi mathcolor="#EE0000" mathvariant="bold">LW</m:mi></m:maction><m:mo>/</m:mo><m:mn>4</m:mn></m:math>.
</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LIW"><m:mi mathcolor="#EE0000" mathvariant="bold">LIW</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>2</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="IFAIL" id="IFAIL"/>15: &#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> D01APF 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 maximum number of subdivisions allowed with the given workspace has been reached without the accuracy requirements being achieved.  Look at the integrand in order to determine the integration difficulties.  If the position of a discontinuity or a singularity of algebraico-logarithmic type within the interval can be determined, the interval must be split up at this point and the integrator called on the subranges.  If necessary, another integrator, which is designed for handling the type of difficulty involved, must be used.  Alternatively, consider relaxing the accuracy requirements specified by <a class="arg" href="#EPSABS">EPSABS</a> and <a class="arg" href="#EPSREL">EPSREL</a>, or increasing the amount of workspace.</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">Round-off error prevents the requested tolerance from being achieved.  Consider requesting less accuracy.</div></dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq3" id="IFeq3"/><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>3</m:mn></m:math></dt>
<dd><div class="paramtext">Extremely bad local integrand behaviour causes a very strong subdivision around one (or more) points of the interval.  The same advice applies as in the case of <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="#IFeq1"><m:mn mathcolor="#003399" mathvariant="bold">1</m:mn></m:maction></m:math>.</div></dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq4" id="IFeq4"/><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>4</m:mn></m:math></dt>
<dd>
<table class="ifail"><tr><td class="ifail1">On&#160;entry,</td><td class="ifail2-90"><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:maction actiontype="link" dsi:type="simple" dsi:href="#A"><m:mi mathcolor="#EE0000" mathvariant="bold">A</m:mi></m:maction></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#ALFA"><m:mi mathcolor="#EE0000" mathvariant="bold">ALFA</m:mi></m:maction><m:mo>&#8804;</m:mo><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#BETA"><m:mi mathcolor="#EE0000" mathvariant="bold">BETA</m:mi></m:maction><m:mo>&#8804;</m:mo><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#KEY"><m:mi mathcolor="#EE0000" mathvariant="bold">KEY</m:mi></m:maction><m:mo>&#8800;</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>&#160;or <m:math><m:mn>4</m:mn></m:math>.</td></tr></table>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq5" id="IFeq5"/><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>5</m:mn></m:math></dt>
<dd>
<table class="ifail"><tr><td class="ifail1">On&#160;entry,</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LW"><m:mi mathcolor="#EE0000" mathvariant="bold">LW</m:mi></m:maction><m:mo>&lt;</m:mo><m:mn>8</m:mn></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LIW"><m:mi mathcolor="#EE0000" mathvariant="bold">LIW</m:mi></m:maction><m:mo>&lt;</m:mo><m:mn>2</m:mn></m:math>.</td></tr></table>
</dd>
</dl><h2 class="standard"><a class="sec" name="accuracy" id="accuracy"/>7&#160;&#160;Accuracy</h2>
<div class="paramtext">D01APF cannot guarantee, but in practice usually achieves, the following accuracy:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mfenced open="|" close="|" separators=""><m:mi>I</m:mi><m:mo>-</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#RESULT"><m:mi mathcolor="#EE0000" mathvariant="bold">RESULT</m:mi></m:maction></m:mfenced><m:mo>&#8804;</m:mo><m:mi mathvariant="italic">tol</m:mi><m:mtext>,</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

where

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi mathvariant="italic">tol</m:mi><m:mo>=</m:mo><m:mrow><m:mi>max</m:mi><m:mspace width="0.125em"/><m:mfenced open="{" close="}" separators=""><m:mfenced open="|" close="|" separators=""><m:maction actiontype="link" dsi:type="simple" dsi:href="#EPSABS"><m:mi mathcolor="#EE0000" mathvariant="bold">EPSABS</m:mi></m:maction></m:mfenced><m:mo>,</m:mo><m:mfenced open="|" close="|" separators=""><m:maction actiontype="link" dsi:type="simple" dsi:href="#EPSREL"><m:mi mathcolor="#EE0000" mathvariant="bold">EPSREL</m:mi></m:maction></m:mfenced><m:mo>&#215;</m:mo><m:mfenced open="|" close="|" separators=""><m:mi>I</m:mi></m:mfenced></m:mfenced></m:mrow> <m:mtext>,</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

and <a class="arg" href="#EPSABS">EPSABS</a> and <a class="arg" href="#EPSREL">EPSREL</a> are user-specified absolute and relative error tolerances.  Moreover, it returns the quantity <a class="arg" href="#ABSERR">ABSERR</a> which, in normal circumstances, satisfies

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mfenced open="|" close="|" separators=""><m:mi>I</m:mi><m:mo>-</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#RESULT"><m:mi mathcolor="#EE0000" mathvariant="bold">RESULT</m:mi></m:maction></m:mfenced><m:mo>&#8804;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#ABSERR"><m:mi mathcolor="#EE0000" mathvariant="bold">ABSERR</m:mi></m:maction><m:mo>&#8804;</m:mo><m:mi mathvariant="italic">tol</m:mi><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div></div><h2 class="standard"><a class="sec" name="fcomments" id="fcomments"/>8&#160;&#160;Further Comments</h2>
<div class="paramtext">The time taken by D01APF depends on the integrand and the accuracy required.</div><div class="paramtext">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, then you may wish to examine the contents of the array <a class="arg" href="#W">W</a>, which contains the end points of the sub-intervals used by D01APF along with the integral contributions and error estimates over these sub-intervals.</div><div class="paramtext">Specifically, for <m:math><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>n</m:mi></m:math>, let <m:math><m:msub><m:mi>r</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;denote the approximation to the value of the integral over the sub-interval <m:math>
 <m:mfenced separators="" open="[" close="]"><m:msub><m:mi>a</m:mi><m:mi>i</m:mi></m:msub><m:mo>,</m:mo><m:msub><m:mi>b</m:mi><m:mi>i</m:mi></m:msub></m:mfenced>
</m:math>&#160;in the partition of <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>&#160;and <m:math>
 <m:msub><m:mi>e</m:mi><m:mi>i</m:mi></m:msub>
</m:math>&#160;be the corresponding absolute error estimate.  Then, <m:math>
 <m:mstyle displaystyle="true"><m:munderover>
  <m:mo>&#8747;</m:mo>
  <m:msub><m:mi>a</m:mi><m:mi>i</m:mi></m:msub>
  <m:msub><m:mi>b</m:mi><m:mi>i</m:mi></m:msub>
 </m:munderover></m:mstyle>
 <m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced>
 <m:mi>w</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:mo>&#8771;</m:mo>
 <m:msub><m:mi>r</m:mi><m:mi>i</m:mi></m:msub>
</m:math>&#160;and <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#RESULT"><m:mi mathcolor="#EE0000" mathvariant="bold">RESULT</m:mi></m:maction>
 <m:mo>=</m:mo>
 <m:mstyle displaystyle="true"><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:mstyle>
 <m:msub><m:mi>r</m:mi><m:mi>i</m:mi></m:msub>
</m:math>.  The value of <m:math><m:mi>n</m:mi></m:math>&#160;is returned in 
<m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#IW"><m:mi mathcolor="#EE0000" mathvariant="bold">IW</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>1</m:mn></m:mfenced></m:mrow></m:math>, 

and the values <m:math><m:msub><m:mi>a</m:mi><m:mi>i</m:mi></m:msub></m:math>, <m:math><m:msub><m:mi>b</m:mi><m:mi>i</m:mi></m:msub></m:math>, <m:math><m:msub><m:mi>e</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;and <m:math><m:msub><m:mi>r</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;are stored consecutively in the 
 array <a class="arg" href="#W">W</a>,

that is:
<ul class="listind"><li class="listind"><m:math><m:msub><m:mi>a</m:mi><m:mi>i</m:mi></m:msub><m:mo>=</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#W"><m:mi mathcolor="#EE0000" mathvariant="bold">W</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi></m:mfenced></m:mrow></m:math>,</li><li class="listind"><m:math><m:msub><m:mi>b</m:mi><m:mi>i</m:mi></m:msub><m:mo>=</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#W"><m:mi mathcolor="#EE0000" mathvariant="bold">W</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mrow><m:mi>n</m:mi><m:mo>+</m:mo><m:mi>i</m:mi></m:mrow></m:mfenced></m:mrow></m:math>,</li><li class="listind"><m:math><m:msub><m:mi>e</m:mi><m:mi>i</m:mi></m:msub><m:mo>=</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#W"><m:mi mathcolor="#EE0000" mathvariant="bold">W</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mrow><m:mn>2</m:mn><m:mi>n</m:mi><m:mo>+</m:mo><m:mi>i</m:mi></m:mrow></m:mfenced></m:mrow></m:math>&#160;and </li><li class="listind"><m:math><m:msub><m:mi>r</m:mi><m:mi>i</m:mi></m:msub><m:mo>=</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#W"><m:mi mathcolor="#EE0000" mathvariant="bold">W</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mrow><m:mn>3</m:mn><m:mi>n</m:mi><m:mo>+</m:mo><m:mi>i</m:mi></m:mrow></m:mfenced></m:mrow></m:math>.</li></ul></div><h2 class="standard"><a class="sec" name="example" id="example"/>9&#160;&#160;Example</h2>
<div class="paramtext">This example computes

<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:mrow><m:mi>ln</m:mi><m:mo>&#8289;</m:mo><m:mi>x</m:mi></m:mrow>
 <m:mrow><m:mi>cos</m:mi><m:mfenced separators=""><m:mn>10</m:mn><m:mi>&#960;</m:mi><m:mi>x</m:mi></m:mfenced></m:mrow>
 <m:mrow><m:mi>d</m:mi><m:mi>x</m:mi></m:mrow>
 <m:mtext>&#8195; and &#8195;</m:mtext>
 <m:munderover><m:mo>&#8747;</m:mo><m:mn>0</m:mn><m:mn>1</m:mn></m:munderover>
 <m:mfrac>
  <m:mrow><m:mi>sin</m:mi><m:mfenced separators=""><m:mn>10</m:mn><m:mi>x</m:mi></m:mfenced></m:mrow>
  <m:msqrt><m:mi>x</m:mi><m:mfenced separators=""><m:mn>1</m:mn><m:mo>-</m:mo><m:mi>x</m:mi></m:mfenced></m:msqrt>
 </m:mfrac>
 <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></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/d01apfe.f">Program Text (d01apfe.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/d01apfe.r">Program Results (d01apfe.r)</a></p>
<hr/><div><a class="rout" href="../../pdf/D01/d01apf.pdf">D01APF (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>
