<?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>D02HAF : 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/d02haf.pdf">D02HAF (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/>D02HAF</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">D02HAF solves a two-point boundary value problem for a system of ordinary differential equations, using a Runge&#8211;Kutta&#8211;Merson method and a Newton iteration in a shooting and matching technique.</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;D02HAF&#160;(</td><td class="tdfspec2"><a class="arg" href="#U">U</a>, <a class="arg" href="#V">V</a>, <a class="arg" href="#N">N</a>, <a class="arg" href="#A">A</a>, <a class="arg" href="#B">B</a>, <a class="arg" href="#TOL">TOL</a>, <a class="arg" href="#FCN">FCN</a>, <a class="arg" href="#SOLN">SOLN</a>, <a class="arg" href="#M1">M1</a>, <a class="arg" href="#W">W</a>, <a class="arg" href="#SDW">SDW</a>, <a class="arg" href="#IFAIL">IFAIL</a>)</td></tr><tr><td class="tdfspec1">INTEGER</td><td class="tdfspec2">N, M1, SDW, IFAIL</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">U(N,2), V(N,2), A, B, TOL, SOLN(N,M1), W(N,SDW)</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">D02HAF solves a two-point boundary value problem for a system of <m:math><m:mi mathvariant="italic">n</m:mi></m:math>&#160;ordinary differential equations in the range <m:math><m:mi>a</m:mi><m:mo>,</m:mo><m:mi>b</m:mi></m:math>.  The system is written in the form:

<div class="formula-eqn"><a name="eqn1" id="eqn1"/><table class="formula-eqn"><tr><td class="formula-eqn"><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:math></td><td class="formula-eqn2">
      (1)
     </td></tr></table></div>

and the derivatives <m:math><m:msub><m:mi>f</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;are evaluated by <a class="arg" href="#FCN">FCN</a>.  Initially, <m:math><m:mi mathvariant="italic">n</m:mi></m:math>&#160;boundary values of the variables <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;must be specified, some at <m:math><m:mi>a</m:mi></m:math>&#160;and some at <m:math><m:mi>b</m:mi></m:math>.  You must supply estimates of the remaining <m:math><m:mi mathvariant="italic">n</m:mi></m:math>&#160;boundary values (called parameters below); the subroutine corrects these by a form of Newton iteration.  It also calculates the complete solution on an equispaced mesh if required.</div><div class="paramtext">Starting from the known and estimated values of <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;at <m:math><m:mi>a</m:mi></m:math>, the subroutine integrates the equations from <m:math><m:mi>a</m:mi></m:math>&#160;to <m:math><m:mi>b</m:mi></m:math>&#160;(using a Runge&#8211;Kutta&#8211;Merson method).  The differences between the values of <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;at <m:math><m:mi>b</m:mi></m:math>&#160;from integration and those specified initially should be zero for the true solution.  (These differences are called residuals below.)  The subroutine uses a generalized Newton method to reduce the residuals to zero, by calculating corrections to the estimated boundary values.  This process is repeated iteratively until convergence is obtained, or until the routine can no longer reduce the residuals.  See <a class="ref" href="#ref024">Hall and Watt (1976)</a> for a simple discussion of shooting and matching techniques.</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="U" id="U"/>1: &#160;&#160;&#8194; U(<a class="arg" href="#N">N</a>,<m:math><m:mn>2</m:mn></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On entry</i>: <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#U"><m:mi mathcolor="#EE0000" mathvariant="bold">U</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi><m:mn>1</m:mn></m:mfenced></m:mrow></m:math>&#160;must be set to the known or estimated value of <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;at <m:math><m:mi>a</m:mi></m:math>&#160;and <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#U"><m:mi mathcolor="#EE0000" mathvariant="bold">U</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi><m:mn>2</m:mn></m:mfenced></m:mrow></m:math>&#160;must be set to the known or estimated value of <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;at <m:math><m:mi>b</m:mi></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>
<div class="paramtext"><i>On exit</i>: the known values unaltered, and corrected values of the estimates, unless an error has occurred. If an error has occurred, <a class="arg" href="#U">U</a> contains the known values and the latest values of the estimates.</div></dd><dt class="paramhead"><a name="V" id="V"/>2: &#160;&#160;&#8194; V(<a class="arg" href="#N">N</a>,<m:math><m:mn>2</m:mn></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:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#V"><m:mi mathcolor="#EE0000" mathvariant="bold">V</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>&#160;must be set to <m:math><m:mn>0.0</m:mn></m:math>&#160;if <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#U"><m:mi mathcolor="#EE0000" mathvariant="bold">U</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>&#160;is a known value and to <m:math><m:mn>1.0</m:mn></m:math>&#160;if <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#U"><m:mi mathcolor="#EE0000" mathvariant="bold">U</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>&#160;is an estimated value, 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>&#160;and <m:math><m:mi>j</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn></m:math>.</div><div class="paramtext"><i>Constraint</i>:
  

precisely <m:math><m:mi mathvariant="italic">n</m:mi></m:math>&#160;of the <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#V"><m:mi mathcolor="#EE0000" mathvariant="bold">V</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>&#160;must be set to <m:math><m:mn>0.0</m:mn></m:math>, i.e., precisely <m:math><m:mi mathvariant="italic">n</m:mi></m:math>&#160;of the <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#U"><m:mi mathcolor="#EE0000" mathvariant="bold">U</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>&#160;must be known values, and these must not be all at <m:math><m:mi>a</m:mi></m:math>&#160;or all at <m:math><m:mi>b</m:mi></m:math></div></dd><dt class="paramhead"><a name="N" id="N"/>3: &#160;&#160;&#8194; N &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: 

<m:math><m:mi mathvariant="italic">n</m:mi></m:math>, the number of equations.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>2</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="A" id="A"/>4: &#160;&#160;&#8194; A &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: <m:math><m:mi>a</m:mi></m:math>, the initial point of the interval of integration.</div></dd><dt class="paramhead"><a name="B" id="B"/>5: &#160;&#160;&#8194; B &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: <m:math><m:mi>b</m:mi></m:math>, the final point of the interval of integration.</div></dd><dt class="paramhead"><a name="TOL" id="TOL"/>6: &#160;&#160;&#8194; TOL &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: must be set to a small quantity suitable for:
<table class="standard-90"><tr>
<td style="width:2.1em;" valign="baseline">(a)</td>
<td valign="top">testing the local error in <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;during integration,</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline">(b)</td>
<td valign="top">testing for the convergence of <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;at <m:math><m:mi>b</m:mi></m:math>,</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline">(c)</td>
<td valign="top">calculating the perturbation in estimated boundary values for <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>, which are used to obtain the approximate derivatives of the residuals for use in the Newton iteration.</td>
</tr></table>
<div class="paramtext">You are advised to check your results by varying <a class="arg" href="#TOL">TOL</a>.</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></dd><dt class="paramhead"><a name="FCN" id="FCN"/>7: &#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 <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>, at a general point <m:math><m:mi>x</m:mi></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/d02haf.xml#FCN_X">X</a>, <a class="arg" href="../D02/d02haf.xml#FCN_Y">Y</a>, <a class="arg" href="../D02/d02haf.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 D02HAF.</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 values of <m:math><m:msub><m:mi>f</m:mi><m:mi>i</m:mi></m:msub><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></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 D02HAF 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="SOLN" id="SOLN"/>8: &#160;&#160;&#8194; SOLN(<a class="arg" href="#N">N</a>,<a class="arg" href="#M1">M1</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Output</span></dt><dd>
<div class="paramtext"><i>On exit</i>: the solution when <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#M1"><m:mi mathcolor="#EE0000" mathvariant="bold">M1</m:mi></m:maction><m:mo>&gt;</m:mo><m:mn>1</m:mn></m:math>.</div></dd><dt class="paramhead"><a name="M1" id="M1"/>9: &#160;&#160;&#8194; M1 &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: 

a value which controls output.

<dl>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#M1"><m:mi mathcolor="#EE0000" mathvariant="bold">M1</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math></dt>
<dd>The final solution is not evaluated.</dd>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#M1"><m:mi mathcolor="#EE0000" mathvariant="bold">M1</m:mi></m:maction><m:mo>&gt;</m:mo><m:mn>1</m:mn></m:math></dt>
<dd>The final values of <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;at interval <m:math><m:mfenced separators=""><m:mi>b</m:mi><m:mo>-</m:mo><m:mi>a</m:mi></m:mfenced><m:mo>/</m:mo><m:mfenced separators=""><m:maction actiontype="link" dsi:type="simple" dsi:href="#M1"><m:mi mathcolor="#EE0000" mathvariant="bold">M1</m:mi></m:maction><m:mo>-</m:mo><m:mn>1</m:mn></m:mfenced></m:math>&#160;are calculated and stored in the array <a class="arg" href="#SOLN">SOLN</a> by columns, starting with values <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;at <m:math><m:mi>a</m:mi></m:math>&#160;stored in <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#SOLN"><m:mi mathcolor="#EE0000" mathvariant="bold">SOLN</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi><m:mn>1</m:mn></m:mfenced></m:mrow></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>.</dd></dl>
</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#M1"><m:mi mathcolor="#EE0000" mathvariant="bold">M1</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>1</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="W" id="W"/>10: &#8194; W(<a class="arg" href="#N">N</a>,<a class="arg" href="#SDW">SDW</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Output</span></dt><dd>
<div class="paramtext"><i>On exit</i>: if <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</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>, <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>, <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFeq4"><m:mn mathcolor="#003399" mathvariant="bold">4</m:mn></m:maction></m:math>&#160;or <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFeq5"><m:mn mathcolor="#003399" mathvariant="bold">5</m:mn></m:maction></m:math>, <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#W"><m:mi mathcolor="#EE0000" mathvariant="bold">W</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi><m:mn>1</m:mn></m:mfenced></m:mrow></m:math>&#160;contains the solution at the point where the integration fails, 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>, and the point of failure is returned in <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#W"><m:mi mathcolor="#EE0000" mathvariant="bold">W</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>1</m:mn><m:mn>2</m:mn></m:mfenced></m:mrow></m:math>.</div></dd><dt class="paramhead"><a name="SDW" id="SDW"/>11: &#8194; SDW &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the second dimension of the array <a class="arg" href="#W">W</a> as declared in the (sub)program from which D02HAF is called.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#SDW"><m:mi mathcolor="#EE0000" mathvariant="bold">SDW</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>3</m:mn><m:mo>&#8290;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction><m:mo>+</m:mo><m:mn>17</m:mn><m:mo>+</m:mo><m:mrow><m:mi>max</m:mi><m:mspace width="0.125em"/><m:mfenced separators=""><m:mn>11</m:mn><m:mo>,</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:mfenced></m:mrow></m:math>.
</div></dd><dt class="paramhead"><a name="IFAIL" id="IFAIL"/>12: &#8194; IFAIL &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext">For this routine, the normal use of <a class="arg" href="#IFAIL">IFAIL</a> is extended to control the printing of error and warning messages as well as specifying hard or soft failure (see <a class="sec" href="../GENINT/essint.xml#library3">Section 3.3</a> in  the Essential Introduction).</div>
<div class="paramtext"><i>On entry</i>: <a class="arg" href="#IFAIL">IFAIL</a> must be set to a value with the decimal expansion <m:math><m:mi mathvariant="italic">cba</m:mi></m:math>, where each of the decimal digits <m:math><m:mi>c</m:mi></m:math>, <m:math><m:mi>b</m:mi></m:math>&#160;and <m:math><m:mi>a</m:mi></m:math>&#160;must have a value of <m:math><m:mn>0</m:mn></m:math>&#160;or <m:math><m:mn>1</m:mn></m:math>.
<table class="standard-90"><tr>
<td style="width:3.0em;" valign="baseline"><m:math><m:mi>a</m:mi><m:mo>=</m:mo><m:mn>0</m:mn></m:math></td>
<td valign="top">specifies hard failure, otherwise soft failure;</td>
</tr><tr>
<td style="width:3.0em;" valign="baseline"><m:math><m:mi>b</m:mi><m:mo>=</m:mo><m:mn>0</m:mn></m:math></td>
<td valign="top">suppresses error messages, otherwise error messages will be printed (see <a class="sec" href="#errors">Section 6</a>);</td>
</tr><tr>
<td style="width:3.0em;" valign="baseline"><m:math><m:mi>c</m:mi><m:mo>=</m:mo><m:mn>0</m:mn></m:math></td>
<td valign="top">suppresses warning messages, otherwise warning messages will be printed (see <a class="sec" href="#errors">Section 6</a>).</td>
</tr></table>
<div class="paramtext">The recommended value for inexperienced users is <m:math><m:mn>110</m:mn></m:math>&#160;(i.e., hard failure with all messages printed).</div>
</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></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>
<div class="paramtext">One or more of the parameters <a class="arg" href="#V">V</a>, <a class="arg" href="#N">N</a>, <a class="arg" href="#M1">M1</a>, <a class="arg" href="#SDW">SDW</a>, or <a class="arg" href="#TOL">TOL</a> is incorrectly set.</div>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq2" id="IFeq2"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn></m:math></dt>
<dd>
<div class="paramtext">The step length for the integration is too short whilst calculating the residual (see <a class="sec" href="#fcomments">Section 8</a>).</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">No initial step length could be chosen for the integration whilst calculating the residual.</div></dd>
</dl>
<div class="paramtext"><b>Note:</b> <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;can occur due to choosing too small a value for <a class="arg" href="#TOL">TOL</a> or due to choosing the wrong direction of integration.  Try varying <a class="arg" href="#TOL">TOL</a> and interchanging <m:math><m:mi>a</m:mi></m:math>&#160;and <m:math><m:mi>b</m:mi></m:math>.  These error exits can also occur for very poor initial estimates of the unknown initial values and, in extreme cases, because D02HAF cannot be used to solve the problem posed.</div>
<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">As for <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;but the error occurred when calculating the Jacobian of the derivatives of the residuals with respect to the parameters.</div>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq5" id="IFeq5"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>5</m:mn></m:math></dt>
<dd>
<div class="paramtext">As for <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>&#160;but the error occurred when calculating the derivatives of the residuals with respect to the parameters.</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">The calculated Jacobian has an insignificant column.</div>
</dd>
</dl>
<div class="paramtext"><b>Note:</b> <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>, <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFeq5"><m:mn mathcolor="#003399" mathvariant="bold">5</m:mn></m:maction></m:math>&#160;or <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFeq6"><m:mn mathcolor="#003399" mathvariant="bold">6</m:mn></m:maction></m:math>&#160;usually indicate a badly scaled problem.  You may vary the size of <a class="arg" href="#TOL">TOL</a> or change to one of the more general routines <a class="rout" href="../D02/d02hbf.xml">D02HBF</a> or <a class="rout" href="../D02/d02saf.xml">D02SAF</a> which afford more control over the calculations.</div>
<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">The linear algebra routine  (<a class="rout" href="../F08/f08kbf.xml">F08KBF (DGESVD)</a>) used has failed.  This error exit should not occur and can be avoided by changing the estimated initial values.</div>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq8" id="IFeq8"/><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>8</m:mn></m:math></dt>
<dd>
<div class="paramtext">The Newton iteration has failed to converge.</div>
</dd>
</dl>
<div class="paramtext"><b>Note:</b> <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="#IFeq8"><m:mn mathcolor="#003399" mathvariant="bold">8</m:mn></m:maction></m:math>&#160;can indicate poor initial estimates or a very difficult problem.  Consider varying <a class="arg" href="#TOL">TOL</a> if the residuals are small in the monitoring output.  If the residuals are large try varying the initial estimates.</div>
<dl class="ifail">
<dt class="errorhead"><a name="IFeq9" id="IFeq9"/><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>9</m:mn></m:math></dt>
<dt class="multi-errorhead"><a name="IFeq10" id="IFeq10"/><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>10</m:mn></m:math></dt>
<dt class="multi-errorhead"><a name="IFeq11" id="IFeq11"/><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>11</m:mn></m:math></dt>
<dt class="multi-errorhead"><a name="IFeq12" id="IFeq12"/><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>12</m:mn></m:math></dt>
<dt class="multi-errorhead"><a name="IFeq13" id="IFeq13"/><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>13</m:mn></m:math></dt>
<dd>
<div class="paramtext">Indicates that a serious error has occurred in an internal call.  Check all array subscripts and subroutine parameter lists in calls to D02HAF.  Seek expert help.</div>
</dd>
</dl><h2 class="standard"><a class="sec" name="accuracy" id="accuracy"/>7&#160;&#160;Accuracy</h2>
<div class="paramtext">If the process converges, the accuracy to which the unknown parameters are determined is usually close to that specified by you; the solution, if requested, may be determined to a required accuracy by varying <a class="arg" href="#TOL">TOL</a>.</div><h2 class="standard"><a class="sec" name="fcomments" id="fcomments"/>8&#160;&#160;Further Comments</h2>
<div class="paramtext">The time taken by D02HAF depends on the complexity of the system, and on the number of iterations required.  In practice, integration of the differential equations is by far the most costly process involved.</div><div class="paramtext">Wherever it occurs in the routine, the error parameter <a class="arg" href="#TOL">TOL</a> is used in &#8216;mixed&#8217; form; that is <a class="arg" href="#TOL">TOL</a> always occurs in expressions of the form <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>&#215;</m:mo><m:mfenced separators=""><m:mn>1</m:mn><m:mo>+</m:mo><m:mfenced open="|" close="|" separators=""><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:mfenced></m:mfenced></m:math>.  Though not ideal for every application, it is expected that this mixture of absolute and relative error testing will be adequate for most purposes.</div><div class="paramtext">You are strongly recommended to set <a class="arg" href="#IFAIL">IFAIL</a> to obtain self-explanatory error messages, and also monitoring information about the course of the computation.  You may select the channel numbers on which this output is to appear by calls of <a class="rout" href="../X04/x04aaf.xml">X04AAF</a> (for error messages)  or <a class="rout" href="../X04/x04abf.xml">X04ABF</a> (for monitoring information) &#8211; see <a class="sec" href="#example">Section 9</a> for an example.  Otherwise the default channel numbers will be used, as specified in the <a class="url" href="http://www.nag.co.uk/doc/inun/fl22.html">Users' Note</a>.  The monitoring information produced at each iteration includes the current parameter values, the residuals and two norms: a basic norm and a current norm.  At each iteration the aim is to find parameter values which make the current norm less than the basic norm.  Both these norms should tend to zero as should the residuals.  (They would all be zero if the exact parameters were used as input.)  For more details, you may consult the specification of <a class="rout" href="../D02/d02saf.xml">D02SAF</a>, and especially the description of the parameter <a class="arg" href="../D02/d02saf.xml#MONIT">MONIT</a> there.</div><div class="paramtext">The computing time for integrating the differential equations can sometimes depend critically on the quality of the initial estimates.  If it seems that too much computing time is required and, in particular, if the values of the residuals printed by the monitoring routine are much larger than the expected values of the solution at <m:math><m:mi>b</m:mi></m:math>, then the coding of <a class="arg" href="#FCN">FCN</a> should be checked for errors.  If no errors can be found, an independent attempt should be made to improve the initial estimates.  In practical problems it is not uncommon for the differential equation to have a singular point at one or both ends of the range.  Suppose <m:math><m:mi>a</m:mi></m:math>&#160;is a singular point; then 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>&#160;in <a class="eqn" href="#eqn1">(1)</a> (in <a class="sec" href="#description">Section 3</a>)  cannot be evaluated at <m:math><m:mi>a</m:mi></m:math>, usually because one or more of the expressions for <m:math><m:msub><m:mi>f</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;give overflow.  In such a case it is necessary for you to take <m:math><m:mi>a</m:mi></m:math>&#160;a short distance away from the singularity, and to find values for <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;at the new value of <m:math><m:mi>a</m:mi></m:math>&#160;(e.g., use the first one or two terms of an analytical  (power series) solution).  You should experiment with the new position of <m:math><m:mi>a</m:mi></m:math>; if it is taken too close to the singular point, the derivatives <m:math><m:msub><m:mi>f</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;will be inaccurate, and the routine may sometimes fail 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;or, in extreme cases,  with an overflow condition.  A more general treatment of singular solutions is provided by the subroutine <a class="rout" href="../D02/d02hbf.xml">D02HBF</a>.</div><div class="paramtext">Another difficulty which often arises in practice is the case when one end of the range, <m:math><m:mi>b</m:mi></m:math>&#160;say, is at infinity.  You must approximate the end point by taking a finite value for <m:math><m:mi>b</m:mi></m:math>,  which is obtained by estimating where the solution will reach its asymptotic state.  The estimate can be checked by repeating the calculation with a larger value of <m:math><m:mi>b</m:mi></m:math>.  If <m:math><m:mi>b</m:mi></m:math>&#160;is very large, and if the matching point is also at <m:math><m:mi>b</m:mi></m:math>, the numerical solution may suffer a considerable loss of accuracy in integrating across the range,  and the program may fail 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="#IFeq6"><m:mn mathcolor="#003399" mathvariant="bold">6</m:mn></m:maction></m:math>&#160;or <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFeq8"><m:mn mathcolor="#003399" mathvariant="bold">8</m:mn></m:maction></m:math>.  (In the former case, solutions from all initial values at <m:math><m:mi>a</m:mi></m:math>&#160;are tending to the same curve at infinity.)  The simplest remedy is to try to solve the equations with a smaller value of <m:math><m:mi>b</m:mi></m:math>, and then to increase <m:math><m:mi>b</m:mi></m:math>&#160;in stages, using each solution to give boundary value estimates for the next calculation.  For problems where some terms in the asymptotic form of the solution are known, <a class="rout" href="../D02/d02hbf.xml">D02HBF</a> will be more successful.</div><div class="paramtext">If the unknown quantities are not boundary values, but are eigenvalues or the length of the range or some other parameters occurring in the differential equations, <a class="rout" href="../D02/d02hbf.xml">D02HBF</a> may be used.</div><h2 class="standard"><a class="sec" name="example" id="example"/>9&#160;&#160;Example</h2>
<div class="paramtext">This example finds the angle at which a projectile must be fired for a given range.</div><div class="paramtext">The differential equations are:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mtable>
 <m:mtr columnalign="left">
  <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 columnalign="left">
  <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:mrow><m:mo>-</m:mo><m:mn>0.032</m:mn></m:mrow>
     <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 columnalign="left">
  <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:mtext>,</m:mtext>
  </m:mtd>
 </m:mtr>
</m:mtable>
</m:math></td><td class="formula2"/></tr></table></div>

with the following boundary conditions:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mtable>
 <m:mtr>
  <m:mtd><m:mi>y</m:mi><m:mo>=</m:mo> <m:mn>0</m:mn><m:mtext>,</m:mtext></m:mtd>
  <m:mtd><m:mi>v</m:mi><m:mo>=</m:mo> <m:mn>0.5</m:mn></m:mtd>
  <m:mtd><m:mtext>at &#8195;</m:mtext> <m:mi>x</m:mi><m:mo>=</m:mo> <m:mn>0</m:mn><m:mtext>,</m:mtext></m:mtd>
 </m:mtr><m:mtr>
  <m:mtd/>
  <m:mtd/>
  <m:mtd/>
 </m:mtr><m:mtr>
  <m:mtd><m:mi>y</m:mi><m:mo>=</m:mo> <m:mn>0</m:mn></m:mtd>
  <m:mtd/>
  <m:mtd><m:mtext>at &#8195;</m:mtext> <m:mi>x</m:mi><m:mo>=</m:mo> <m:mn>5</m:mn><m:mtext>.</m:mtext></m:mtd>
 </m:mtr>
</m:mtable>
</m:math></td><td class="formula2"/></tr></table></div>

The remaining boundary conditions are estimated as:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mtable>
 <m:mtr>
  <m:mtd><m:mi>&#981;</m:mi><m:mo>=</m:mo><m:mn>1.15</m:mn></m:mtd>
  <m:mtd/>
  <m:mtd><m:mtext>at &#8195;</m:mtext><m:mi>x</m:mi><m:mo>=</m:mo><m:mn>0</m:mn><m:mtext>,</m:mtext></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>=</m:mo><m:mn>1.2</m:mn><m:mtext>,</m:mtext></m:mtd>
  <m:mtd><m:mi>v</m:mi><m:mo>=</m:mo><m:mn>0.46</m:mn></m:mtd>
  <m:mtd><m:mtext>at &#8195;</m:mtext><m:mi>x</m:mi><m:mo>=</m:mo><m:mn>5</m:mn><m:mtext>.</m:mtext></m:mtd>
 </m:mtr>
</m:mtable>
</m:math></td><td class="formula2"/></tr></table></div>

We write <m:math><m:mi>y</m:mi><m:mo>=</m:mo><m:mi mathvariant="normal">Z</m:mi><m:mfenced separators=""><m:mn>1</m:mn></m:mfenced></m:math>, <m:math><m:mi>v</m:mi><m:mo>=</m:mo><m:mi mathvariant="normal">Z</m:mi><m:mfenced separators=""><m:mn>2</m:mn></m:mfenced></m:math>, <m:math><m:mi>&#981;</m:mi><m:mo>=</m:mo><m:mi mathvariant="normal">Z</m:mi><m:mfenced separators=""><m:mn>3</m:mn></m:mfenced></m:math>.  To check the accuracy of the results the problem is solved twice 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:mn>5</m:mn></m:math>.<m:math><m:mtext>0D&#8722;3</m:mtext></m:math>&#160;and <m:math><m:mtext>5.0D&#8722;4</m:mtext></m:math>&#160;respectively.  Note the call to <a class="rout" href="../X04/x04abf.xml">X04ABF</a> before the call to D02HAF.</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/d02hafe.f">Program Text (d02hafe.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/d02hafe.r">Program Results (d02hafe.r)</a></p><div class="figure"><a name="d02haf-plot" id="d02haf-plot"/><img src="../figures/d02haf-plot.png" alt="Example Program Plot for d02haf-plot"/></div>
<hr/><div><a class="rout" href="../../pdf/D02/d02haf.pdf">D02HAF (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>
