<?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>D02BJF : 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/D02/d02bjf.pdf">D02BJF (PDF version)</a></div><div><a class="chap" href="d02conts.xml">D02 Chapter Contents</a></div><div><a class="chapint" href="d02intro.xml">D02 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/>D02BJF</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">D02BJF integrates a system of first-order ordinary differential equations over an interval with suitable initial conditions, using a fixed order Runge&#8211;Kutta method, until a user-specified function, if supplied, of the solution is zero, and returns the solution at points specified by you, if desired.</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;D02BJF&#160;(</td><td class="tdfspec2"><a class="arg" href="#X">X</a>, <a class="arg" href="#XEND">XEND</a>, <a class="arg" href="#N">N</a>, <a class="arg" href="#Y">Y</a>, <a class="arg" href="#FCN">FCN</a>, <a class="arg" href="#TOL">TOL</a>, <a class="arg" href="#RELABS">RELABS</a>, <a class="arg" href="#OUTPUT">OUTPUT</a>, <a class="arg" href="#G">G</a>, <a class="arg" href="#W">W</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">X, XEND, Y(N), TOL, G, W(20*N)</td></tr><tr><td class="tdfspec1">CHARACTER*1</td><td class="tdfspec2">RELABS</td></tr><tr><td class="tdfspec1">EXTERNAL</td><td class="tdfspec2">FCN, OUTPUT, G</td></tr></table><h2 class="standard"><a class="sec" name="description" id="description"/>3&#160;&#160;Description</h2>
<div class="paramtext">D02BJF advances the solution of a system of ordinary differential equations

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:msubsup><m:mi>y</m:mi><m:mi>i</m:mi><m:mo>&#8242;</m:mo></m:msubsup><m:mo>=</m:mo><m:msub><m:mi>f</m:mi><m:mi>i</m:mi></m:msub><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mn>2</m:mn></m:msub><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mi mathvariant="italic">n</m:mi></m:msub></m:mfenced><m:mtext>, &#8195;</m:mtext><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 mathvariant="italic">n</m:mi><m:mtext>,</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

from <m:math><m:mi>x</m:mi><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction></m:math>&#160;to <m:math><m:mi>x</m:mi><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#XEND"><m:mi mathcolor="#EE0000" mathvariant="bold">XEND</m:mi></m:maction></m:math>&#160;using a fixed order Runge&#8211;Kutta method.  The system is defined by <a class="arg" href="#FCN">FCN</a>, which evaluates <m:math><m:msub><m:mi>f</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;in terms of <m:math><m:mi>x</m:mi></m:math>&#160;and <m:math><m:mi>y</m:mi><m:mo>=</m:mo><m:mfenced separators=""><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mn>2</m:mn></m:msub><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mi mathvariant="italic">n</m:mi></m:msub></m:mfenced></m:math>.  The initial values of <m:math><m:mi>y</m:mi><m:mo>=</m:mo><m:mfenced separators=""><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mn>2</m:mn></m:msub><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mi mathvariant="italic">n</m:mi></m:msub></m:mfenced></m:math>&#160;must be given at <m:math><m:mi>x</m:mi><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction></m:math>.</div><div class="paramtext">The solution is returned via the <a class="arg" href="#OUTPUT">OUTPUT</a> supplied by you and at points specified by you, if desired: this solution is obtained by <m:math><m:msup><m:mi>C</m:mi><m:mn>1</m:mn></m:msup></m:math>&#160;interpolation on solution values produced by the method.  As the integration proceeds a check can be made on the user-specified function <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced></m:math>&#160;to determine an interval where it changes sign.  The position of this sign change is then determined accurately by <m:math><m:msup><m:mi>C</m:mi><m:mn>1</m:mn></m:msup></m:math>&#160;interpolation to the solution.  It is assumed that <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced></m:math>&#160;is a continuous function of the variables, so that a solution of <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced><m:mo>=</m:mo><m:mn>0</m:mn></m:math>&#160;can be determined by searching for a change in sign in <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced></m:math>.  The accuracy of the integration, the interpolation and, indirectly, of the determination of the position where <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced><m:mo>=</m:mo><m:mn>0</m:mn></m:math>, is controlled by the parameters <a class="arg" href="#TOL">TOL</a> and <a class="arg" href="#RELABS">RELABS</a>.</div><h2 class="standard"><a class="sec" name="references" id="references"/>4&#160;&#160;References</h2><div class="paramtext"><a name="ref641" id="ref641"/>Shampine L F (1994)  <i>Numerical solution of ordinary differential equations</i> Chapman and Hall </div><h2 class="standard"><a class="sec" name="parameters" id="parameters"/>5&#160;&#160;Parameters</h2>
<dl><dt class="paramhead"><a name="X" id="X"/>1: &#160;&#160;&#8194; X &#8211; <span class="bitalic">double precision</span><span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the initial value of the independent variable <m:math><m:mi>x</m:mi></m:math>.</div>
<div class="paramtext"><i>On exit</i>: if <m:math><m:mi>g</m:mi></m:math>&#160;is supplied by you, it contains the point where <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced><m:mo>=</m:mo><m:mn>0</m:mn></m:math>, unless <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced><m:mo>&#8800;</m:mo><m:mn>0</m:mn></m:math>&#160;anywhere on the range <a class="arg" href="#X">X</a> to <a class="arg" href="#XEND">XEND</a>, in which case, <a class="arg" href="#X">X</a> will contain <a class="arg" href="#XEND">XEND</a> (and the error indicator <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="#IFeq6"><m:mn mathcolor="#003399" mathvariant="bold">6</m:mn></m:maction></m:math>&#160;is set); if <m:math><m:mi>g</m:mi></m:math>&#160;is not supplied by you it contains <a class="arg" href="#XEND">XEND</a>. However, if an error has occurred, it contains the value of <m:math><m:mi>x</m:mi></m:math>&#160;at which the error occurred.</div></dd><dt class="paramhead"><a name="XEND" id="XEND"/>2: &#160;&#160;&#8194; XEND &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the final value of the independent variable. If <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#XEND"><m:mi mathcolor="#EE0000" mathvariant="bold">XEND</m:mi></m:maction><m:mo>&lt;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction></m:math>, integration will proceed in the negative direction.</div>
<div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#XEND"><m:mi mathcolor="#EE0000" mathvariant="bold">XEND</m:mi></m:maction><m:mo>&#8800;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction></m:math>.
</div></dd><dt class="paramhead"><a name="N" id="N"/>3: &#160;&#160;&#8194; N &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: 

<m:math><m:mi mathvariant="italic">n</m:mi></m:math>, the number of equations.</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>&gt;</m:mo><m:mn>0</m:mn></m:math>.
</div>
</dd><dt class="paramhead"><a name="Y" id="Y"/>4: &#160;&#160;&#8194; Y(<a class="arg" href="#N">N</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the initial values of the solution <m:math><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mn>2</m:mn></m:msub><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mi mathvariant="italic">n</m:mi></m:msub></m:math>&#160;at <m:math><m:mi>x</m:mi><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction></m:math>.</div><div class="paramtext"><i>On exit</i>: the computed values of the solution at the final point <m:math><m:mi>x</m:mi><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction></m:math>.</div></dd><dt class="paramhead"><a name="FCN" id="FCN"/>5: &#160;&#160;&#8194; FCN &#8211; SUBROUTINE, supplied by the user.<span class="pclass">External Procedure</span></dt><dd>
<div class="paramtext"><a class="arg" href="#FCN">FCN</a> must evaluate the functions <m:math><m:msub><m:mi>f</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;(i.e., the derivatives <m:math><m:msubsup><m:mi>y</m:mi><m:mi>i</m:mi><m:mo>&#8242;</m:mo></m:msubsup></m:math>) for given values of its arguments <m:math><m:mi>x</m:mi><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mi mathvariant="italic">n</m:mi></m:msub></m:math>.</div><div class="subprog">
<div class="paramtext">The specification of <a class="arg" href="#FCN">FCN</a> is:</div><table class="fspec"><tr><td class="tdfspec1">SUBROUTINE&#160;FCN&#160;(</td><td class="tdfspec2"><a class="arg" href="../D02/d02bjf.xml#FCN_X">X</a>, <a class="arg" href="../D02/d02bjf.xml#FCN_Y">Y</a>, <a class="arg" href="../D02/d02bjf.xml#FCN_F">F</a>)</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">X, Y(*), F(*)</td></tr></table><dl><dt class="paramhead"><a name="FCN_X" id="FCN_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>: <m:math><m:mi>x</m:mi></m:math>, the value of the independent variable.</div></dd><dt class="paramhead"><a name="FCN_Y" id="FCN_Y"/>2: &#160;&#160;&#8194; Y(<m:math><m:mo>*</m:mo></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><b>Note:</b> the dimension of the array <a class="arg" href="../D02/d02bjf.xml#FCN_Y">Y</a>
is
<m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:math>.</div><div class="paramtext"><i>On entry</i>: <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>, the value of the variable, 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 mathvariant="italic">n</m:mi></m:math>.</div></dd><dt class="paramhead"><a name="FCN_F" id="FCN_F"/>3: &#160;&#160;&#8194; F(<m:math><m:mo>*</m:mo></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Output</span></dt><dd>
<div class="paramtext"><b>Note:</b> the dimension of the array <a class="arg" href="../D02/d02bjf.xml#FCN_F">F</a>
is
<m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:math>.</div>
<div class="paramtext"><i>On exit</i>: the value of <m:math><m:msub><m:mi>f</m:mi><m:mi>i</m:mi></m:msub></m:math>, 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 mathvariant="italic">n</m:mi></m:math>.</div></dd></dl>
</div>
<div class="paramtext"><a class="arg" href="#FCN">FCN</a> must be declared as EXTERNAL in the (sub)program from which D02BJF 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="TOL" id="TOL"/>6: &#160;&#160;&#8194; TOL &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: a <b>positive</b> tolerance for controlling the error in the integration. Hence <a class="arg" href="#TOL">TOL</a> affects the determination of the position where <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced><m:mo>=</m:mo><m:mn>0</m:mn></m:math>, if <m:math><m:mi>g</m:mi></m:math>&#160;is supplied.
<div class="paramtext">D02BJF has been designed so that, for most problems, a reduction in <a class="arg" href="#TOL">TOL</a> leads to an approximately proportional reduction in the error in the solution. However, the actual relation between <a class="arg" href="#TOL">TOL</a> and the accuracy achieved cannot be guaranteed. You are strongly recommended to call D02BJF with more than one value for <a class="arg" href="#TOL">TOL</a> and to compare the results obtained to estimate their accuracy. In the absence of any prior knowledge, you might compare the results obtained by calling D02BJF with <a class="arg" href="#RELABS">RELABS</a> set to 'D' and with each of <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#TOL"><m:mi mathcolor="#EE0000" mathvariant="bold">TOL</m:mi></m:maction><m:mo>=</m:mo><m:msup><m:mn>10.0</m:mn><m:mrow><m:mo>-</m:mo><m:mi>p</m:mi></m:mrow></m:msup></m:math>&#160;and <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#TOL"><m:mi mathcolor="#EE0000" mathvariant="bold">TOL</m:mi></m:maction><m:mo>=</m:mo><m:msup><m:mn>10.0</m:mn><m:mrow><m:mo>-</m:mo><m:mi>p</m:mi><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:msup></m:math>&#160;where <m:math><m:mi>p</m:mi></m:math>&#160;correct significant digits are required in the solution, <m:math><m:mi>y</m:mi></m:math>. The accuracy of the value <m:math><m:mi>x</m:mi></m:math>&#160;such that <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced><m:mo>=</m:mo><m:mn>0</m:mn></m:math>&#160;is indirectly controlled by varying <a class="arg" href="#TOL">TOL</a>. You should experiment to determine this accuracy.</div>
</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:mn>10.0</m:mn><m:mo>&#215;</m:mo><m:mi mathvariant="bold-italic">machine&#160;precision</m:mi><m:mo>&lt;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#TOL"><m:mi mathcolor="#EE0000" mathvariant="bold">TOL</m:mi></m:maction><m:mo>&lt;</m:mo><m:mn>0.01</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="RELABS" id="RELABS"/>7: &#160;&#160;&#8194; RELABS &#8211; CHARACTER*1<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the type of error control. At each step in the numerical solution an estimate of the local error, <m:math><m:mi mathvariant="italic">est</m:mi></m:math>, is made. For the current step to be accepted the following condition must be satisfied: 
<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block"> <m:mi mathvariant="italic">est</m:mi> <m:mo>=</m:mo><m:mrow><m:mi>max</m:mi><m:mspace width="0.125em"/><m:mfenced separators=""><m:msub><m:mi>e</m:mi><m:mi>i</m:mi></m:msub><m:mo>/</m:mo><m:mfenced separators=""> <m:msub><m:mi>&#964;</m:mi><m:mi>r</m:mi></m:msub> <m:mo>&#215;</m:mo> <m:mrow><m:mi>max</m:mi><m:mspace width="0.125em"/><m:mfenced separators=""><m:mfenced open="|" close="|" separators=""><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:mfenced><m:mo>,</m:mo><m:msub><m:mi>&#964;</m:mi><m:mi>a</m:mi></m:msub></m:mfenced></m:mrow> </m:mfenced></m:mfenced></m:mrow> <m:mo>&#8804;</m:mo> <m:mn>1.0</m:mn> </m:math></td><td class="formula2"/></tr></table></div>
 where <m:math><m:msub><m:mi>&#964;</m:mi><m:mi>r</m:mi></m:msub></m:math>&#160;and <m:math><m:msub><m:mi>&#964;</m:mi><m:mi>a</m:mi></m:msub></m:math>&#160;are defined by <div class="tablediv"><table class="frame-none">    <tbody> <tr> <td class="libdoc" valign="top" align="center"><a class="arg" href="#RELABS">RELABS</a></td> <td class="libdoc" valign="top" align="center"><m:math><m:msub><m:mi>&#964;</m:mi><m:mi>r</m:mi></m:msub></m:math></td> <td class="libdoc" valign="top" align="center"><m:math><m:msub><m:mi>&#964;</m:mi><m:mi>a</m:mi></m:msub></m:math></td> </tr><tr> <td class="libdoc" valign="top" align="center">'M'</td> <td class="libdoc" valign="top" align="left"><a class="arg" href="#TOL">TOL</a></td> <td class="libdoc" valign="top" align="left">1.0</td> </tr><tr> <td class="libdoc" valign="top" align="center">'A'</td> <td class="libdoc" valign="top" align="left"><m:math><m:msub><m:mi>&#949;</m:mi><m:mi>r</m:mi></m:msub></m:math></td> <td class="libdoc" valign="top" align="left"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#TOL"><m:mi mathcolor="#EE0000" mathvariant="bold">TOL</m:mi></m:maction><m:mo>/</m:mo><m:msub><m:mi>&#949;</m:mi><m:mi>r</m:mi></m:msub></m:math></td> </tr><tr> <td class="libdoc" valign="top" align="center">'R'</td> <td class="libdoc" valign="top" align="left"><a class="arg" href="#TOL">TOL</a></td> <td class="libdoc" valign="top" align="left"><m:math><m:msub><m:mi>&#949;</m:mi><m:mi>a</m:mi></m:msub></m:math></td> </tr><tr> <td class="libdoc" valign="top" align="center">'D'</td> <td class="libdoc" valign="top" align="left"><a class="arg" href="#TOL">TOL</a></td> <td class="libdoc" valign="top" align="left"><m:math><m:msub><m:mi>&#949;</m:mi><m:mi>a</m:mi></m:msub></m:math></td> </tr> </tbody> </table></div> where <m:math><m:msub><m:mi>&#949;</m:mi><m:mi>r</m:mi></m:msub></m:math>&#160;and <m:math><m:msub><m:mi>&#949;</m:mi><m:mi>a</m:mi></m:msub></m:math>&#160;are small machine-dependent numbers and <m:math><m:msub><m:mi>e</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;is an estimate of the local error at <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>, computed internally. If the condition is not satisfied, the step size is reduced and the solution is recomputed on the current step. If you wish to measure the error in the computed solution in terms of the number of correct decimal places, then <a class="arg" href="#RELABS">RELABS</a> should be set to 'A' on entry, whereas if the error requirement is in terms of the number of correct significant digits, then <a class="arg" href="#RELABS">RELABS</a> should be set to 'R'. If you prefer a mixed error test, then <a class="arg" href="#RELABS">RELABS</a> should be set to 'M', otherwise if you have no preference, <a class="arg" href="#RELABS">RELABS</a> should be set to the default 'D'. Note that in this case 'D' is taken to be 'R'.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#RELABS"><m:mi mathcolor="#EE0000" mathvariant="bold">RELABS</m:mi></m:maction><m:mo>=</m:mo><m:mtext>'M'</m:mtext></m:math>, <m:math><m:mtext>'A'</m:mtext></m:math>, <m:math><m:mtext>'R'</m:mtext></m:math>&#160;or <m:math><m:mtext>'D'</m:mtext></m:math>.
</div></dd><dt class="paramhead"><a name="OUTPUT" id="OUTPUT"/>8: &#160;&#160;&#8194; OUTPUT &#8211; SUBROUTINE, supplied by the NAG Library or the user.<span class="pclass">External Procedure</span></dt><dd>
<div class="paramtext"><a class="arg" href="#OUTPUT">OUTPUT</a> permits access to intermediate values of the computed solution (for example to print or plot them), at successive user-specified points. It is initially called by D02BJF with <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#OUTPUT_XSOL"><m:mi mathcolor="#EE0000" mathvariant="bold">XSOL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction></m:math>&#160;(the initial value of <m:math><m:mi>x</m:mi></m:math>). You must reset <a class="arg" href="../D02/d02bjf.xml#OUTPUT_XSOL">XSOL</a> to the next point (between the current <a class="arg" href="../D02/d02bjf.xml#OUTPUT_XSOL">XSOL</a> and <a class="arg" href="#XEND">XEND</a>) where <a class="arg" href="#OUTPUT">OUTPUT</a> is to be called, and so on at each call to <a class="arg" href="#OUTPUT">OUTPUT</a>. If, after a call to <a class="arg" href="#OUTPUT">OUTPUT</a>, the reset point <a class="arg" href="../D02/d02bjf.xml#OUTPUT_XSOL">XSOL</a> is beyond <a class="arg" href="#XEND">XEND</a>, D02BJF will integrate to <a class="arg" href="#XEND">XEND</a> with no further calls to <a class="arg" href="#OUTPUT">OUTPUT</a>; if a call to <a class="arg" href="#OUTPUT">OUTPUT</a> is required at the point <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#OUTPUT_XSOL"><m:mi mathcolor="#EE0000" mathvariant="bold">XSOL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#XEND"><m:mi mathcolor="#EE0000" mathvariant="bold">XEND</m:mi></m:maction></m:math>, then <a class="arg" href="../D02/d02bjf.xml#OUTPUT_XSOL">XSOL</a> must be given precisely the value <a class="arg" href="#XEND">XEND</a>.</div><div class="subprog">
<div class="paramtext">The specification of <a class="arg" href="#OUTPUT">OUTPUT</a> is:</div><table class="fspec"><tr><td class="tdfspec1">SUBROUTINE&#160;OUTPUT&#160;(</td><td class="tdfspec2"><a class="arg" href="../D02/d02bjf.xml#OUTPUT_XSOL">XSOL</a>, <a class="arg" href="../D02/d02bjf.xml#OUTPUT_Y">Y</a>)</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">XSOL, Y(*)</td></tr></table><dl><dt class="paramhead"><a name="OUTPUT_XSOL" id="OUTPUT_XSOL"/>1: &#160;&#160;&#8194; XSOL &#8211; <span class="bitalic">double precision</span><span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the output value of the independent variable <m:math><m:mi>x</m:mi></m:math>.</div>
<div class="paramtext"><i>On exit</i>: you must set <a class="arg" href="../D02/d02bjf.xml#OUTPUT_XSOL">XSOL</a> to the next value of <m:math><m:mi>x</m:mi></m:math>&#160;at which <a class="arg" href="#OUTPUT">OUTPUT</a> is to be called.</div></dd><dt class="paramhead"><a name="OUTPUT_Y" id="OUTPUT_Y"/>2: &#160;&#160;&#8194; Y(<m:math><m:mo>*</m:mo></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd><div class="paramtext"><b>Note:</b> the dimension of the array <a class="arg" href="../D02/d02bjf.xml#OUTPUT_Y">Y</a>
is
<m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:math>.</div><div class="paramtext"><i>On entry</i>: the computed solution at the point <a class="arg" href="../D02/d02bjf.xml#OUTPUT_XSOL">XSOL</a>.</div></dd></dl>
</div>
<div class="paramtext"><a class="arg" href="#OUTPUT">OUTPUT</a> must be declared as EXTERNAL in the (sub)program from which D02BJF is called. Parameters denoted as <span class="italic">Input</span>  must <b>not</b>  be changed by this procedure.</div>
<div class="paramtext">If you do not wish to access intermediate output, the actual parameter <a class="arg" href="#OUTPUT">OUTPUT</a>
<b>must</b> be the dummy routine D02BJX.  D02BJX is included in the NAG Library.</div>
</dd><dt class="paramhead"><a name="G" id="G"/>9: &#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 evaluate the function <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced></m:math>&#160;for specified values <m:math><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:math>. It specifies the function <m:math><m:mi>g</m:mi></m:math>&#160;for which the first position <m:math><m:mi>x</m:mi></m:math>&#160;where <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced><m:mo>=</m:mo><m:mn>0</m:mn></m:math>&#160;is to be found.</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="../D02/d02bjf.xml#G_X">X</a>, <a class="arg" href="../D02/d02bjf.xml#G_Y">Y</a>)</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">X, Y(*)</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>: <m:math><m:mi>x</m:mi></m:math>, the value of the independent variable.</div></dd><dt class="paramhead"><a name="G_Y" id="G_Y"/>2: &#160;&#160;&#8194; Y(<m:math><m:mo>*</m:mo></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><b>Note:</b> the dimension of the array <a class="arg" href="../D02/d02bjf.xml#G_Y">Y</a>
is
<m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:math>.</div><div class="paramtext"><i>On entry</i>: <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>, the value of the variable, 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 mathvariant="italic">n</m:mi></m:math>.</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 D02BJF is called. Parameters denoted as <span class="italic">Input</span>  must <b>not</b>  be changed by this procedure.</div>
<div class="paramtext">
<div class="paramtext">If you do not require the root-finding option, the actual parameter <a class="arg" href="#G">G</a> <b>must</b> be the dummy routine D02BJW.  (D02BJW is included in the NAG Library.)</div>
</div>
</dd><dt class="paramhead"><a name="W" id="W"/>10: &#8194; W(<m:math><m:mn>20</m:mn><m:mo>&#215;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Workspace</span></dt><dt class="paramhead"><a name="IFAIL" id="IFAIL"/>11: &#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, if you are not familiar with this parameter, the recommended value is <m:math><m:mn>0</m:mn></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 mathvariant="bold">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">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>
<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="#TOL"><m:mi mathcolor="#EE0000" mathvariant="bold">TOL</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>0.01</m:mn></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><a class="arg" href="#TOL">TOL</a> is too small</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><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>&#8804;</m:mo><m:mn>0</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="#RELABS"><m:mi mathcolor="#EE0000" mathvariant="bold">RELABS</m:mi></m:maction><m:mo>&#8800;</m:mo><m:mtext>'M'</m:mtext></m:math>, <m:math><m:mtext>'A'</m:mtext></m:math>, <m:math><m:mtext>'R'</m:mtext></m:math>&#160;or <m:math><m:mtext>'D'</m:mtext></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="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#XEND"><m:mi mathcolor="#EE0000" mathvariant="bold">XEND</m:mi></m:maction></m:math>.</td></tr></table>
</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">With the given value of <a class="arg" href="#TOL">TOL</a>, no further progress can be made across the integration range from the current point <m:math><m:mi>x</m:mi><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction></m:math>.  (See <a class="sec" href="#fcomments">Section 8</a> for a discussion of this error exit.)  The components <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#Y"><m:mi mathcolor="#EE0000" mathvariant="bold">Y</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>1</m:mn></m:mfenced></m:mrow><m:mo>,</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#Y"><m:mi mathcolor="#EE0000" mathvariant="bold">Y</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>2</m:mn></m:mfenced></m:mrow><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#Y"><m:mi mathcolor="#EE0000" mathvariant="bold">Y</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:mfenced></m:mrow></m:math>&#160;contain the computed values of the solution at the current point <m:math><m:mi>x</m:mi><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction></m:math>.  If you have supplied <m:math><m:mi>g</m:mi></m:math>, then no point at which <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced></m:math>&#160;changes sign has been located up to the point <m:math><m:mi>x</m:mi><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction></m:math>.</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"><a class="arg" href="#TOL">TOL</a> is too small for D02BJF to take an initial step.  <a class="arg" href="#X">X</a> and <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#Y"><m:mi mathcolor="#EE0000" mathvariant="bold">Y</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>1</m:mn></m:mfenced></m:mrow><m:mo>,</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#Y"><m:mi mathcolor="#EE0000" mathvariant="bold">Y</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>2</m:mn></m:mfenced></m:mrow><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#Y"><m:mi mathcolor="#EE0000" mathvariant="bold">Y</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:mfenced></m:mrow></m:math>&#160;retain their initial values.</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>
<div class="paramtext"><a class="arg" href="../D02/d02bjf.xml#OUTPUT_XSOL">XSOL</a> has not been reset or <a class="arg" href="../D02/d02bjf.xml#OUTPUT_XSOL">XSOL</a> lies behind <a class="arg" href="#X">X</a> in the direction of integration, after the initial call to <a class="arg" href="#OUTPUT">OUTPUT</a>, if the <a class="arg" href="#OUTPUT">OUTPUT</a> option was selected.</div>
</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>
<div class="paramtext">A value of <a class="arg" href="../D02/d02bjf.xml#OUTPUT_XSOL">XSOL</a> returned by the <a class="arg" href="#OUTPUT">OUTPUT</a> has not been reset or lies behind the last value of <a class="arg" href="../D02/d02bjf.xml#OUTPUT_XSOL">XSOL</a> in the direction of integration, if the <a class="arg" href="#OUTPUT">OUTPUT</a> option was selected.</div>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq6" id="IFeq6"/><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>6</m:mn></m:math></dt>
<dd>
<div class="paramtext">At no point in the range <a class="arg" href="#X">X</a> to <a class="arg" href="#XEND">XEND</a> did the function <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced></m:math>&#160;change sign, if <m:math><m:mi>g</m:mi></m:math>&#160;was supplied.  It is assumed that <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced><m:mo>=</m:mo><m:mn>0</m:mn></m:math>&#160;has no solution.</div>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq7" id="IFeq7"/><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>7</m:mn></m:math></dt>
<dd>
<div class="paramtext">A serious error has occurred in an internal call to an interpolation routine. Check all (sub)program calls and array dimensions. Seek expert help.</div></dd>
</dl><h2 class="standard"><a class="sec" name="accuracy" id="accuracy"/>7&#160;&#160;Accuracy</h2>
<div class="paramtext">The accuracy of the computation of the solution vector <a class="arg" href="#Y">Y</a> may be controlled by varying the local error tolerance <a class="arg" href="#TOL">TOL</a>.  In general, a decrease in local error tolerance should lead to an increase in accuracy.  You are advised to choose <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#RELABS"><m:mi mathcolor="#EE0000" mathvariant="bold">RELABS</m:mi></m:maction><m:mo>=</m:mo><m:mtext>'D'</m:mtext></m:math>&#160;unless you have a good reason for a different choice.</div><div class="paramtext">If the problem is a root-finding one, then the accuracy of the root determined will depend on the properties of <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced></m:math>&#160;and on the values of <a class="arg" href="#TOL">TOL</a> and <a class="arg" href="#RELABS">RELABS</a>.  You should try to code <a class="arg" href="#G">G</a> without introducing any unnecessary cancellation errors.</div><h2 class="standard"><a class="sec" name="fcomments" id="fcomments"/>8&#160;&#160;Further Comments</h2>
<div class="paramtext">If more than one root is required, then to determine the second and later roots D02BJF may be called again starting a short distance past the previously determined roots.  Alternatively you may construct your own root-finding code using <a class="rout" href="../C05/c05azf.xml">C05AZF</a>, <a class="rout" href="../D02/d02pdf.xml">D02PDF</a> and <a class="rout" href="../D02/d02pxf.xml">D02PXF</a>.</div><div class="paramtext">If D02BJF fails with <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="#IFeq3"><m:mn mathcolor="#003399" mathvariant="bold">3</m:mn></m:maction></m:math>, then it can be called again with a larger value of <a class="arg" href="#TOL">TOL</a> if this has not already been tried.  If the accuracy requested is really needed and cannot be obtained with this routine,  the system may be very stiff (see below) or so badly scaled that it cannot be solved to the required accuracy.</div><div class="paramtext">If D02BJF fails with <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="#IFeq2"><m:mn mathcolor="#003399" mathvariant="bold">2</m:mn></m:maction></m:math>, it is probable that it has been called with a value of <a class="arg" href="#TOL">TOL</a> which is so small that a solution cannot be obtained on the range <a class="arg" href="#X">X</a> to <a class="arg" href="#XEND">XEND</a>.  This can happen for well-behaved systems and very small values of <a class="arg" href="#TOL">TOL</a>.  You should, however, consider whether there is a more fundamental difficulty.  For example:
<table class="standard-100"><tr>
<td style="width:2.1em;" valign="baseline">(a)</td>
<td valign="top">in the region of a singularity (infinite value) of the solution, the routine will usually stop with <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="#IFeq2"><m:mn mathcolor="#003399" mathvariant="bold">2</m:mn></m:maction></m:math>, unless overflow occurs first.  Numerical integration cannot be continued through a singularity, and analytic treatment should be considered;</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline">(b)</td>
<td valign="top">for &#8216;stiff&#8217; equations where the solution contains rapidly decaying components, the routine will use very small steps in <m:math><m:mi>x</m:mi></m:math>&#160;(internally to D02BJF) to preserve stability.  This will exhibit itself by making the computing time excessively long, or occasionally by an exit with <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="#IFeq2"><m:mn mathcolor="#003399" mathvariant="bold">2</m:mn></m:maction></m:math>.  Runge&#8211;Kutta methods are not efficient in such cases, and you should try <a class="rout" href="../D02/d02ejf.xml">D02EJF</a>.</td>
</tr></table>
</div><h2 class="standard"><a class="sec" name="example" id="example"/>9&#160;&#160;Example</h2>
<div class="paramtext">This example illustrates the solution of four different problems.  In each case the differential system (for a projectile) is

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mtable columnalign="left">
 <m:mtr>
  <m:mtd><m:msup><m:mi>y</m:mi><m:mo>&#8242;</m:mo></m:msup><m:mo>=</m:mo><m:mrow><m:mi>tan</m:mi><m:mo>&#8289;</m:mo><m:mi>&#981;</m:mi></m:mrow></m:mtd>
 </m:mtr><m:mtr>
  <m:mtd/>
  <m:mtd/>
  <m:mtd/></m:mtr><m:mtr>
  <m:mtd><m:msup><m:mi>v</m:mi><m:mo>&#8242;</m:mo></m:msup><m:mo>=</m:mo><m:mfrac other="display">
  <m:mrow><m:mo>-</m:mo><m:mn>0.032</m:mn><m:mrow><m:mi>tan</m:mi><m:mo>&#8289;</m:mo><m:mi>&#981;</m:mi></m:mrow></m:mrow><m:mi>v</m:mi></m:mfrac><m:mo>-</m:mo><m:mfrac other="display">
  <m:mrow><m:mn>0.02</m:mn><m:mi>v</m:mi></m:mrow>
  <m:mrow><m:mi>cos</m:mi><m:mo>&#8289;</m:mo><m:mi>&#981;</m:mi></m:mrow>
 </m:mfrac></m:mtd>
 </m:mtr><m:mtr>
  <m:mtd/>
  <m:mtd/>
  <m:mtd/></m:mtr><m:mtr>
  <m:mtd><m:msup><m:mi>&#981;</m:mi><m:mo>&#8242;</m:mo></m:msup><m:mo>=</m:mo><m:mfrac other="display">
  <m:mrow><m:mo>-</m:mo><m:mn>0.032</m:mn></m:mrow><m:msup><m:mi>v</m:mi><m:mn>2</m:mn></m:msup></m:mfrac></m:mtd>
 </m:mtr>
</m:mtable>
</m:math></td><td class="formula2"/></tr></table></div>

over an interval <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>&#160;to <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#XEND"><m:mi mathcolor="#EE0000" mathvariant="bold">XEND</m:mi></m:maction><m:mo>=</m:mo><m:mn>10.0</m:mn></m:math>&#160;starting with values <m:math><m:mi>y</m:mi><m:mo>=</m:mo><m:mn>0.5</m:mn></m:math>,  <m:math><m:mi>v</m:mi><m:mo>=</m:mo><m:mn>0.5</m:mn></m:math>&#160;and <m:math><m:mi>&#981;</m:mi><m:mo>=</m:mo><m:mi>&#960;</m:mi><m:mo>/</m:mo><m:mn>5</m:mn></m:math>.  We solve each of the following problems with local error tolerances <m:math><m:mtext>1.0D&#8722;4</m:mtext></m:math>&#160;and <m:math><m:mtext>1.0D&#8722;5</m:mtext></m:math>.
<table class="standard-100"><tr>
<td style="width:2.1em;" valign="baseline"><a name="item1" id="item1"/>(i)</td>
<td valign="top">To integrate to <m:math><m:mi>x</m:mi><m:mo>=</m:mo><m:mn>10.0</m:mn></m:math>&#160;producing intermediate output at intervals of <m:math><m:mn>2.0</m:mn></m:math>&#160;until a root is encountered where <m:math><m:mi>y</m:mi><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>.</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline"><a name="item2" id="item2"/>(ii)</td>
<td valign="top">As <a class="item" href="#item1">(i)</a> but with no intermediate output.</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline"><a name="item3" id="item3"/>(iii)</td>
<td valign="top">As <a class="item" href="#item1">(i)</a> but with no termination on a root-finding condition.</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline"><a name="item4" id="item4"/>(iv)</td>
<td valign="top">As <a class="item" href="#item1">(i)</a> but with no intermediate output and no root-finding termination condition.</td>
</tr></table>
</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/d02bjfe.f">Program Text (d02bjfe.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/d02bjfe.r">Program Results (d02bjfe.r)</a></p><div class="figure"><a name="d02bjf-plot" id="d02bjf-plot"/><img src="../figures/d02bjf-plot.png" alt="Example Program Plot for d02bjf-plot"/></div>
<hr/><div><a class="rout" href="../../pdf/D02/d02bjf.pdf">D02BJF (PDF version)</a></div><div><a class="chap" href="d02conts.xml">D02 Chapter Contents</a></div><div><a class="chapint" href="d02intro.xml">D02 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>
