<?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>D02LAF : 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/d02laf.pdf">D02LAF (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/>D02LAF</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">D02LAF is a routine for integrating a non-stiff system of second-order ordinary differential equations using Runge&#8211;Kutta&#8211;Nystrom techniques.</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;D02LAF&#160;(</td><td class="tdfspec2"><a class="arg" href="#FCN">FCN</a>, <a class="arg" href="#NEQ">NEQ</a>, <a class="arg" href="#T">T</a>, <a class="arg" href="#TEND">TEND</a>, <a class="arg" href="#Y">Y</a>, <a class="arg" href="#YP">YP</a>, <a class="arg" href="#YDP">YDP</a>, <a class="arg" href="#RWORK">RWORK</a>, <a class="arg" href="#LRWORK">LRWORK</a>, <a class="arg" href="#IFAIL">IFAIL</a>)</td></tr><tr><td class="tdfspec1">INTEGER</td><td class="tdfspec2">NEQ, LRWORK, IFAIL</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">T, TEND, Y(NEQ), YP(NEQ), YDP(NEQ), RWORK(LRWORK)</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">Given the initial values <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: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:maction actiontype="link" dsi:type="simple" dsi:href="#NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction></m:msub><m:mo>,</m:mo><m:msubsup><m:mi>y</m:mi><m:mn>1</m:mn><m:mo>&#8242;</m:mo></m:msubsup><m:mo>,</m:mo><m:msubsup><m:mi>y</m:mi><m:mn>2</m:mn><m:mo>&#8242;</m:mo></m:msubsup><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msubsup><m:mi>y</m:mi><m:maction actiontype="link" dsi:type="simple" dsi:href="#NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction><m:mo>&#8242;</m:mo></m:msubsup></m:math>&#160;D02LAF integrates a non-stiff system of second-order differential equations of the type

<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:mrow><m:mo>&#8242;</m:mo><m:mo>&#8242;</m:mo></m:mrow></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:maction actiontype="link" dsi:type="simple" dsi:href="#NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction></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:maction actiontype="link" dsi:type="simple" dsi:href="#NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction><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="#T"><m:mi mathcolor="#EE0000" mathvariant="bold">T</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="#TEND"><m:mi mathcolor="#EE0000" mathvariant="bold">TEND</m:mi></m:maction></m:math>&#160;using a  Runge&#8211;Kutta&#8211;Nystrom formula pair.  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:maction actiontype="link" dsi:type="simple" dsi:href="#NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction></m:msub></m:math>, where <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:maction actiontype="link" dsi:type="simple" dsi:href="#NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction></m:msub></m:math>&#160;are supplied at <m:math><m:mi>x</m:mi></m:math>.</div><div class="paramtext">There are two Runge&#8211;Kutta&#8211;Nystrom formula pairs implemented in this routine.  The lower order method is intended if you have moderate accuracy requirements and may be used in conjunction with the interpolation routine <a class="rout" href="../D02/d02lzf.xml">D02LZF</a> to produce solutions and derivatives at user-specified points.  The higher order method is intended if you have high accuracy requirements.</div><div class="paramtext">In one-step mode the routine returns approximations to the solution, derivative and <m:math><m:msub><m:mi>f</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;at each integration point.  In interval mode these values are returned at the end of the integration range.  You select the order of the method, the mode of operation, the error control and various optional inputs by a prior call to <a class="rout" href="../D02/d02lxf.xml">D02LXF</a>.</div><div class="paramtext">For a description of the Runge&#8211;Kutta&#8211;Nystrom formula pairs see <a class="ref" href="#ref289">Dormand <span class="italic">et al.</span> (1986a)</a> and <a class="ref" href="#ref290">Dormand <span class="italic">et al.</span> (1986b)</a> and for a description of their practical implementation see <a class="ref" href="#ref288">Brankin <span class="italic">et al.</span> (1989)</a>.</div><h2 class="standard"><a class="sec" name="references" id="references"/>4&#160;&#160;References</h2><div class="paramtext"><a name="ref288" id="ref288"/>Brankin R W, Dormand J R, Gladwell I, Prince P J and Seward W L (1989)  Algorithm 670: A Runge&#8211;Kutta&#8211;Nystrom Code <i>ACM Trans. Math. Software</i> <b>15</b> 31&#8211;40 </div>
<div class="paramtext"><a name="ref289" id="ref289"/>Dormand J R, El&#8211;Mikkawy M E A and Prince P J (1986a)  Families of Runge&#8211;Kutta&#8211;Nystrom formulae <i>Mathematical Report TPMR 86-1</i> Teesside Polytechnic </div>
<div class="paramtext"><a name="ref290" id="ref290"/>Dormand J R, El&#8211;Mikkawy M E A and Prince P J (1986b)  High order embedded Runge&#8211;Kutta&#8211;Nystrom formulae <i>Mathematical Report TPMR 86-2</i> Teesside Polytechnic </div><h2 class="standard"><a class="sec" name="parameters" id="parameters"/>5&#160;&#160;Parameters</h2>
<dl><dt class="paramhead"><a name="FCN" id="FCN"/>1: &#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;(that is the second derivatives <m:math><m:msubsup><m:mi>y</m:mi><m:mi>i</m:mi><m:mrow><m:mo>&#8242;</m:mo><m:mo>&#8242;</m:mo></m:mrow></m:msubsup></m:math>) for given values of its arguments <m:math><m:mi>x</m:mi></m:math>, <m:math><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mn>2</m:mn></m:msub><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:maction actiontype="link" dsi:type="simple" dsi:href="#FCN_NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction></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/d02laf.xml#FCN_NEQ">NEQ</a>, <a class="arg" href="../D02/d02laf.xml#FCN_T">T</a>, <a class="arg" href="../D02/d02laf.xml#FCN_Y">Y</a>, <a class="arg" href="../D02/d02laf.xml#FCN_F">F</a>)</td></tr><tr><td class="tdfspec1">INTEGER</td><td class="tdfspec2">NEQ</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">T, Y(NEQ), F(NEQ)</td></tr></table>
<dl><dt class="paramhead"><a name="FCN_NEQ" id="FCN_NEQ"/>1: &#160;&#160;&#8194; NEQ &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: 

the number of differential equations.</div></dd><dt class="paramhead"><a name="FCN_T" id="FCN_T"/>2: &#160;&#160;&#8194; T &#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"/>3: &#160;&#160;&#8194; Y(<a class="arg" href="../D02/d02laf.xml#FCN_NEQ">NEQ</a>) &#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:maction actiontype="link" dsi:type="simple" dsi:href="#FCN_NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction></m:math>.</div></dd><dt class="paramhead"><a name="FCN_F" id="FCN_F"/>4: &#160;&#160;&#8194; F(<a class="arg" href="../D02/d02laf.xml#FCN_NEQ">NEQ</a>) &#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:maction actiontype="link" dsi:type="simple" dsi:href="#FCN_NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction></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 D02LAF 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="NEQ" id="NEQ"/>2: &#160;&#160;&#8194; NEQ &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: 

the number of second-order ordinary differential equations to be solved by D02LAF. It must contain the same value as the parameter <a class="arg" href="#NEQ">NEQ</a> used in a prior call to <a class="rout" href="../D02/d02lxf.xml">D02LXF</a>.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>1</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="T" id="T"/>3: &#160;&#160;&#8194; T &#8211; <span class="bitalic">double precision</span><span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the initial value of the independent variable <m:math><m:mi>x</m:mi></m:math>.</div>
<div class="paramtext"><i>On exit</i>: the value of the independent variable, which is usually <a class="arg" href="#TEND">TEND</a>, unless an error has occurred or the code is operating in one-step mode. If the integration is to be continued, possibly with a new value for <a class="arg" href="#TEND">TEND</a>, <a class="arg" href="#T">T</a> must not be changed.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#T"><m:mi mathcolor="#EE0000" mathvariant="bold">T</m:mi></m:maction><m:mo>&#8800;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#TEND"><m:mi mathcolor="#EE0000" mathvariant="bold">TEND</m:mi></m:maction></m:math>.
</div></dd><dt class="paramhead"><a name="TEND" id="TEND"/>4: &#160;&#160;&#8194; TEND &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the end point of the range of integration. If <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#TEND"><m:mi mathcolor="#EE0000" mathvariant="bold">TEND</m:mi></m:maction><m:mo>&lt;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#T"><m:mi mathcolor="#EE0000" mathvariant="bold">T</m:mi></m:maction></m:math>&#160;on initial entry, integration will proceed in the negative direction. <a class="arg" href="#TEND">TEND</a> may be reset, in the direction of integration, before any continuation call.</div></dd><dt class="paramhead"><a name="Y" id="Y"/>5: &#160;&#160;&#8194; Y(<a class="arg" href="#NEQ">NEQ</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:maction actiontype="link" dsi:type="simple" dsi:href="#NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction></m:msub></m:math>.</div>
<div class="paramtext"><i>On exit</i>: the computed values of the solution at the exit value of <a class="arg" href="#T">T</a>. If the integration is to be continued, possibly with a new value for <a class="arg" href="#TEND">TEND</a>, these values must not be changed.</div></dd><dt class="paramhead"><a name="YP" id="YP"/>6: &#160;&#160;&#8194; YP(<a class="arg" href="#NEQ">NEQ</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 derivatives <m:math><m:msubsup><m:mi>y</m:mi><m:mn>1</m:mn><m:mo>&#8242;</m:mo></m:msubsup><m:mo>,</m:mo><m:msubsup><m:mi>y</m:mi><m:mn>2</m:mn><m:mo>&#8242;</m:mo></m:msubsup><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msubsup><m:mi>y</m:mi><m:maction actiontype="link" dsi:type="simple" dsi:href="#NEQ"><m:mi mathcolor="#EE0000" mathvariant="bold">NEQ</m:mi></m:maction><m:mo>&#8242;</m:mo></m:msubsup></m:math>.</div>
<div class="paramtext"><i>On exit</i>: the computed values of the derivatives at the exit value of <a class="arg" href="#T">T</a>. If the integration is to be continued, possibly with a new value for <a class="arg" href="#TEND">TEND</a>, these values must not be changed.</div></dd><dt class="paramhead"><a name="YDP" id="YDP"/>7: &#160;&#160;&#8194; YDP(<a class="arg" href="#NEQ">NEQ</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On entry</i>: must be unchanged from a previous call to D02LAF.</div>
<div class="paramtext"><i>On exit</i>: the computed values of the second derivative at the exit value of <a class="arg" href="#T">T</a>, unless illegal input is detected, in which case the elements of <a class="arg" href="#YDP">YDP</a> may not have been initialized. If the integration is to be continued, possibly with a new value for <a class="arg" href="#TEND">TEND</a>, these values must not be changed.</div></dd><dt class="paramhead"><a name="RWORK" id="RWORK"/>8: &#160;&#160;&#8194; RWORK(<a class="arg" href="#LRWORK">LRWORK</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Communication Array</span></dt><dd>
<div class="paramtext">This <b>must</b> be the same parameter <a class="arg" href="#RWORK">RWORK</a> as supplied to <a class="rout" href="../D02/d02lxf.xml">D02LXF</a>. It is used to pass information from <a class="rout" href="../D02/d02lxf.xml">D02LXF</a> to D02LAF, and from D02LAF to both <a class="rout" href="../D02/d02lyf.xml">D02LYF</a> and <a class="rout" href="../D02/d02lzf.xml">D02LZF</a>. Therefore the contents of this array <b>must not</b> be changed before the call to D02LAF or calling either of the routines <a class="rout" href="../D02/d02lyf.xml">D02LYF</a> and <a class="rout" href="../D02/d02lzf.xml">D02LZF</a>.</div></dd><dt class="paramhead"><a name="LRWORK" id="LRWORK"/>9: &#160;&#160;&#8194; LRWORK &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the dimension of the array <a class="arg" href="#RWORK">RWORK</a> as declared in the (sub)program from which D02LAF is called.<div class="paramtext">This must be the same parameter <a class="arg" href="#LRWORK">LRWORK</a> as supplied to <a class="rout" href="../D02/d02lxf.xml">D02LXF</a>.</div></div></dd><dt class="paramhead"><a name="IFAIL" id="IFAIL"/>10: &#8194; IFAIL &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd><div class="paramtext"><i>On entry</i>: <a class="arg" href="#IFAIL">IFAIL</a> must be set to <m:math><m:mn>0</m:mn></m:math>, <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>. If you are unfamiliar with this parameter you should refer to <a class="sec" href="../GENINT/essint.xml#library3">Section 3.3</a> in  the Essential Introduction for details.</div>
<div class="paramtext"><i>On exit</i>: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;unless the routine detects an error (see <a class="sec" href="#errors">Section 6</a>).
<div class="paramtext">For environments where it might be inappropriate to halt program execution when an error is detected, the value <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>&#160;is recommended.  If the output of error messages is undesirable, then the value <m:math><m:mn>1</m:mn></m:math>&#160;is recommended.  Otherwise, because for this routine the values of the output parameters may be useful even if <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>&#8800;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;on exit, the recommended value is <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:math>.  <b>When the value <m:math><m:mrow><m:mo>-</m:mo><m:mn mathvariant="bold">1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>&#160;is used it is essential to test the value of <a class="arg" href="#IFAIL">IFAIL</a> on exit.</b></div>
</div></dd></dl><h2 class="standard"><a class="sec" name="errors" id="errors"/>6&#160;&#160;Error Indicators and Warnings</h2>
<div class="paramtext">If on entry <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;or <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">-1</m:mn></m:maction></m:math>, explanatory error messages are output on the current error message unit (as defined by <a class="rout" href="../X04/x04aaf.xml">X04AAF</a>).</div><div class="paramtext">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">Illegal input detected, i.e., one of the following conditions:
<ul class="listind"><li class="listind">on any call, <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#T"><m:mi mathcolor="#EE0000" mathvariant="bold">T</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#TEND"><m:mi mathcolor="#EE0000" mathvariant="bold">TEND</m:mi></m:maction></m:math>, or the value of <a class="arg" href="#NEQ">NEQ</a> or <a class="arg" href="#LRWORK">LRWORK</a> has been altered;</li><li class="listind">on a continuation call, the direction of integration has been changed;</li><li class="listind"><a class="rout" href="../D02/d02lxf.xml">D02LXF</a> had not been called previously, or the previous call to <a class="rout" href="../D02/d02lxf.xml">D02LXF</a> resulted in an error exit.</li></ul>
</div>
<div class="paramtext">This error exit can be caused if elements of <a class="arg" href="#RWORK">RWORK</a> have been overwritten.</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 maximum number of steps has been attempted.  (See parameter <a class="arg" href="../D02/d02lxf.xml#MAXSTP">MAXSTP</a> in <a class="rout" href="../D02/d02lxf.xml">D02LXF</a>.)  If integration is to be continued then you need only reset <a class="arg" href="#IFAIL">IFAIL</a> and call the routine again and a further <a class="arg" href="../D02/d02lxf.xml#MAXSTP">MAXSTP</a> steps will be attempted.</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">In order to satisfy the error requirements, the step size needed is too small for the <span class="bitalic">machine precision</span> being used.</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">The code has detected two successive error exits at the current value of <m:math><m:mi>x</m:mi></m:math>&#160;and cannot proceed.  Check all input variables.</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">The code has detected inefficient use of the integration method.  The step size has been reduced by a significant amount too often in order to hit the output points specified by <a class="arg" href="#TEND">TEND</a>.  (Of the last <m:math><m:mn>100</m:mn></m:math>&#160;or more successful steps more than <m:math><m:mn>10</m:mn><m:mo>%</m:mo></m:math>&#160;are steps with sizes that have had to be reduced by a factor of greater than a half.)</div>
</dd>
</dl><h2 class="standard"><a class="sec" name="accuracy" id="accuracy"/>7&#160;&#160;Accuracy</h2>
<div class="paramtext">The accuracy of integration is determined by the parameters <a class="arg" href="../D02/d02lxf.xml#TOL">TOL</a>, <a class="arg" href="../D02/d02lxf.xml#THRES">THRES</a> and <a class="arg" href="../D02/d02lxf.xml#THRESP">THRESP</a> in a prior call to <a class="rout" href="../D02/d02lxf.xml">D02LXF</a>.  Note that only the local error at each step is controlled by these parameters.  The error estimates obtained are not strict bounds but are usually reliable over one step.  Over a number of steps the overall error may accumulate in various ways, depending on the system.  The code is designed so that a reduction in <a class="arg" href="../D02/d02lxf.xml#TOL">TOL</a> should lead to an approximately proportional reduction in the error.  You are strongly recommended to call D02LAF with more than one value for <a class="arg" href="../D02/d02lxf.xml#TOL">TOL</a> and to compare the results obtained to estimate their accuracy.</div><div class="paramtext">The accuracy obtained depends on the type of error test used.  If the solution oscillates around zero a relative error test should be avoided, whereas if the solution is exponentially increasing an absolute error test should not be used.  For a description of the error test see the specifications of the parameters <a class="arg" href="../D02/d02lxf.xml#TOL">TOL</a>, <a class="arg" href="../D02/d02lxf.xml#THRES">THRES</a> and <a class="arg" href="../D02/d02lxf.xml#THRESP">THRESP</a> in routine document <a class="rout" href="../D02/d02lxf.xml">D02LXF</a>.</div><h2 class="standard"><a class="sec" name="fcomments" id="fcomments"/>8&#160;&#160;Further Comments</h2>
<div class="paramtext">If D02LAF 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>&#160;then the value of <a class="arg" href="../D02/d02lxf.xml#TOL">TOL</a> may be so small that a solution cannot be obtained, in which case the routine should be called again with a larger value for <a class="arg" href="../D02/d02lxf.xml#TOL">TOL</a>.  If the accuracy requested is really needed then you should 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 the solution components will usually be of a large magnitude.  D02LAF could be used in one-step mode to monitor the size of the solution with the aim of trapping the solution before the singularity. In any case numerical integration cannot be continued through a singularity, and analytical treatment may be necessary;</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline">(b)</td>
<td valign="top">if the solution contains fast oscillatory components, the routine will require a very small step size to preserve stability.  This will usually be exhibited by excessive computing time and sometimes 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="#IFeq3"><m:mn mathcolor="#003399" mathvariant="bold">3</m:mn></m:maction></m:math>.  The Runge&#8211;Kutta&#8211;Nystrom methods are not efficient in such cases and you should consider reposing your problem as a system of first-order ordinary differential equations and then using a routine from <a class="chap" href="../D02/d02conts.xml">sub-chapter D02M&#8211;N</a> with the Blend formulae (see <a class="rout" href="../D02/d02nwf.xml">D02NWF</a>).</td>
</tr></table>
D02LAF can be used for producing results at short intervals  (for example, for tabulation), in two ways.  By far the less efficient is to call D02LAF successively over short intervals,  <m:math><m:mi>t</m:mi><m:mo>+</m:mo><m:mfenced separators=""><m:mi>i</m:mi><m:mo>-</m:mo><m:mn>1</m:mn></m:mfenced><m:mo>&#215;</m:mo><m:mi>h</m:mi></m:math>&#160;to <m:math><m:mi>t</m:mi><m:mo>+</m:mo><m:mi>i</m:mi><m:mo>&#215;</m:mo><m:mi>h</m:mi></m:math>, although this is the only way if the higher order method has been selected and precisely <b>not</b> what it is intended for.  A more efficient way,  <b>only</b> for use when the lower order method has been selected,  is to use D02LAF in one-step mode.  The output values of parameters <a class="arg" href="#Y">Y</a>, <a class="arg" href="#YP">YP</a>, <a class="arg" href="#YDP">YDP</a>, <a class="arg" href="#T">T</a> and <a class="arg" href="#RWORK">RWORK</a> are set correctly for a call to <a class="rout" href="../D02/d02lzf.xml">D02LZF</a> to compute the solution and derivative at the required points.</div><h2 class="standard"><a class="sec" name="example" id="example"/>9&#160;&#160;Example</h2>
<div class="paramtext">This example solves the following system (the two body problem)

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mtable>
 <m:mtr>
  <m:mtd columnalign="right"><m:msubsup><m:mi>y</m:mi><m:mn>1</m:mn><m:mrow><m:mo>&#8242;</m:mo><m:mo>&#8242;</m:mo></m:mrow></m:msubsup></m:mtd>
  <m:mtd><m:mo>=</m:mo></m:mtd>
  <m:mtd columnalign="left"><m:mo>-</m:mo><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub><m:mo>/</m:mo><m:msup><m:mfenced separators=""><m:msubsup><m:mi>y</m:mi><m:mn>1</m:mn><m:mn>2</m:mn></m:msubsup><m:mo>+</m:mo><m:msubsup><m:mi>y</m:mi><m:mn>2</m:mn><m:mn>2</m:mn></m:msubsup></m:mfenced><m:mrow><m:mn>3</m:mn><m:mo>/</m:mo><m:mn>2</m:mn></m:mrow></m:msup></m:mtd>
 </m:mtr><m:mtr>
  <m:mtd columnalign="right"><m:msubsup><m:mi>y</m:mi><m:mn>2</m:mn><m:mrow><m:mo>&#8242;</m:mo><m:mo>&#8242;</m:mo></m:mrow></m:msubsup></m:mtd>
  <m:mtd><m:mo>=</m:mo></m:mtd>
  <m:mtd><m:mo>-</m:mo><m:msub><m:mi>y</m:mi><m:mn>2</m:mn></m:msub><m:mo>/</m:mo><m:msup><m:mfenced separators=""><m:msubsup><m:mi>y</m:mi><m:mn>1</m:mn><m:mn>2</m:mn></m:msubsup><m:mo>+</m:mo><m:msubsup><m:mi>y</m:mi><m:mn>2</m:mn><m:mn>2</m:mn></m:msubsup></m:mfenced><m:mrow><m:mn>3</m:mn><m:mo>/</m:mo><m:mn>2</m:mn></m:mrow></m:msup></m:mtd>
 </m:mtr>
</m:mtable>
</m:math></td><td class="formula2"/></tr></table></div>

over the range <m:math><m:mfenced separators="" open="[" close="]"><m:mn>0</m:mn><m:mo>,</m:mo><m:mn>20</m:mn></m:mfenced></m:math>&#160;with initial conditions <m:math><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub><m:mo>=</m:mo><m:mn>1.0</m:mn><m:mo>-</m:mo><m:mi>&#949;</m:mi></m:math>, <m:math><m:msub><m:mi>y</m:mi><m:mn>2</m:mn></m:msub><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>,  <m:math><m:msubsup><m:mi>y</m:mi><m:mn>1</m:mn><m:mo>&#8242;</m:mo></m:msubsup><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>&#160;and <m:math><m:msubsup><m:mi>y</m:mi><m:mn>2</m:mn><m:mo>&#8242;</m:mo></m:msubsup><m:mo>=</m:mo><m:msqrt>
<m:mfenced separators=""><m:mfrac other="display">
  <m:mrow><m:mn>1</m:mn><m:mo>+</m:mo><m:mi>&#949;</m:mi></m:mrow>
  <m:mrow><m:mn>1</m:mn><m:mo>-</m:mo><m:mi>&#949;</m:mi></m:mrow>
 </m:mfrac></m:mfenced>
</m:msqrt></m:math>&#160;where <m:math><m:mi>&#949;</m:mi></m:math>, the eccentricity, is <m:math><m:mn>0.5</m:mn></m:math>.  The system is solved using the lower order method with relative local error tolerances <m:math><m:mtext>1.0D&#8722;4</m:mtext></m:math>&#160;and <m:math><m:mtext>1.0D&#8722;5</m:mtext></m:math>&#160;and default threshold tolerances.  D02LAF is used in one-step mode  (<m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="../D02/d02lxf.xml#ONESTP"><m:mi mathcolor="#EE0000" mathvariant="bold">ONESTP</m:mi></m:maction><m:mo>=</m:mo><m:mi mathvariant="normal">.TRUE.</m:mi></m:math>) and <a class="rout" href="../D02/d02lzf.xml">D02LZF</a> provides solution values at intervals of <m:math><m:mn>2.0</m:mn></m:math>.</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/d02lafe.f">Program Text (d02lafe.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/d02lafe.r">Program Results (d02lafe.r)</a></p><div class="figure"><a name="d02laf-plot" id="d02laf-plot"/><img src="../figures/d02laf-plot.png" alt="Example Program Plot for d02laf-plot"/></div>
<hr/><div><a class="rout" href="../../pdf/D02/d02laf.pdf">D02LAF (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>
