<?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>D02BHF : 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/d02bhf.pdf">D02BHF (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/>D02BHF</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">D02BHF integrates a system of first-order ordinary differential equations over an interval with suitable initial conditions, using a Runge&#8211;Kutta&#8211;Merson method, until a user-specified function of the solution is zero.</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;D02BHF&#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="#TOL">TOL</a>, <a class="arg" href="#IRELAB">IRELAB</a>, <a class="arg" href="#HMAX">HMAX</a>, <a class="arg" href="#FCN">FCN</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, IRELAB, IFAIL</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">X, XEND, Y(N), TOL, HMAX, G, W(N,7)</td></tr><tr><td class="tdfspec1">EXTERNAL</td><td class="tdfspec2">FCN, G</td></tr></table><h2 class="standard"><a class="sec" name="description" id="description"/>3&#160;&#160;Description</h2>
<div class="paramtext">D02BHF 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;towards <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 Merson form of the 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: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;(see <a class="sec" href="#parameters">Section 5</a>), and the values of <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;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">As the integration proceeds, a check is made on 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;specified by you, to determine an interval where it changes sign.  The position of this sign change is then determined accurately by interpolating for the solution and its derivative.  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>.</div><div class="paramtext">The accuracy of the integration 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 <a class="arg" href="#TOL">TOL</a>.</div><div class="paramtext">For a description of Runge&#8211;Kutta methods and their practical implementation see <a class="ref" href="#ref024">Hall and Watt (1976)</a>.</div><h2 class="standard"><a class="sec" name="references" id="references"/>4&#160;&#160;References</h2><div class="paramtext"><a name="ref024" id="ref024"/>Hall G and Watt J M (ed.) (1976)  <i>Modern Numerical Methods for Ordinary Differential Equations</i> Clarendon Press, Oxford </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>: must be set to the initial value of the independent variable <m:math><m:mi>x</m:mi></m:math>.</div>
<div class="paramtext"><i>On exit</i>: 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.0</m:mn></m:math>&#160;unless an error has occurred, when it contains the value of <m:math><m:mi>x</m:mi></m:math>&#160;at the error. In particular, if <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.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>, it will contain <a class="arg" href="#XEND">XEND</a> on exit.</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 <m:math><m:mi>x</m:mi></m:math>.
<div class="paramtext">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>&#160;on entry, integration proceeds in a negative direction.</div>
</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 differential 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>.</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="TOL" id="TOL"/>5: &#160;&#160;&#8194; TOL &#8211; <span class="bitalic">double precision</span><span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On entry</i>: must be set to a <b>positive</b> tolerance for controlling the error in the integration and in 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.0</m:mn></m:math>.
<div class="paramtext">D02BHF 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 obtained in the integration. The relation between changes in <a class="arg" href="#TOL">TOL</a> and the error in 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.0</m:mn></m:math>&#160;is less clear, but for <a class="arg" href="#TOL">TOL</a> small enough the error should be approximately proportional to <a class="arg" href="#TOL">TOL</a>. However, the actual relation between <a class="arg" href="#TOL">TOL</a> and the accuracy cannot be guaranteed. You are strongly recommended to call D02BHF 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 results obtained by calling D02BHF with <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;if <m:math><m:mi>p</m:mi></m:math>&#160;correct decimal digits in the solution are required.</div>
</div><div class="paramtext"><i>Constraint</i>:
  <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>&gt;</m:mo><m:mn>0.0</m:mn></m:math>.
</div>
<div class="paramtext"><i>On exit</i>: normally unchanged. However if the range 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 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.0</m:mn></m:math>&#160;(or to the final value of <m:math><m:mi>x</m:mi></m:math>&#160;if an error occurs) is so short that a small change in <a class="arg" href="#TOL">TOL</a> is unlikely to make any change in the computed solution, then <a class="arg" href="#TOL">TOL</a> is returned with its sign changed. To check results returned with <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>&lt;</m:mo><m:mn>0.0</m:mn></m:math>, D02BHF should be called again with a positive value of <a class="arg" href="#TOL">TOL</a> whose magnitude is considerably smaller than that of the previous call.</div></dd><dt class="paramhead"><a name="IRELAB" id="IRELAB"/>6: &#160;&#160;&#8194; IRELAB &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: determines 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: 
<dl>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IRELAB"><m:mi mathcolor="#EE0000" mathvariant="bold">IRELAB</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn></m:math></dt>
<dd><m:math><m:mi mathvariant="italic">est</m:mi><m:mo>&#8804;</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>&#215;</m:mo><m:mrow><m:mi>max</m:mi><m:mspace width="0.125em"/><m:mfenced open="{" close="}" separators=""><m:mn>1.0</m:mn><m:mo>,</m:mo><m:mfenced open="|" close="|" separators=""><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub></m:mfenced><m:mo>,</m:mo><m:mfenced open="|" close="|" separators=""><m:msub><m:mi>y</m:mi><m:mn>2</m:mn></m:msub></m:mfenced><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mfenced open="|" close="|" separators=""><m:msub><m:mi>y</m:mi><m:mi mathvariant="italic">n</m:mi></m:msub></m:mfenced></m:mfenced></m:mrow></m:math>;</dd>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IRELAB"><m:mi mathcolor="#EE0000" mathvariant="bold">IRELAB</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math></dt>
<dd><m:math><m:mi mathvariant="italic">est</m:mi><m:mo>&#8804;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#TOL"><m:mi mathcolor="#EE0000" mathvariant="bold">TOL</m:mi></m:maction></m:math>;</dd>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IRELAB"><m:mi mathcolor="#EE0000" mathvariant="bold">IRELAB</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn></m:math></dt>
<dd><m:math><m:mi mathvariant="italic">est</m:mi><m:mo>&#8804;</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>&#215;</m:mo><m:mrow><m:mi>max</m:mi><m:mspace width="0.125em"/><m:mfenced open="{" close="}" separators=""><m:mi>&#949;</m:mi><m:mo>,</m:mo><m:mfenced open="|" close="|" separators=""><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub></m:mfenced><m:mo>,</m:mo><m:mfenced open="|" close="|" separators=""><m:msub><m:mi>y</m:mi><m:mn>2</m:mn></m:msub></m:mfenced><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mfenced open="|" close="|" separators=""><m:msub><m:mi>y</m:mi><m:mi mathvariant="italic">n</m:mi></m:msub></m:mfenced></m:mfenced></m:mrow></m:math>, where <m:math><m:mi>&#949;</m:mi></m:math>&#160;is <span class="bitalic">machine precision</span>.</dd></dl>
<div class="paramtext">If the appropriate condition is not satisfied, the step size is reduced and the solution recomputed on the current step.</div>
<div class="paramtext">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="#IRELAB">IRELAB</a> should be given the value <m:math><m:mn>1</m:mn></m:math>&#160;on entry, whereas if the error requirement is in terms of the number of correct significant digits, then <a class="arg" href="#IRELAB">IRELAB</a> should be given the value <m:math><m:mn>2</m:mn></m:math>. Where there is no preference in the choice of error test, <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IRELAB"><m:mi mathcolor="#EE0000" mathvariant="bold">IRELAB</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn></m:math>&#160;will result in a mixed error test. It should be borne in mind that the computed solution will be used in evaluating <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>.</div>
</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IRELAB"><m:mi mathcolor="#EE0000" mathvariant="bold">IRELAB</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn></m:math>, <m:math><m:mn>1</m:mn></m:math>&#160;or <m:math><m:mn>2</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="HMAX" id="HMAX"/>7: &#160;&#160;&#8194; HMAX &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: if <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#HMAX"><m:mi mathcolor="#EE0000" mathvariant="bold">HMAX</m:mi></m:maction><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>, no special action is taken.
<div class="paramtext">If <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#HMAX"><m:mi mathcolor="#EE0000" mathvariant="bold">HMAX</m:mi></m:maction><m:mo>&#8800;</m:mo><m:mn>0.0</m:mn></m:math>, a check is made for a change in sign 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;at steps not greater than <m:math><m:mfenced open="|" close="|" separators=""><m:maction actiontype="link" dsi:type="simple" dsi:href="#HMAX"><m:mi mathcolor="#EE0000" mathvariant="bold">HMAX</m:mi></m:maction></m:mfenced></m:math>. This facility should be used if there is any chance of &#8216;missing&#8217; the change in sign by checking too infrequently. For example, if two changes of sign 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;are expected within a distance <m:math><m:mi>h</m:mi></m:math>, say, of each other, then a suitable value for <a class="arg" href="#HMAX">HMAX</a> might be <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#HMAX"><m:mi mathcolor="#EE0000" mathvariant="bold">HMAX</m:mi></m:maction><m:mo>=</m:mo><m:mi>h</m:mi><m:mo>/</m:mo><m:mn>2</m:mn></m:math>. If only one change of 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>&#160;is expected on the range <a class="arg" href="#X">X</a> to <a class="arg" href="#XEND">XEND</a>, then the choice <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#HMAX"><m:mi mathcolor="#EE0000" mathvariant="bold">HMAX</m:mi></m:maction><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>&#160;is most appropriate.</div>
</div></dd><dt class="paramhead"><a name="FCN" id="FCN"/>8: &#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/d02bhf.xml#FCN_X">X</a>, <a class="arg" href="../D02/d02bhf.xml#FCN_Y">Y</a>, <a class="arg" href="../D02/d02bhf.xml#FCN_F">F</a>)</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">X, Y(<m:math><m:mi mathvariant="italic">n</m:mi></m:math>), F(<m:math><m:mi mathvariant="italic">n</m:mi></m:math>)</td></tr></table>
<div class="paramtext">where <m:math><m:mi mathvariant="italic">n</m:mi></m:math>&#160;is the value of <a class="arg" href="#N">N</a> in the call of D02BHF.</div>
<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 argument.</div></dd><dt class="paramhead"><a name="FCN_Y" id="FCN_Y"/>2: &#160;&#160;&#8194; Y(<m:math><m:mi mathvariant="italic">n</m:mi></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd>
<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 argument, 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:mi mathvariant="italic">n</m:mi></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Output</span></dt><dd><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 D02BHF 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="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;at a specified point.</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/d02bhf.xml#G_X">X</a>, <a class="arg" href="../D02/d02bhf.xml#G_Y">Y</a>)</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">X, Y(<m:math><m:mi mathvariant="italic">n</m:mi></m:math>)</td></tr></table>
<div class="paramtext">where <m:math><m:mi mathvariant="italic">n</m:mi></m:math>&#160;is the value of <a class="arg" href="#N">N</a> in the call of D02BHF.</div>
<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:mi mathvariant="italic">n</m:mi></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the value of <m:math><m:msub><m:mi>y</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="#G">G</a> must be declared as EXTERNAL in the (sub)program from which D02BHF 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="W" id="W"/>10: &#8194; W(<a class="arg" href="#N">N</a>,<m:math><m:mn>7</m:mn></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>&#8804;</m:mo><m:mn>0.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="#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="#IRELAB"><m:mi mathcolor="#EE0000" mathvariant="bold">IRELAB</m:mi></m:maction><m:mo>&#8800;</m:mo><m:mn>0</m:mn></m:math>, <m:math><m:mn>1</m:mn></m:math>&#160;or <m:math><m:mn>2</m:mn></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>, or dependence of the error on <a class="arg" href="#TOL">TOL</a> would be lost if further progress across the integration range were attempted (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:mi mathvariant="italic">n</m:mi></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>.  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 D02BHF to take an initial step (see <a class="sec" href="#fcomments">Section 8</a>).  <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:mi mathvariant="italic">n</m:mi></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">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. 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.0</m:mn></m:math>&#160;has no solution.</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>&#160;(<a class="rout" href="../C05/c05azf.xml">C05AZF</a>)</dt>
<dd>
<div class="paramtext">A serious error has occurred in an internal call to the specified routine.  Check all subroutine calls and array dimensions.  Seek expert help.</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">A serious error has occurred in an internal call to an integration routine.  Check all subroutine calls and array dimensions.  Seek expert help.</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 depends on <a class="arg" href="#TOL">TOL</a>, on the mathematical properties of the differential system, on 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.0</m:mn></m:math>&#160;and on the method.  It can be controlled by varying <a class="arg" href="#TOL">TOL</a> but the approximate proportionality of the error to <a class="arg" href="#TOL">TOL</a> holds only for a restricted range of values of <a class="arg" href="#TOL">TOL</a>.  For <a class="arg" href="#TOL">TOL</a> too large, the underlying theory may break down and the result of varying <a class="arg" href="#TOL">TOL</a> may be unpredictable.  For <a class="arg" href="#TOL">TOL</a> too small, rounding error may affect the solution significantly and an error 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>&#160;or <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFeq3"><m:mn mathcolor="#003399" mathvariant="bold">3</m:mn></m:maction></m:math>&#160;is possible.</div><div class="paramtext">The accuracy may also be restricted by 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>.  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">The time taken by D02BHF depends on the complexity and mathematical properties of the system of differential equations defined by <a class="arg" href="#FCN">FCN</a>, the complexity of <a class="arg" href="#G">G</a>, on the range, the position of the solution and the tolerance.  There is also an overhead of the form <m:math><m:mi>a</m:mi><m:mo>+</m:mo><m:mi>b</m:mi><m:mo>&#215;</m:mo><m:mi mathvariant="italic">n</m:mi></m:math>&#160;where <m:math><m:mi>a</m:mi></m:math>&#160;and <m:math><m:mi>b</m:mi></m:math>&#160;are machine-dependent computing times.</div><div class="paramtext">For some problems it is possible that D02BHF will return <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="#IFeq4"><m:mn mathcolor="#003399" mathvariant="bold">4</m:mn></m:maction></m:math>&#160;because of inaccuracy of the computed values <a class="arg" href="#Y">Y</a>, leading to inaccuracy in the computed values 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;used in the search for the 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.0</m:mn></m:math>.  This difficulty can be overcome by reducing <a class="arg" href="#TOL">TOL</a> sufficiently, and if necessary, by choosing <a class="arg" href="#HMAX">HMAX</a> sufficiently small.  If possible, you should choose <a class="arg" href="#XEND">XEND</a> well beyond the expected 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.0</m:mn></m:math>; for example make <m:math><m:mfenced open="|" close="|" separators=""><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:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction></m:mfenced></m:math>&#160;about <m:math><m:mn>50</m:mn><m:mo>%</m:mo></m:math>&#160;larger than the expected range.  As a simple check, if, with <a class="arg" href="#XEND">XEND</a> fixed, a change in <a class="arg" href="#TOL">TOL</a> does not lead to a significant change in <a class="arg" href="#Y">Y</a> at <a class="arg" href="#XEND">XEND</a>, then inaccuracy is not a likely source of error.</div><div class="paramtext">If D02BHF 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 could 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 D02BHF 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 likely 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.  If overflow occurs using D02BHF, <a class="rout" href="../D02/d02pdf.xml">D02PDF</a> can be used instead to detect the increasing solution, before overflow occurs. In any case, numerical integration cannot be continued through a singularity, and analytical 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 compute in very small steps in <m:math><m:mi>x</m:mi></m:math>&#160;(internally to D02BHF) to preserve stability.  This will usually 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>.  Merson's method is not efficient in such cases, and you should try <a class="rout" href="../D02/d02ejf.xml">D02EJF</a> which uses a Backward Differentiation Formula method.  To determine whether a problem is stiff, <a class="rout" href="../D02/d02pcf.xml">D02PCF</a> may be used.</td>
</tr></table>
</div><div class="paramtext">For well-behaved systems with no difficulties such as stiffness or singularities, the Merson method should work well for low accuracy calculations (three or four figures).  For high accuracy calculations or where <a class="arg" href="#FCN">FCN</a> is costly to evaluate, Merson's method may not be appropriate and a computationally less expensive method may be <a class="rout" href="../D02/d02cjf.xml">D02CJF</a> which uses an Adams method.</div><div class="paramtext">For problems for which D02BHF is not sufficiently general, you should consider <a class="rout" href="../D02/d02pdf.xml">D02PDF</a>.  <a class="rout" href="../D02/d02pdf.xml">D02PDF</a> is a more general routine with many facilities including a more general error control criterion.  <a class="rout" href="../D02/d02pdf.xml">D02PDF</a> can be combined with the rootfinder <a class="rout" href="../C05/c05azf.xml">C05AZF</a> and the interpolation routine <a class="rout" href="../D02/d02pxf.xml">D02PXF</a> to solve equations involving <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;and their derivatives.</div><div class="paramtext">D02BHF can also be used to solve an equation involving <m:math><m:mi>x</m:mi></m:math>, <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;and the derivatives of <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>.  For example in <a class="sec" href="#example">Section 9</a>, D02BHF is used to find a value of <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>&gt;</m:mo><m:mn>0.0</m:mn></m:math>&#160;where <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:mn>0.0</m:mn></m:math>.  It could instead be used to find a turning-point of <m:math><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub></m:math>&#160;by replacing 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;in the program by:
<pre class="verbatim">
<span class="bitalic">double precision</span> FUNCTION G(X,Y)
<span class="bitalic">double precision</span> X,Y(3),F(3)
CALL FCN(X,Y,F)
G = F(1)
RETURN
END
</pre>

This routine is only intended to locate the <b>first</b> zero 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>.  If later zeros are required, you are strongly advised to construct your own more general root-finding routines as discussed above.</div><h2 class="standard"><a class="sec" name="example" id="example"/>9&#160;&#160;Example</h2>
<div class="paramtext">This example finds the value <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>&gt;</m:mo><m:mn>0.0</m:mn></m:math>&#160;at which <m:math><m:mi>y</m:mi><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>, where <m:math><m:mi>y</m:mi></m:math>, <m:math><m:mi>v</m:mi></m:math>, <m:math><m:mi>&#981;</m:mi></m:math>&#160;are defined by

<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:mtd>
  <m:mtd><m:mo>=</m:mo></m:mtd>
  <m:mtd><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:mtd>
  <m:mtd><m:mo>=</m:mo></m:mtd>
  <m:mtd><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:mtd>
  <m:mtd><m:mo>=</m:mo></m:mtd>
  <m:mtd><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>

and where at <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;we are given <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 write <m:math><m:mi>y</m:mi><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>1</m:mn></m:mfenced></m:mrow></m:math>, <m:math><m:mi>v</m:mi><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:math>&#160;and <m:math><m:mi>&#981;</m:mi><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>3</m:mn></m:mfenced></m:mrow></m:math>&#160;and we set <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:mtext>1.0D&#8722;4</m:mtext></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:mtext>1.0D&#8722;5</m:mtext></m:math>&#160;in turn so that we can compare the solutions.  We expect the solution <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>&#8771;</m:mo><m:mn>7.3</m:mn></m:math>&#160;and so we set <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;to avoid determining the solution of <m:math><m:mi>y</m:mi><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>&#160;too near the end of the range of integration.  The value of <m:math><m:mi>&#960;</m:mi></m:math>&#160;is obtained by using <a class="rout" href="../X01/x01aaf.xml">X01AAF</a>.</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/d02bhfe.f">Program Text (d02bhfe.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/d02bhfe.r">Program Results (d02bhfe.r)</a></p>
<hr/><div><a class="rout" href="../../pdf/D02/d02bhf.pdf">D02BHF (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>
