<?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>D02BGF : 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/d02bgf.pdf">D02BGF (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/>D02BGF</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">D02BGF 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 specified component attains a given value.</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;D02BGF&#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="#HMAX">HMAX</a>, <a class="arg" href="#M">M</a>, <a class="arg" href="#VAL">VAL</a>, <a class="arg" href="#FCN">FCN</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, M, IFAIL</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">X, XEND, Y(N), TOL, HMAX, VAL, W(N,10)</td></tr><tr><td class="tdfspec1">EXTERNAL</td><td class="tdfspec2">FCN</td></tr></table><h2 class="standard"><a class="sec" name="description" id="description"/>3&#160;&#160;Description</h2>
<div class="paramtext">D02BGF 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 specified component <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub></m:math>&#160;of the solution to determine an interval where it attains a given value <m:math><m:mi>&#945;</m:mi></m:math>.  The position where this value is attained is then determined accurately by interpolation on the solution and its derivative.  It is assumed that the solution of <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>=</m:mo><m:mi>&#945;</m:mi></m:math>&#160;can be determined by searching for a change in sign in the function <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>-</m:mo><m:mi>&#945;</m:mi></m:math>.</div><div class="paramtext">The accuracy of the integration and, indirectly, of the determination of the position where <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>=</m:mo><m:mi>&#945;</m:mi></m:math>&#160;is controlled by the parameter <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 the component <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub></m:math>&#160;attains the value <m:math><m:mi>&#945;</m:mi></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:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>&#8800;</m:mo><m:mi>&#945;</m:mi></m:math>&#160;anywhere on the range <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>, 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 will proceed in the 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 a point near the solution <a class="arg" href="#X">X</a>, unless an error has occurred when they contain the computed values at the final value of <a class="arg" href="#X">X</a>.</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 positive tolerance for controlling the error in the integration and in the determination of the position where <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>=</m:mo><m:mi>&#945;</m:mi></m:math>.
<div class="paramtext">D02BGF 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:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>=</m:mo><m:mi>&#945;</m:mi></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 D02BGF 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 D02BGF 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 <a class="arg" href="#X">X</a> to the position where <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>=</m:mo><m:mi>&#945;</m:mi></m:math>&#160;(or to the final value of <a class="arg" href="#X">X</a> 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, on return, <a class="arg" href="#TOL">TOL</a> has 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>, D02BGF 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="HMAX" id="HMAX"/>6: &#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>: controls how the sign of <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>-</m:mo><m:mi>&#945;</m:mi></m:math>&#160;is checked.

<dl>
<dt class="paramval"><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></dt>
<dd><m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>-</m:mo><m:mi>&#945;</m:mi></m:math>&#160;is checked at every internal integration step.</dd>
<dt class="paramval"><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></dt>
<dd>The computed solution is checked for a change in sign of <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>-</m:mo><m:mi>&#945;</m:mi></m:math>&#160;at steps of 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:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>-</m:mo><m:mi>&#945;</m:mi></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:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>-</m:mo><m:mi>&#945;</m:mi></m:math>&#160;is expected on the range <a class="arg" href="#X">X</a> to <a class="arg" href="#XEND">XEND</a> then <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.</dd></dl>
</div></dd><dt class="paramhead"><a name="M" id="M"/>7: &#160;&#160;&#8194; M &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the index <m:math><m:mi>m</m:mi></m:math>&#160;of the component of the solution whose value is to be checked.</div>
<div class="paramtext"><i>Constraint</i>:
  <m:math><m:mn>1</m:mn><m:mo>&#8804;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>&#8804;</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>.
</div></dd><dt class="paramhead"><a name="VAL" id="VAL"/>8: &#160;&#160;&#8194; VAL &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the value of <m:math><m:mi>&#945;</m:mi></m:math>&#160;in the equation <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>=</m:mo><m:mi>&#945;</m:mi></m:math>&#160;to be solved for <a class="arg" href="#X">X</a>.</div></dd><dt class="paramhead"><a name="FCN" id="FCN"/>9: &#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/d02bgf.xml#FCN_X">X</a>, <a class="arg" href="../D02/d02bgf.xml#FCN_Y">Y</a>, <a class="arg" href="../D02/d02bgf.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 actual value of <a class="arg" href="#N">N</a> in the call of D02BGF.</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 D02BGF 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>10</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="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</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="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>&gt;</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>.</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:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>-</m:mo><m:mi>&#945;</m:mi></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 the routine 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:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>-</m:mo><m:mi>&#945;</m:mi></m:math>&#160;change sign. It is assumed that <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>-</m:mo><m:mi>&#945;</m:mi></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:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>=</m:mo><m:mi>&#945;</m:mi></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><h2 class="standard"><a class="sec" name="fcomments" id="fcomments"/>8&#160;&#160;Further Comments</h2>
<div class="paramtext">The time taken by D02BGF depends on the complexity and mathematical properties of the system of differential equations defined by <a class="arg" href="#FCN">FCN</a>, on the range, the position of 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 D02BGF will 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="#IFeq4"><m:mn mathcolor="#003399" mathvariant="bold">4</m:mn></m:maction></m:math>&#160;due to inaccuracy of the computed value <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub></m:math>.  For example, consider a case where the component <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub></m:math>&#160;has a maximum in the integration range and <m:math><m:mi>&#945;</m:mi></m:math>&#160;is close to the maximum value.  If <a class="arg" href="#TOL">TOL</a> is too large, it is possible that the maximum might be estimated as less than <m:math><m:mi>&#945;</m:mi></m:math>, or even that the integration step length chosen might be so long that the maximum of <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub></m:math>&#160;and the (two) positions where <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>=</m:mo><m:mi>&#945;</m:mi></m:math>&#160;are all in the same step and so the position where <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>=</m:mo><m:mi>&#945;</m:mi></m:math>&#160;remains undetected.  Both these difficulties 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.  For similar reasons, care should be taken when choosing <a class="arg" href="#XEND">XEND</a>.  If possible, you should choose <a class="arg" href="#XEND">XEND</a> well beyond the point where <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub></m:math>&#160;is expected to equal <m:math><m:mi>&#945;</m:mi></m:math>, for example <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;should be made about <m:math><m:mn>50</m:mn><m:mo>%</m:mo></m:math>&#160;longer 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 <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub></m:math>&#160;at <a class="arg" href="#XEND">XEND</a>, then inaccuracy is not a likely source of error.</div><div class="paramtext">If D02BGF 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 D02BGF 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 D02BGF, routine <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 use very small steps in <m:math><m:mi>x</m:mi></m:math>&#160;(internally to D02BGF) 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 the method <a class="rout" href="../D02/d02ejf.xml">D02EJF</a> which uses a Backward Differentiation Formula.  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 D02BGF is not sufficiently general, you should consider the routines <a class="rout" href="../D02/d02bhf.xml">D02BHF</a> and <a class="rout" href="../D02/d02pdf.xml">D02PDF</a>.  Routine <a class="rout" href="../D02/d02bhf.xml">D02BHF</a> can be used to solve an equation involving the components <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 (for example, to find where a component passes through zero or to find the maximum value of a component).  It also permits a more general form of error control and may be preferred to D02BGF if the component whose value is to be determined is very small in modulus on the integration range.  <a class="rout" href="../D02/d02bhf.xml">D02BHF</a> can always be used in place of D02BGF, but will usually be computationally more expensive for solving the same problem.  <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 root-finder <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">This routine is only intended to be used to locate the <b>first</b> zero of the function <m:math><m:msub><m:mi>y</m:mi><m:mi>m</m:mi></m:msub><m:mo>-</m:mo><m:mi>&#945;</m:mi></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;where <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>, 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: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:mi>&#981;</m:mi><m:mo>&#8242;</m:mo><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>

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 obtained.  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 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;so that the point where <m:math><m:mi>y</m:mi><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>&#160;is not 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/d02bgfe.f">Program Text (d02bgfe.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/d02bgfe.r">Program Results (d02bgfe.r)</a></p>
<hr/><div><a class="rout" href="../../pdf/D02/d02bgf.pdf">D02BGF (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>
