<?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>C05NDF : 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/C05/c05ndf.pdf">C05NDF (PDF version)</a></div><div><a class="chap" href="c05conts.xml">C05 Chapter Contents</a></div><div><a class="chapint" href="c05intro.xml">C05 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/>C05NDF</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">C05NDF is a comprehensive reverse communication routine to find a solution of a system of nonlinear equations by a modification of the Powell hybrid method.</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;C05NDF&#160;(</td><td class="tdfspec2"><a class="arg" href="#IREVCM">IREVCM</a>, <a class="arg" href="#N">N</a>, <a class="arg" href="#X">X</a>, <a class="arg" href="#FVEC">FVEC</a>, <a class="arg" href="#XTOL">XTOL</a>, <a class="arg" href="#ML">ML</a>, <a class="arg" href="#MU">MU</a>, <a class="arg" href="#EPSFCN">EPSFCN</a>, <a class="arg" href="#DIAG">DIAG</a>, <a class="arg" href="#MODE">MODE</a>, <a class="arg" href="#FACTOR">FACTOR</a>, <a class="arg" href="#FJAC">FJAC</a>, <a class="arg" href="#LDFJAC">LDFJAC</a>, <a class="arg" href="#R">R</a>, <a class="arg" href="#LR">LR</a>, <a class="arg" href="#QTF">QTF</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">IREVCM, N, ML, MU, MODE, LDFJAC, LR, IFAIL</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">X(N), FVEC(N), XTOL, EPSFCN, DIAG(N), FACTOR, FJAC(LDFJAC,N), R(LR), QTF(N), W(N,4)</td></tr></table><h2 class="standard"><a class="sec" name="description" id="description"/>3&#160;&#160;Description</h2>
<div class="paramtext">The system of equations is defined as:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
 <m:msub><m:mi>f</m:mi><m:mi>i</m:mi></m:msub>
 <m:mfenced separators=""><m:msub><m:mi>x</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:msub><m:mi>x</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>x</m:mi><m:mi>n</m:mi></m:msub></m:mfenced>
 <m:mo>=</m:mo>
 <m:mn>0</m:mn>
 <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>n</m:mi>
 <m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

C05NDF is based on the MINPACK routine HYBRD (see <a class="ref" href="#ref004">Mor&#233; <span class="italic">et al.</span> (1980)</a>).  It chooses the correction at each step as a convex combination of the Newton and scaled gradient directions.  Under reasonable conditions this guarantees global convergence for starting points far from the solution and a fast rate of convergence.  The Jacobian is updated by the rank-1 method of Broyden.  At the starting point the Jacobian is approximated by forward differences, but these are not used again until the rank-1 method fails to produce satisfactory progress.  For more details see <a class="ref" href="#ref005">Powell (1970)</a>.</div><h2 class="standard"><a class="sec" name="references" id="references"/>4&#160;&#160;References</h2><div class="paramtext"><a name="ref004" id="ref004"/>Mor&#233; J J, Garbow B S and Hillstrom K E (1980)  User guide for MINPACK-1 <i>Technical Report ANL-80-74</i> Argonne National Laboratory </div>
<div class="paramtext"><a name="ref005" id="ref005"/>Powell M J D (1970)  A hybrid method for nonlinear algebraic equations <i>Numerical Methods for Nonlinear Algebraic Equations</i> (ed P Rabinowitz) Gordon and Breach </div><h2 class="standard"><a class="sec" name="parameters" id="parameters"/>5&#160;&#160;Parameters</h2>
<div class="paramtext"><b>Note:</b> this routine uses <b>reverse communication.</b> Its use involves an initial entry, intermediate exits and re-entries, and a final exit, as indicated by the <b>parameter <a class="arg" href="#IREVCM">IREVCM</a></b>. Between intermediate exits and re-entries, <b>all parameters other than</b> <b><a class="arg" href="#FVEC">FVEC</a> must remain unchanged</b>.</div><dl><dt class="paramhead"><a name="IREVCM" id="IREVCM"/>1: &#160;&#160;&#8194; IREVCM &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On initial entry</i>: must have the value <m:math><m:mn>0</m:mn></m:math>.</div>
<div class="paramtext"><i>On intermediate exit</i>:
specifies what action you must take before re-entering C05NDF with <a class="arg" href="#IREVCM">IREVCM</a> <b>unchanged</b>.  The value of <a class="arg" href="#IREVCM">IREVCM</a> should be interpreted as follows: 

<dl>
<dt class="paramval"><m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#IREVCM"><m:mi mathcolor="#EE0000" mathvariant="bold">IREVCM</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn>
</m:math></dt>
<dd>Indicates the start of a new iteration.  No action is required by you, but <a class="arg" href="#X">X</a> and <a class="arg" href="#FVEC">FVEC</a> are available for printing.</dd>
<dt class="paramval"><m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#IREVCM"><m:mi mathcolor="#EE0000" mathvariant="bold">IREVCM</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn>
</m:math></dt>
<dd>Indicates that before re-entry to C05NDF, <a class="arg" href="#FVEC">FVEC</a> must contain the function values <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>.</dd></dl>
</div>
<div class="paramtext"><i>On final exit</i>: <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#IREVCM"><m:mi mathcolor="#EE0000" mathvariant="bold">IREVCM</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn>
</m:math>, and the algorithm has terminated.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IREVCM"><m:mi mathcolor="#EE0000" mathvariant="bold">IREVCM</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn></m:math>, <m:math><m:mn>1</m:mn></m:math>&#160;or <m:math><m:mn>2</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="N" id="N"/>2: &#160;&#160;&#8194; N &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On initial entry</i>: 
  
  
  

<m:math><m:mi>n</m:mi></m:math>, the number of equations.


</div><div class="paramtext"><i>Constraint</i>:
  <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction><m:mo>&gt;</m:mo><m:mn>0</m:mn>
</m:math>.
</div></dd><dt class="paramhead"><a name="X" id="X"/>3: &#160;&#160;&#8194; X(<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 initial entry</i>: an initial guess at the solution vector.</div>
<div class="paramtext"><i>On intermediate exit</i>:
contains the current point.</div>
<div class="paramtext"><i>On final exit</i>: the final estimate of the solution vector.</div></dd><dt class="paramhead"><a name="FVEC" id="FVEC"/>4: &#160;&#160;&#8194; FVEC(<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 initial entry</i>: need not be set.</div>
<div class="paramtext"><i>On intermediate re-entry</i>: if <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#IREVCM"><m:mi mathcolor="#EE0000" mathvariant="bold">IREVCM</m:mi></m:maction><m:mo>&#8800;</m:mo><m:mn>2</m:mn>
</m:math>, <a class="arg" href="#FVEC">FVEC</a> must not be changed.
<div class="paramtext">If <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#IREVCM"><m:mi mathcolor="#EE0000" mathvariant="bold">IREVCM</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn>
</m:math>, <a class="arg" href="#FVEC">FVEC</a> must be set to the values of the functions computed at the current point <a class="arg" href="#X">X</a>.</div>
</div>
<div class="paramtext"><i>On final exit</i>: the function values at the final point, <a class="arg" href="#X">X</a>.</div></dd><dt class="paramhead"><a name="XTOL" id="XTOL"/>5: &#160;&#160;&#8194; XTOL &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On initial entry</i>: the accuracy in <a class="arg" href="#X">X</a> to which the solution is required.</div>
<div class="paramtext"><i>Suggested value</i>:
  the square root of the <span class="bitalic">machine precision</span>.

</div><div class="paramtext"><i>Constraint</i>:
  <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#XTOL"><m:mi mathcolor="#EE0000" mathvariant="bold">XTOL</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>0.0</m:mn>
</m:math>.
</div></dd><dt class="paramhead"><a name="ML" id="ML"/>6: &#160;&#160;&#8194; ML &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On initial entry</i>: the number of subdiagonals within the band of the Jacobian matrix.  (If the Jacobian is not banded, or you are unsure, set <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#ML"><m:mi mathcolor="#EE0000" mathvariant="bold">ML</m:mi></m:maction><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:mo>-</m:mo><m:mn>1</m:mn>
</m:math>.)</div><div class="paramtext"><i>Constraint</i>:
  <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#ML"><m:mi mathcolor="#EE0000" mathvariant="bold">ML</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>0</m:mn>
</m:math>.
</div></dd><dt class="paramhead"><a name="MU" id="MU"/>7: &#160;&#160;&#8194; MU &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On initial entry</i>: the number of superdiagonals within the band of the Jacobian matrix.  (If the Jacobian is not banded, or you are unsure, set <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#MU"><m:mi mathcolor="#EE0000" mathvariant="bold">MU</m:mi></m:maction><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:mo>-</m:mo><m:mn>1</m:mn>
</m:math>.)</div><div class="paramtext"><i>Constraint</i>:
  <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#MU"><m:mi mathcolor="#EE0000" mathvariant="bold">MU</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>0</m:mn>
</m:math>.
</div></dd><dt class="paramhead"><a name="EPSFCN" id="EPSFCN"/>8: &#160;&#160;&#8194; EPSFCN &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On initial entry</i>: the order of the largest relative error in the functions.  It is used in determining a suitable step for a forward difference approximation to the Jacobian.  If <a class="arg" href="#EPSFCN">EPSFCN</a> is less than <span class="bitalic">machine precision</span> then <span class="bitalic">machine precision</span> is used.  Consequently a value of <m:math><m:mn>0.0</m:mn></m:math>&#160;will often be suitable.</div>
<div class="paramtext"><i>Suggested value</i>:
  <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#EPSFCN"><m:mi mathcolor="#EE0000" mathvariant="bold">EPSFCN</m:mi></m:maction><m:mo>=</m:mo><m:mn>0.0</m:mn>
</m:math>.</div></dd><dt class="paramhead"><a name="DIAG" id="DIAG"/>9: &#160;&#160;&#8194; DIAG(<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 initial entry</i>: if <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#MODE"><m:mi mathcolor="#EE0000" mathvariant="bold">MODE</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn>
</m:math>, <a class="arg" href="#DIAG">DIAG</a> must contain multiplicative scale factors for the variables.</div><div class="paramtext"><i>Constraint</i>:
  <m:math>
 <m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#DIAG"><m:mi mathcolor="#EE0000" mathvariant="bold">DIAG</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi mathvariant="italic">i</m:mi></m:mfenced></m:mrow><m:mo>&gt;</m:mo><m:mn>0.0</m:mn>
</m:math>,  for <m:math><m:mi mathvariant="italic">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>n</m:mi></m:math>.</div>
<div class="paramtext"><i>On intermediate exit</i>:
the scale factors actually used (computed internally if <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#MODE"><m:mi mathcolor="#EE0000" mathvariant="bold">MODE</m:mi></m:maction><m:mo>&#8800;</m:mo><m:mn>2</m:mn>
</m:math>).</div></dd><dt class="paramhead"><a name="MODE" id="MODE"/>10: &#8194; MODE &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On initial entry</i>: indicates whether or not you have provided scaling factors in <a class="arg" href="#DIAG">DIAG</a>.  If <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#MODE"><m:mi mathcolor="#EE0000" mathvariant="bold">MODE</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn>
</m:math>&#160;the scale factors must be supplied in <a class="arg" href="#DIAG">DIAG</a>.  Otherwise, the variables will be scaled internally.</div></dd><dt class="paramhead"><a name="FACTOR" id="FACTOR"/>11: &#8194; FACTOR &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On initial entry</i>: a quantity to be used in determining the initial step bound.  In most cases, <a class="arg" href="#FACTOR">FACTOR</a> should lie between <m:math><m:mn>0.1</m:mn></m:math>&#160;and <m:math><m:mn>100.0</m:mn></m:math>.  (The step bound is <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#FACTOR"><m:mi mathcolor="#EE0000" mathvariant="bold">FACTOR</m:mi></m:maction><m:mo>&#215;</m:mo><m:msub><m:mfenced open="&#8214;" close="&#8214;" separators=""><m:maction actiontype="link" dsi:type="simple" dsi:href="#DIAG"><m:mi mathcolor="#EE0000" mathvariant="bold">DIAG</m:mi></m:maction><m:mo>&#215;</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:mn>2</m:mn></m:msub>
</m:math>&#160;if this is nonzero; otherwise the bound is <a class="arg" href="#FACTOR">FACTOR</a>.)</div>
<div class="paramtext"><i>Suggested value</i>:
  <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#FACTOR"><m:mi mathcolor="#EE0000" mathvariant="bold">FACTOR</m:mi></m:maction><m:mo>=</m:mo><m:mn>100.0</m:mn>
</m:math>.</div><div class="paramtext"><i>Constraint</i>:
  <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#FACTOR"><m:mi mathcolor="#EE0000" mathvariant="bold">FACTOR</m:mi></m:maction><m:mo>&gt;</m:mo><m:mn>0.0</m:mn>
</m:math>.
</div></dd><dt class="paramhead"><a name="FJAC" id="FJAC"/>12: &#8194; FJAC(<a class="arg" href="#LDFJAC">LDFJAC</a>,<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 initial entry</i>: need not be set.</div>
<div class="paramtext"><i>On intermediate exit</i>:
must not be changed.</div>
<div class="paramtext"><i>On final exit</i>: the orthogonal matrix <m:math><m:mi>Q</m:mi></m:math>&#160;produced by the <m:math>
 <m:mi>Q</m:mi><m:mi>R</m:mi>
</m:math>&#160;factorization of the final approximate Jacobian.</div></dd><dt class="paramhead"><a name="LDFJAC" id="LDFJAC"/>13: &#8194; LDFJAC &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On initial entry</i>: the first dimension of the array <a class="arg" href="#FJAC">FJAC</a> as declared in the (sub)program from which C05NDF is called.</div><div class="paramtext"><i>Constraint</i>:
  <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#LDFJAC"><m:mi mathcolor="#EE0000" mathvariant="bold">LDFJAC</m:mi></m:maction><m:mo>&#8805;</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="R" id="R"/>14: &#8194; R(<a class="arg" href="#LR">LR</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On initial entry</i>: need not be set.</div>
<div class="paramtext"><i>On intermediate exit</i>:
must not be changed.</div><div class="paramtext"><i>On final exit</i>: the upper triangular matrix <m:math><m:mi>R</m:mi></m:math>&#160;produced by the <m:math>
 <m:mi>Q</m:mi><m:mi>R</m:mi>
</m:math>&#160;factorization of the final approximate Jacobian, stored row-wise.</div></dd><dt class="paramhead"><a name="LR" id="LR"/>15: &#8194; LR &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On initial entry</i>: the dimension of the array <a class="arg" href="#R">R</a> as declared in the (sub)program from which C05NDF is called.</div><div class="paramtext"><i>Constraint</i>:
  <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#LR"><m:mi mathcolor="#EE0000" mathvariant="bold">LR</m:mi></m:maction><m:mo>&#8805;</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>&#215;</m:mo><m:mfenced separators=""><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>1</m:mn></m:mfenced><m:mo>/</m:mo><m:mn>2</m:mn>
</m:math>.
</div></dd><dt class="paramhead"><a name="QTF" id="QTF"/>16: &#8194; QTF(<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 initial entry</i>: need not be set.</div>
<div class="paramtext"><i>On intermediate exit</i>:
must not be changed.</div> 
<div class="paramtext"><i>On final exit</i>: the vector <m:math>
 <m:msup><m:mi>Q</m:mi><m:mi mathvariant="normal">T</m:mi></m:msup><m:mi>f</m:mi>
</m:math>.</div></dd><dt class="paramhead"><a name="W" id="W"/>17: &#8194; W(<a class="arg" href="#N">N</a>,<m:math><m:mn>4</m:mn></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Communication Array</span></dt><dt class="paramhead"><a name="IFAIL" id="IFAIL"/>18: &#8194; IFAIL &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd><div class="paramtext"><i>On initial 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 final 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>
<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="#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="#XTOL"><m:mi mathcolor="#EE0000" mathvariant="bold">XTOL</m:mi></m:maction><m:mo>&lt;</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="#ML"><m:mi mathcolor="#EE0000" mathvariant="bold">ML</m:mi></m:maction><m:mo>&lt;</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="#MU"><m:mi mathcolor="#EE0000" mathvariant="bold">MU</m:mi></m:maction><m:mo>&lt;</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="#FACTOR"><m:mi mathcolor="#EE0000" mathvariant="bold">FACTOR</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="#LDFJAC"><m:mi mathcolor="#EE0000" mathvariant="bold">LDFJAC</m:mi></m:maction><m:mo>&lt;</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><tr><td class="ifail1">or</td><td class="ifail2-90"><m:math>
   <m:maction actiontype="link" dsi:type="simple" dsi:href="#LR"><m:mi mathcolor="#EE0000" mathvariant="bold">LR</m:mi></m:maction><m:mo>&lt;</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>&#215;</m:mo>
   <m:mfenced separators=""><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>1</m:mn></m:mfenced>
   <m:mo>/</m:mo>
   <m:mn>2</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="#MODE"><m:mi mathcolor="#EE0000" mathvariant="bold">MODE</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn>
  </m:math>&#160;and <m:math>
   <m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#DIAG"><m:mi mathcolor="#EE0000" mathvariant="bold">DIAG</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi></m:mfenced></m:mrow><m:mo>&#8804;</m:mo><m:mn>0.0</m:mn>
  </m:math>&#160;for some <m:math><m:mi>i</m:mi></m:math>, <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="#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>
<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="#IREVCM"><m:mi mathcolor="#EE0000" mathvariant="bold">IREVCM</m:mi></m:maction><m:mo>&lt;</m:mo><m:mn>0</m:mn>
  </m:math>&#160;or <m:math>
   <m:maction actiontype="link" dsi:type="simple" dsi:href="#IREVCM"><m:mi mathcolor="#EE0000" mathvariant="bold">IREVCM</m:mi></m:maction><m:mo>&gt;</m:mo><m:mn>2</m:mn>
  </m:math>.</td></tr></table>
</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 further improvement in the approximate solution <a class="arg" href="#X">X</a> is possible; <a class="arg" href="#XTOL">XTOL</a> is too small.</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 iteration is not making good progress, as measured by the improvement from the last five Jacobian evaluations.</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 iteration is not making good progress, as measured by the improvement from the last <m:math><m:mn>10</m:mn></m:math>&#160;iterations.</div></dd>
</dl>
<div class="paramtext">The values <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;and <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="#IFeq5"><m:mn mathcolor="#003399" mathvariant="bold">5</m:mn></m:maction></m:math>&#160;may indicate that the system does not have a zero, or that the solution is very close to the origin (see <a class="sec" href="#accuracy">Section 7</a>).  Otherwise, rerunning C05NDF from a different starting point may avoid the region of difficulty.</div><h2 class="standard"><a class="sec" name="accuracy" id="accuracy"/>7&#160;&#160;Accuracy</h2>
<div class="paramtext">If <m:math>
 <m:mover><m:mi>x</m:mi><m:mo>^</m:mo></m:mover>
</m:math>&#160;is the true solution and <m:math><m:mi>D</m:mi></m:math>&#160;denotes the diagonal matrix whose entries are defined by the array <a class="arg" href="#DIAG">DIAG</a>, then C05NDF tries to ensure that

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
 <m:msub><m:mfenced open="&#8214;" close="&#8214;" separators="">
  <m:mi>D</m:mi>
  <m:mfenced separators=""><m:mi>x</m:mi><m:mo>-</m:mo><m:mover><m:mi>x</m:mi><m:mo>^</m:mo></m:mover></m:mfenced>
 </m:mfenced><m:mn>2</m:mn></m:msub>
 <m:mo>&#8804;</m:mo>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#XTOL"><m:mi mathcolor="#EE0000" mathvariant="bold">XTOL</m:mi></m:maction>
 <m:mo>&#215;</m:mo>
 <m:msub><m:mfenced open="&#8214;" close="&#8214;" separators="">
  <m:mi>D</m:mi>
  <m:mover><m:mi>x</m:mi><m:mo>^</m:mo></m:mover>
 </m:mfenced><m:mn>2</m:mn></m:msub>
 <m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

If this condition is satisfied with <m:math>
 <m:maction actiontype="link" dsi:type="simple" dsi:href="#XTOL"><m:mi mathcolor="#EE0000" mathvariant="bold">XTOL</m:mi></m:maction>
 <m:mo>=</m:mo>
 <m:msup><m:mn>10</m:mn><m:mrow><m:mo>-</m:mo><m:mi>k</m:mi></m:mrow></m:msup>
</m:math>, then the larger components of <m:math>
 <m:mi>D</m:mi><m:mi>x</m:mi>
</m:math>&#160;have <m:math><m:mi>k</m:mi></m:math>&#160;significant decimal digits.  There is a danger that the smaller components of <m:math>
 <m:mi>D</m:mi><m:mi>x</m:mi>
</m:math>&#160;may have large relative errors, but the fast rate of convergence of C05NDF usually avoids this possibility.</div><div class="paramtext">If <a class="arg" href="#XTOL">XTOL</a> is less than <span class="bitalic">machine precision</span> and the above test is satisfied with the <span class="bitalic">machine precision</span> in place of <a class="arg" href="#XTOL">XTOL</a>, then the routine exits 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>.</div><div class="paramtext"><b>Note:</b>&#160; this convergence test is based purely on relative error, and may not indicate convergence if the solution is very close to the origin.</div><div class="paramtext">The test assumes that the functions are reasonably well behaved.  If this condition is not satisfied, then C05NDF may incorrectly indicate convergence.  The validity of the answer can be checked, for example, by rerunning C05NDF with a tighter tolerance.</div><h2 class="standard"><a class="sec" name="fcomments" id="fcomments"/>8&#160;&#160;Further Comments</h2>
<div class="paramtext">The time required by C05NDF to solve a given problem depends on <m:math><m:mi>n</m:mi></m:math>, the behaviour of the functions, the accuracy requested and the starting point.  The number of arithmetic operations executed by C05NDF to process the evaluation of functions in the main program in each exit is about <m:math>
 <m:mn>11.5</m:mn><m:mo>&#215;</m:mo><m:msup><m:mi>n</m:mi><m:mn>2</m:mn></m:msup>
</m:math>.  The timing of C05NDF will be strongly influenced by the time spent in the evaluation of the functions.</div><div class="paramtext">Ideally the problem should be scaled so that, at the solution, the function values are of comparable magnitude.</div><div class="paramtext">The number of function evaluations required to evaluate the Jacobian may be reduced if you can specify <a class="arg" href="#ML">ML</a> and <a class="arg" href="#MU">MU</a>.</div><h2 class="standard"><a class="sec" name="example" id="example"/>9&#160;&#160;Example</h2>
<div class="paramtext">This example determines the values <m:math>
 <m:msub><m:mi>x</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>x</m:mi><m:mn>9</m:mn></m:msub>
</m:math>&#160;which satisfy the tridiagonal equations:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mtable columnalign="right center left">
 <m:mtr>
  <m:mtd><m:mfenced separators=""><m:mn>3</m:mn><m:mo>-</m:mo><m:mn>2</m:mn><m:msub><m:mi>x</m:mi><m:mn>1</m:mn></m:msub></m:mfenced><m:msub><m:mi>x</m:mi><m:mn>1</m:mn></m:msub><m:mo>-</m:mo><m:mn>2</m:mn><m:msub><m:mi>x</m:mi><m:mn>2</m:mn></m:msub></m:mtd>
  <m:mtd><m:mo>=</m:mo></m:mtd>
  <m:mtd><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>,</m:mtext></m:mtd>
 </m:mtr><m:mtr>
  <m:mtd><m:mo>-</m:mo><m:msub><m:mi>x</m:mi><m:mrow><m:mi>i</m:mi><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:msub><m:mo>+</m:mo><m:mfenced separators=""><m:mn>3</m:mn><m:mo>-</m:mo><m:mn>2</m:mn><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:mfenced><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub><m:mo>-</m:mo><m:mn>2</m:mn><m:msub><m:mi>x</m:mi><m:mrow><m:mi>i</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:mrow></m:msub></m:mtd>
  <m:mtd><m:mo>=</m:mo></m:mtd>
  <m:mtd><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>, &#8195;</m:mtext><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mn>3</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mn>8</m:mn></m:mtd>
 </m:mtr><m:mtr>
  <m:mtd><m:mo>-</m:mo><m:msub><m:mi>x</m:mi><m:mn>8</m:mn></m:msub><m:mo>+</m:mo><m:mfenced separators=""><m:mn>3</m:mn><m:mo>-</m:mo><m:mn>2</m:mn><m:msub><m:mi>x</m:mi><m:mn>9</m:mn></m:msub></m:mfenced><m:msub><m:mi>x</m:mi><m:mn>9</m:mn></m:msub></m:mtd>
  <m:mtd><m:mo>=</m:mo></m:mtd>
  <m:mtd><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>.</m:mtext></m:mtd>
 </m:mtr>
</m:mtable>
</m:math></td><td class="formula2"/></tr></table></div></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/c05ndfe.f">Program Text (c05ndfe.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/c05ndfe.r">Program Results (c05ndfe.r)</a></p>
<hr/><div><a class="rout" href="../../pdf/C05/c05ndf.pdf">C05NDF (PDF version)</a></div><div><a class="chap" href="c05conts.xml">C05 Chapter Contents</a></div><div><a class="chapint" href="c05intro.xml">C05 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>
