<?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>E04XAF/E04XAA : 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/E04/e04xaf.pdf">E04XAF/E04XAA (PDF version)</a></div><div><a class="chap" href="e04conts.xml">E04 Chapter Contents</a></div><div><a class="chapint" href="e04intro.xml">E04 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/>E04XAF/E04XAA</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="htmltoc" onclick="showLevel('tocspecification');"><span class="htmltocplus" id="tocspecificationplus">+</span><span class="htmltocminus" id="tocspecificationminus">&#8722;</span></span>
<a class="htmltoc" href="#specification">2&#160;&#160;<b>Specification</b></a>
<div class="htmltocitem" id="tocspecification">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#routFspec">2.1&#160;&#160;<b>Specification for E04XAF</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#routAspec">2.2&#160;&#160;<b>Specification for E04XAA</b></a>
</div>
</div>
</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="htmltoc" onclick="showLevel('tocfcomments');"><span class="htmltocplus" id="tocfcommentsplus">+</span><span class="htmltocminus" id="tocfcommentsminus">&#8722;</span></span>
<a class="htmltoc" href="#fcomments">8&#160;&#160;<b>Further Comments</b></a>
<div class="htmltocitem" id="tocfcomments">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#fc-printedoutput">8.1&#160;&#160;<b>Description of the Printed Output</b></a>
</div>
</div>
</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">E04XAF/E04XAA computes an approximation to the gradient vector and/or the Hessian matrix for use in conjunction with, or following the use of an optimization routine (such as <a class="rout" href="../E04/e04uff.xml">E04UFF/E04UFA</a>).</div>
<div class="paramtext">E04XAA is a version of E04XAF that has additional parameters in order to make it safe for use in multithreaded applications (see <a class="sec" href="#parameters">Section 5</a>).  The initialization routine <a class="rout" href="../E04/e04wbf.xml">E04WBF</a> <b>must</b> have been called before calling E04XAA.</div><h2 class="standard"><a class="sec" name="specification" id="specification"/>2&#160;&#160;Specification</h2><h3 class="standard"><a class="sec" name="routFspec" id="routFspec"/>2.1&#160;&#160;Specification for E04XAF</h3>
<table class="fspec"><tr><td class="tdfspec1">SUBROUTINE&#160;E04XAF&#160;(</td><td class="tdfspec2"><a class="arg" href="#MSGLVL">MSGLVL</a>, <a class="arg" href="#N">N</a>, <a class="arg" href="#EPSRF">EPSRF</a>, <a class="arg" href="#X">X</a>, <a class="arg" href="#MODE">MODE</a>, <a class="arg" href="#OBJFUN">OBJFUN</a>, <a class="arg" href="#LDH">LDH</a>, <a class="arg" href="#HFORW">HFORW</a>, <a class="arg" href="#OBJF">OBJF</a>, <a class="arg" href="#OBJGRD">OBJGRD</a>, <a class="arg" href="#HCNTRL">HCNTRL</a>, <a class="arg" href="#H">H</a>, <a class="arg" href="#IWARN">IWARN</a>, <a class="arg" href="#WORK">WORK</a>, <a class="arg" href="#IUSER">IUSER</a>, <a class="arg" href="#RUSER">RUSER</a>, <a class="arg" href="#INFO">INFO</a>, <a class="arg" href="#IFAIL">IFAIL</a>)</td></tr><tr><td class="tdfspec1">INTEGER</td><td class="tdfspec2">MSGLVL, N, MODE, LDH, IWARN, IUSER(*), INFO(N), IFAIL</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">EPSRF, X(N), HFORW(N), OBJF, OBJGRD(N), HCNTRL(N), H(LDH,*), WORK(*), RUSER(*)</td></tr><tr><td class="tdfspec1">EXTERNAL</td><td class="tdfspec2">OBJFUN</td></tr></table><h3 class="standard"><a class="sec" name="routAspec" id="routAspec"/>2.2&#160;&#160;Specification for E04XAA</h3>
<table class="fspec"><tr><td class="tdfspec1">SUBROUTINE&#160;E04XAA&#160;(</td><td class="tdfspec2"><a class="arg" href="#MSGLVL">MSGLVL</a>, <a class="arg" href="#N">N</a>, <a class="arg" href="#EPSRF">EPSRF</a>, <a class="arg" href="#X">X</a>, <a class="arg" href="#MODE">MODE</a>, <a class="arg" href="#OBJFUN">OBJFUN</a>, <a class="arg" href="#LDH">LDH</a>, <a class="arg" href="#HFORW">HFORW</a>, <a class="arg" href="#OBJF">OBJF</a>, <a class="arg" href="#OBJGRD">OBJGRD</a>, <a class="arg" href="#HCNTRL">HCNTRL</a>, <a class="arg" href="#H">H</a>, <a class="arg" href="#IWARN">IWARN</a>, <a class="arg" href="#WORK">WORK</a>, <a class="arg" href="#IUSER">IUSER</a>, <a class="arg" href="#RUSER">RUSER</a>, <a class="arg" href="#INFO">INFO</a>, <a class="arg" href="#LWSAV">LWSAV</a>, <a class="arg" href="#IWSAV">IWSAV</a>, <a class="arg" href="#RWSAV">RWSAV</a>, <a class="arg" href="#IFAIL">IFAIL</a>)</td></tr><tr><td class="tdfspec1">INTEGER</td><td class="tdfspec2">MSGLVL, N, MODE, LDH, IWARN, IUSER(*), INFO(N), IWSAV(1), IFAIL</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">EPSRF, X(N), HFORW(N), OBJF, OBJGRD(N), HCNTRL(N), H(LDH,*), WORK(*), RUSER(*), RWSAV(1)</td></tr><tr><td class="tdfspec1">LOGICAL</td><td class="tdfspec2">LWSAV(1)</td></tr><tr><td class="tdfspec1">EXTERNAL</td><td class="tdfspec2">OBJFUN</td></tr></table><h2 class="standard"><a class="sec" name="description" id="description"/>3&#160;&#160;Description</h2>
<div class="paramtext">E04XAF/E04XAA is similar to routine FDCALC described in <a class="ref" href="#ref442">Gill <span class="italic">et al.</span> (1983a)</a>.  It should be noted that this routine aims to compute sufficiently accurate estimates of the derivatives for use with an optimization algorithm.  If you require more accurate estimates you should refer to <a class="chap" href="../D04/d04conts.xml">Chapter D04</a>.</div><div class="paramtext">E04XAF/E04XAA computes finite-difference approximations to the gradient vector and the Hessian matrix for a given function.  The simplest approximation involves the forward-difference formula, in which the derivative <m:math><m:msup><m:mi>f</m:mi><m:mo>&#8242;</m:mo></m:msup><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;of a univariate function <m:math><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;is approximated by the quantity

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:msub><m:mi>&#961;</m:mi><m:mi>F</m:mi></m:msub><m:mfenced separators=""><m:mi>f</m:mi><m:mo>,</m:mo><m:mi>h</m:mi></m:mfenced><m:mo>=</m:mo><m:mfrac><m:mrow><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>+</m:mo><m:mi>h</m:mi></m:mfenced><m:mo>-</m:mo><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:mrow><m:mi>h</m:mi></m:mfrac>
</m:math></td><td class="formula2"/></tr></table></div>

for some interval <m:math><m:mi>h</m:mi><m:mo>&gt;</m:mo><m:mn>0</m:mn></m:math>, where the subscript 'F' denotes &#8216;forward-difference&#8217; (see <a class="ref" href="#ref443">Gill <span class="italic">et al.</span> (1983b)</a>).</div><div class="paramtext">To summarize the procedure used by E04XAF/E04XAA (for the case when the objective function is available and you require estimates of gradient values and Hessian matrix diagonal values, i.e., <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>0</m:mn></m:math>) consider a univariate function <m:math><m:mi>f</m:mi></m:math>&#160;at the point <m:math><m:mi>x</m:mi></m:math>.  (In order to obtain the gradient of a multivariate function <m:math><m:mi>F</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>, where <m:math><m:mi>x</m:mi></m:math>&#160;is an <m:math><m:mi>n</m:mi></m:math>-vector, the procedure is applied to each component of <m:math><m:mi>x</m:mi></m:math>, keeping the other components fixed.)  Roughly speaking, the method is based on the fact that the bound on the relative truncation error in the forward-difference approximation tends to be an increasing function of <m:math><m:mi>h</m:mi></m:math>, while the relative condition error bound is generally a decreasing function of <m:math><m:mi>h</m:mi></m:math>, hence changes in <m:math><m:mi>h</m:mi></m:math>&#160;will tend to have opposite effects on these errors (see <a class="ref" href="#ref443">Gill <span class="italic">et al.</span> (1983b)</a>).</div><div class="paramtext">The &#8216;best&#8217; interval <m:math><m:mi>h</m:mi></m:math>&#160;is given by

<div class="formula-eqn"><a name="eqn1" id="eqn1"/><table class="formula-eqn"><tr><td class="formula-eqn"><m:math display="block">
<m:msub><m:mi>h</m:mi><m:mi>F</m:mi></m:msub><m:mo>=</m:mo><m:mn>2</m:mn><m:msqrt><m:mfrac><m:mrow><m:mfenced separators=""><m:mn>1</m:mn><m:mo>+</m:mo><m:mfenced open="|" close="|" separators=""><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:mfenced></m:mfenced><m:msub><m:mi>e</m:mi><m:mi>R</m:mi></m:msub></m:mrow><m:mfenced open="|" close="|" separators=""><m:mi>&#934;</m:mi></m:mfenced></m:mfrac></m:msqrt>
</m:math></td><td class="formula-eqn2">
      (1)
     </td></tr></table></div>

where <m:math><m:mi>&#934;</m:mi></m:math>&#160;is an estimate of <m:math><m:msup><m:mi>f</m:mi><m:mrow><m:mo>&#8242;</m:mo><m:mo>&#8242;</m:mo></m:mrow></m:msup><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>, and <m:math><m:msub><m:mi>e</m:mi><m:mi>R</m:mi></m:msub></m:math>&#160;is an estimate of the relative error associated with computing the function (see Chapter 8 of <a class="ref" href="#ref079">Gill <span class="italic">et al.</span> (1981)</a>).  Given an interval <m:math><m:mi>h</m:mi></m:math>, <m:math><m:mi>&#934;</m:mi></m:math>&#160;is defined by the second-order approximation

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi>&#934;</m:mi><m:mo>=</m:mo><m:mfrac><m:mrow><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>+</m:mo><m:mi>h</m:mi></m:mfenced><m:mo>-</m:mo><m:mn>2</m:mn><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>+</m:mo><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>-</m:mo><m:mi>h</m:mi></m:mfenced></m:mrow><m:msup><m:mi>h</m:mi><m:mn>2</m:mn></m:msup></m:mfrac><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The decision as to whether a given value of <m:math><m:mi>&#934;</m:mi></m:math>&#160;is acceptable involves <m:math><m:mover><m:mi>c</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>&#934;</m:mi></m:mfenced></m:math>, the following bound on the relative condition error in <m:math><m:mi>&#934;</m:mi></m:math>:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mover><m:mi>c</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>&#934;</m:mi></m:mfenced><m:mo>=</m:mo><m:mfrac><m:mrow><m:mn>4</m:mn><m:msub><m:mi>e</m:mi><m:mi>R</m:mi></m:msub><m:mfenced separators=""><m:mn>1</m:mn><m:mo>+</m:mo><m:mfenced open="|" close="|" separators=""><m:mi>f</m:mi></m:mfenced></m:mfenced></m:mrow>
  <m:mrow><m:msup><m:mi>h</m:mi><m:mn>2</m:mn></m:msup><m:mfenced open="|" close="|" separators=""><m:mi>&#934;</m:mi></m:mfenced></m:mrow>
 </m:mfrac>
</m:math></td><td class="formula2"/></tr></table></div>

(When <m:math><m:mi>&#934;</m:mi></m:math>&#160;is zero, <m:math><m:mover><m:mi>c</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>&#934;</m:mi></m:mfenced></m:math>&#160;is taken as an arbitrary large number.)</div><div class="paramtext">The procedure selects the interval <m:math><m:msub><m:mi>h</m:mi><m:mi>&#981;</m:mi></m:msub></m:math>&#160;(to be used in computing <m:math><m:mi>&#934;</m:mi></m:math>) from a sequence of trial intervals <m:math><m:mfenced separators=""><m:msub><m:mi>h</m:mi><m:mi>k</m:mi></m:msub></m:mfenced></m:math>.  The initial trial interval is taken as <m:math><m:mn>10</m:mn><m:mover><m:mi>h</m:mi><m:mo>-</m:mo></m:mover></m:math>, where

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mover><m:mi>h</m:mi><m:mo>-</m:mo></m:mover><m:mo>=</m:mo><m:mn>2</m:mn><m:mfenced separators=""><m:mn>1</m:mn><m:mo>+</m:mo><m:mfenced open="|" close="|" separators=""><m:mi>x</m:mi></m:mfenced></m:mfenced><m:msqrt><m:msub><m:mi>e</m:mi><m:mi>R</m:mi></m:msub></m:msqrt>
</m:math></td><td class="formula2"/></tr></table></div>

unless you specify the initial value to be used.</div><div class="paramtext">The value of <m:math><m:mover><m:mi>c</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>&#934;</m:mi></m:mfenced></m:math>&#160;for a trial value <m:math><m:msub><m:mi>h</m:mi><m:mi>k</m:mi></m:msub></m:math>&#160;is defined as &#8216;acceptable&#8217; if it lies in the interval <m:math><m:mfenced separators="" open="[" close="]"><m:mn>0.001</m:mn><m:mo>,</m:mo><m:mn>0.1</m:mn></m:mfenced></m:math>.  In this case <m:math><m:msub><m:mi>h</m:mi><m:mi>&#981;</m:mi></m:msub></m:math>&#160;is taken as <m:math><m:msub><m:mi>h</m:mi><m:mi>k</m:mi></m:msub></m:math>, and the current value of <m:math><m:mi>&#934;</m:mi></m:math>&#160;is used to compute <m:math><m:msub><m:mi>h</m:mi><m:mi>F</m:mi></m:msub></m:math>&#160;from <a class="eqn" href="#eqn1">(1)</a>.  If <m:math><m:mover><m:mi>c</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>&#934;</m:mi></m:mfenced></m:math>&#160;is unacceptable, the next trial interval is chosen so that the relative condition error bound will either decrease or increase, as required.  If the bound on the relative condition error is too large, a larger interval is used as the next trial value in an attempt to reduce the condition error bound.  On the other hand, if the relative condition error bound is too small, <m:math><m:msub><m:mi>h</m:mi><m:mi>k</m:mi></m:msub></m:math>&#160;is reduced.</div><div class="paramtext">The procedure will fail to produce an acceptable value of <m:math><m:mover><m:mi>c</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>&#934;</m:mi></m:mfenced></m:math>&#160;in two situations.  Firstly, if <m:math><m:msup><m:mi>f</m:mi><m:mrow><m:mo>&#8242;</m:mo><m:mo>&#8242;</m:mo></m:mrow></m:msup><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;is extremely small, then <m:math><m:mover><m:mi>c</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>&#934;</m:mi></m:mfenced></m:math>&#160;may never become small, even for a very large value of the interval.  Alternatively, <m:math><m:mover><m:mi>c</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>&#934;</m:mi></m:mfenced></m:math>&#160;may never exceed <m:math><m:mn>0.001</m:mn></m:math>, even for a very small value of the interval.  This usually implies that <m:math><m:msup><m:mi>f</m:mi><m:mrow><m:mo>&#8242;</m:mo><m:mo>&#8242;</m:mo></m:mrow></m:msup><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;is extremely large, and occurs most often near a singularity.</div><div class="paramtext">As a check on the validity of the estimated first derivative, the procedure provides a comparison of the forward-difference approximation computed with <m:math><m:msub><m:mi>h</m:mi><m:mi>F</m:mi></m:msub></m:math>&#160;(as above) and the central-difference approximation computed with <m:math><m:msub><m:mi>h</m:mi><m:mi>&#981;</m:mi></m:msub></m:math>.  Using the central-difference formula the first derivative can be approximated by

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:msub><m:mi>&#961;</m:mi><m:mi>c</m:mi></m:msub><m:mfenced separators=""><m:mi>f</m:mi><m:mo>,</m:mo><m:mi>h</m:mi></m:mfenced><m:mo>=</m:mo><m:mfrac><m:mrow><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>+</m:mo><m:mi>h</m:mi></m:mfenced><m:mo>-</m:mo><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>-</m:mo><m:mi>h</m:mi></m:mfenced></m:mrow>
  <m:mrow><m:mn>2</m:mn><m:mi>h</m:mi></m:mrow>
 </m:mfrac>
</m:math></td><td class="formula2"/></tr></table></div>

where <m:math><m:mi>h</m:mi><m:mo>&gt;</m:mo><m:mn>0</m:mn></m:math>.  If the values <m:math><m:msub><m:mi>h</m:mi><m:mi>F</m:mi></m:msub></m:math>&#160;and <m:math><m:msub><m:mi>h</m:mi><m:mi>&#981;</m:mi></m:msub></m:math>&#160;do not display some agreement, neither can be considered reliable.</div><div class="paramtext">When both function and gradients are available and you require the Hessian matrix (i.e., <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>1</m:mn></m:math>) E04XAF/E04XAA follows a similar procedure to the case above with the exception that the gradient function <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;is substituted for the objective function and so the forward-difference interval for the first derivative of <m:math><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;with respect to variable <m:math><m:msub><m:mi>x</m:mi><m:mi>j</m:mi></m:msub></m:math>&#160;is computed.  The <m:math><m:mi>j</m:mi></m:math>th column of the approximate Hessian matrix is then defined as in Chapter 2 of <a class="ref" href="#ref079">Gill <span class="italic">et al.</span> (1981)</a>, by

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mfrac><m:mrow><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>+</m:mo><m:msub><m:mi>h</m:mi><m:mi>j</m:mi></m:msub><m:msub><m:mi>e</m:mi><m:mi>j</m:mi></m:msub></m:mfenced><m:mo>-</m:mo><m:mi>g</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:mrow><m:msub><m:mi>h</m:mi><m:mi>j</m:mi></m:msub></m:mfrac>
</m:math></td><td class="formula2"/></tr></table></div>

where <m:math><m:msub><m:mi>h</m:mi><m:mi>j</m:mi></m:msub></m:math>&#160;is the best forward-difference interval associated with the <m:math><m:mi>j</m:mi></m:math>th component of <m:math><m:mi>g</m:mi></m:math>&#160;and <m:math><m:msub><m:mi>e</m:mi><m:mi>j</m:mi></m:msub></m:math>&#160;is the vector with unity in the <m:math><m:mi>j</m:mi></m:math>th position and zeros elsewhere.</div><div class="paramtext">When only the objective function is available and you require the gradients and Hessian matrix (i.e., <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>) E04XAF/E04XAA again follows the same procedure as the case for <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>0</m:mn></m:math>&#160;except that this time the value of <m:math><m:mover><m:mi>c</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>&#934;</m:mi></m:mfenced></m:math>&#160;for a trial value <m:math><m:msub><m:mi>h</m:mi><m:mi>k</m:mi></m:msub></m:math>&#160;is defined as acceptable if it lies in the interval <m:math><m:mfenced separators="" open="[" close="]"><m:mn>0.0001</m:mn><m:mo>,</m:mo><m:mn>0.01</m:mn></m:mfenced></m:math>&#160;and the initial trial interval is taken as

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mover><m:mi>h</m:mi><m:mo>-</m:mo></m:mover><m:mo>=</m:mo><m:mn>2</m:mn><m:mfenced separators=""><m:mn>1</m:mn><m:mo>+</m:mo><m:mfenced open="|" close="|" separators=""><m:mi>x</m:mi></m:mfenced></m:mfenced><m:mroot><m:msub><m:mi>e</m:mi><m:mi>R</m:mi></m:msub><m:mn>4</m:mn></m:mroot><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The approximate Hessian matrix <m:math><m:mi>G</m:mi></m:math>&#160;is then defined as in Chapter 2 of <a class="ref" href="#ref079">Gill <span class="italic">et al.</span> (1981)</a>, by

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:msub><m:mi>G</m:mi><m:mrow><m:mi>i</m:mi><m:mi>j</m:mi></m:mrow></m:msub><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:mfrac><m:mn>1</m:mn><m:mrow><m:msub><m:mi>h</m:mi><m:mi>i</m:mi></m:msub><m:msub><m:mi>h</m:mi><m:mi>j</m:mi></m:msub></m:mrow>
 </m:mfrac><m:mfenced separators=""><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>+</m:mo><m:msub><m:mi>h</m:mi><m:mi>i</m:mi></m:msub><m:msub><m:mi>e</m:mi><m:mi>i</m:mi></m:msub><m:mo>+</m:mo><m:msub><m:mi>h</m:mi><m:mi>j</m:mi></m:msub><m:msub><m:mi>e</m:mi><m:mi>j</m:mi></m:msub></m:mfenced><m:mo>-</m:mo><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>+</m:mo><m:msub><m:mi>h</m:mi><m:mi>i</m:mi></m:msub><m:msub><m:mi>e</m:mi><m:mi>i</m:mi></m:msub></m:mfenced><m:mo>-</m:mo><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi><m:mo>+</m:mo><m:msub><m:mi>h</m:mi><m:mi>j</m:mi></m:msub><m:msub><m:mi>e</m:mi><m:mi>j</m:mi></m:msub></m:mfenced><m:mo>+</m:mo><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:mfenced><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div></div><h2 class="standard"><a class="sec" name="references" id="references"/>4&#160;&#160;References</h2><div class="paramtext"><a name="ref442" id="ref442"/>Gill P E, Murray W, Saunders M A and Wright M H (1983a)  Documentation for FDCALC and FDCORE <i>Technical Report SOL</i> 83&#8211;6 Stanford University </div>
<div class="paramtext"><a name="ref443" id="ref443"/>Gill P E, Murray W, Saunders M A and Wright M H (1983b)  Computing forward-difference intervals for numerical optimization <i>SIAM J. Sci. Statist. Comput.</i> <b>4</b> 310&#8211;321 </div>
<div class="paramtext"><a name="ref079" id="ref079"/>Gill P E, Murray W and Wright M H (1981)  <i>Practical Optimization</i> Academic Press </div><h2 class="standard"><a class="sec" name="parameters" id="parameters"/>5&#160;&#160;Parameters</h2>
<dl><dt class="paramhead"><a name="MSGLVL" id="MSGLVL"/>1: &#160;&#160;&#8194; MSGLVL &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: must indicate the amount of intermediate output desired (see <a class="sec" href="#fc-printedoutput">Section 8.1</a> for a description of the printed output).  All output is written on the current advisory message unit (see <a class="rout" href="../X04/x04abf.xml">X04ABF</a>). 
<div class="left-tablediv"><table class="frame-none"><tbody>
<tr>
<td class="libdoc" valign="top" align="center"><b>Value</b></td>
<td class="libdoc" valign="top" align="left"><b>Definition</b></td>
</tr><tr>
<td class="libdoc" valign="top" align="center">0</td>
<td class="libdoc" valign="top" align="left">No printout</td>
</tr><tr>
<td class="libdoc" valign="top" align="center">1</td>
<td class="libdoc" valign="top" align="left">A summary is printed out for each variable plus any warning messages.</td>
</tr><tr>
<td class="libdoc" valign="top" align="center">Other</td>
<td class="libdoc" valign="top" align="left">Values other than <m:math><m:mn>0</m:mn></m:math>&#160;and <m:math><m:mn>1</m:mn></m:math>&#160;should normally be used <b>only</b> at the direction of NAG.</td>
</tr>
</tbody>
</table></div>
</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 entry</i>: 


the number <m:math><m:mi>n</m:mi></m:math>&#160;of independent variables.</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>1</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="EPSRF" id="EPSRF"/>3: &#160;&#160;&#8194; EPSRF &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: must define <m:math><m:msub><m:mi>e</m:mi><m:mi>R</m:mi></m:msub></m:math>, which is intended to be a measure of the accuracy with which the problem function <m:math><m:mi>F</m:mi></m:math>&#160;can be computed.  The value of <m:math><m:msub><m:mi>e</m:mi><m:mi>R</m:mi></m:msub></m:math>&#160;should reflect the relative precision of <m:math><m:mn>1</m:mn><m:mo>+</m:mo><m:mfenced open="|" close="|" separators=""><m:mi>F</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:mfenced></m:math>, i.e., acts as a relative precision when <m:math><m:mfenced open="|" close="|" separators=""><m:mi>F</m:mi></m:mfenced></m:math>&#160;is large, and as an absolute precision when <m:math><m:mfenced open="|" close="|" separators=""><m:mi>F</m:mi></m:mfenced></m:math>&#160;is small.  For example, if <m:math><m:mi>F</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;is typically of order <m:math><m:mn>1000</m:mn></m:math>&#160;and the first six significant digits are known to be correct, an appropriate value for <m:math><m:msub><m:mi>e</m:mi><m:mi>R</m:mi></m:msub></m:math>&#160;would be <m:math><m:mtext>1.0D&#8722;6</m:mtext></m:math>.
<div class="paramtext">A discussion of <a class="arg" href="#EPSRF">EPSRF</a> is given in Chapter 8 of <a class="ref" href="#ref079">Gill <span class="italic">et al.</span> (1981)</a>.  If <a class="arg" href="#EPSRF">EPSRF</a> is either too small or too large on entry a warning will be printed if <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#MSGLVL"><m:mi mathcolor="#EE0000" mathvariant="bold">MSGLVL</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math>, the parameter <a class="arg" href="#IWARN">IWARN</a> set to the appropriate value on exit and E04XAF/E04XAA will use a default value of <m:math><m:msubsup><m:mi>e</m:mi><m:mi>M</m:mi><m:mn>0.9</m:mn></m:msubsup></m:math>, where <m:math><m:msub><m:mi>e</m:mi><m:mi>M</m:mi></m:msub></m:math>&#160;is the <span class="bitalic">machine precision</span>.</div>
<div class="paramtext">If <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#EPSRF"><m:mi mathcolor="#EE0000" mathvariant="bold">EPSRF</m:mi></m:maction><m:mo>&#8804;</m:mo><m:mn>0.0</m:mn></m:math>&#160;on entry then E04XAF/E04XAA will use the default value internally.  The default value will be appropriate for most simple functions that are computed with full accuracy.</div>
</div></dd><dt class="paramhead"><a name="X" id="X"/>4: &#160;&#160;&#8194; X(<a class="arg" href="#N">N</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the point <m:math><m:mi>x</m:mi></m:math>&#160;at which the derivatives are to be computed.</div></dd><dt class="paramhead"><a name="MODE" id="MODE"/>5: &#160;&#160;&#8194; MODE &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd><div class="paramtext"><i>On entry</i>: indicates which derivatives are required.  
<dl>
<dt class="paramval"><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>0</m:mn></m:math></dt>
<dd>The gradient and Hessian diagonal values having supplied the objective function via <a class="arg" href="#OBJFUN">OBJFUN</a>.</dd>
<dt class="paramval"><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>1</m:mn></m:math></dt>
<dd>The Hessian matrix having supplied both the objective function and gradients via <a class="arg" href="#OBJFUN">OBJFUN</a>.</dd>
<dt class="paramval"><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></dt>
<dd>The gradient values and Hessian matrix having supplied the objective function via <a class="arg" href="#OBJFUN">OBJFUN</a>.</dd></dl>
</div>
<div class="paramtext"><i>On exit</i>: is changed <b>only</b> if you set <a class="arg" href="#MODE">MODE</a> negative in <a class="arg" href="#OBJFUN">OBJFUN</a>, i.e., you have requested termination of E04XAF/E04XAA.</div></dd><dt class="paramhead"><a name="OBJFUN" id="OBJFUN"/>6: &#160;&#160;&#8194; OBJFUN &#8211; SUBROUTINE, supplied by the user.<span class="pclass">External Procedure</span></dt><dd><div class="paramtext">If <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#OBJFUN_MODE"><m:mi mathcolor="#EE0000" mathvariant="bold">MODE</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn></m:math>&#160;or <m:math><m:mn>2</m:mn></m:math>, <a class="arg" href="#OBJFUN">OBJFUN</a> must calculate the objective function; otherwise if <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#OBJFUN_MODE"><m:mi mathcolor="#EE0000" mathvariant="bold">MODE</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math>, <a class="arg" href="#OBJFUN">OBJFUN</a> must calculate the objective function and the gradients.</div><div class="subprog">
<div class="paramtext">The specification of <a class="arg" href="#OBJFUN">OBJFUN</a> is:</div><table class="fspec"><tr><td class="tdfspec1">SUBROUTINE&#160;OBJFUN&#160;(</td><td class="tdfspec2"><a class="arg" href="../E04/e04xaf.xml#OBJFUN_MODE">MODE</a>, <a class="arg" href="../E04/e04xaf.xml#OBJFUN_N">N</a>, <a class="arg" href="../E04/e04xaf.xml#OBJFUN_X">X</a>, <a class="arg" href="../E04/e04xaf.xml#OBJFUN_OBJF">OBJF</a>, <a class="arg" href="../E04/e04xaf.xml#OBJFUN_OBJGRD">OBJGRD</a>, <a class="arg" href="../E04/e04xaf.xml#OBJFUN_NSTATE">NSTATE</a>, <a class="arg" href="../E04/e04xaf.xml#OBJFUN_IUSER">IUSER</a>, <a class="arg" href="../E04/e04xaf.xml#OBJFUN_RUSER">RUSER</a>)</td></tr><tr><td class="tdfspec1">INTEGER</td><td class="tdfspec2">MODE, N, NSTATE, IUSER(*)</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">X(N), OBJF, OBJGRD(N), RUSER(*)</td></tr></table>
<dl><dt class="paramhead"><a name="OBJFUN_MODE" id="OBJFUN_MODE"/>1: &#160;&#160;&#8194; MODE &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd><div class="paramtext"><a class="arg" href="../E04/e04xaf.xml#OBJFUN_MODE">MODE</a> indicates which parameter values within <a class="arg" href="#OBJFUN">OBJFUN</a> need to be set.</div>
<div class="paramtext"><i>On entry</i>: to <a class="arg" href="#OBJFUN">OBJFUN</a>, <a class="arg" href="../E04/e04xaf.xml#OBJFUN_MODE">MODE</a> is always set to the value that you set it to before the call to E04XAF/E04XAA.</div>
<div class="paramtext"><i>On exit</i>: its value must not be altered unless you wish to indicate a failure within <a class="arg" href="#OBJFUN">OBJFUN</a>, in which case it should be set to a negative value.  If <a class="arg" href="../E04/e04xaf.xml#OBJFUN_MODE">MODE</a> is negative on exit from <a class="arg" href="#OBJFUN">OBJFUN</a>, the execution of E04XAF/E04XAA is terminated with <a class="arg" href="#IFAIL">IFAIL</a> set to <a class="arg" href="../E04/e04xaf.xml#OBJFUN_MODE">MODE</a>.</div></dd><dt class="paramhead"><a name="OBJFUN_N" id="OBJFUN_N"/>2: &#160;&#160;&#8194; N &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the number <m:math><m:mi>n</m:mi></m:math>&#160;of variables as input to E04XAF/E04XAA.</div></dd><dt class="paramhead"><a name="OBJFUN_X" id="OBJFUN_X"/>3: &#160;&#160;&#8194; X(<a class="arg" href="../E04/e04xaf.xml#OBJFUN_N">N</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the point <m:math><m:mi>x</m:mi></m:math>&#160;at which the objective function (and gradients if <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#OBJFUN_MODE"><m:mi mathcolor="#EE0000" mathvariant="bold">MODE</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math>) is to be evaluated.</div></dd><dt class="paramhead"><a name="OBJFUN_OBJF" id="OBJFUN_OBJF"/>4: &#160;&#160;&#8194; OBJF &#8211; <span class="bitalic">double precision</span><span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: must be set to the value of the objective function.</div></dd><dt class="paramhead"><a name="OBJFUN_OBJGRD" id="OBJFUN_OBJGRD"/>5: &#160;&#160;&#8194; OBJGRD(<a class="arg" href="../E04/e04xaf.xml#OBJFUN_N">N</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="#OBJFUN_MODE"><m:mi mathcolor="#EE0000" mathvariant="bold">MODE</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math>, <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#OBJFUN_OBJGRD"><m:mi mathcolor="#EE0000" mathvariant="bold">OBJGRD</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>&#160;must contain the value of the first derivative with respect to <m:math><m:mi>x</m:mi></m:math>.  
<div class="paramtext">If <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#OBJFUN_MODE"><m:mi mathcolor="#EE0000" mathvariant="bold">MODE</m:mi></m:maction><m:mo>&#8800;</m:mo><m:mn>1</m:mn></m:math>, <a class="arg" href="../E04/e04xaf.xml#OBJFUN_OBJGRD">OBJGRD</a> need not be set.</div>
</div></dd><dt class="paramhead"><a name="OBJFUN_NSTATE" id="OBJFUN_NSTATE"/>6: &#160;&#160;&#8194; NSTATE &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: will be set to <m:math><m:mn>1</m:mn></m:math>&#160;on the first call of <a class="arg" href="#OBJFUN">OBJFUN</a> by E04XAF/E04XAA, and is <m:math><m:mn>0</m:mn></m:math>&#160;for all subsequent calls.  Thus, if you wish, <a class="arg" href="../E04/e04xaf.xml#OBJFUN_NSTATE">NSTATE</a> may be tested within <a class="arg" href="#OBJFUN">OBJFUN</a> in order to perform certain calculations once only.  For example you may read data.</div></dd><dt class="paramhead"><a name="OBJFUN_IUSER" id="OBJFUN_IUSER"/>7: &#160;&#160;&#8194; IUSER(<m:math><m:mo>*</m:mo></m:math>) &#8211; INTEGER array<span class="pclass">User Workspace</span></dt><dt class="multi-paramhead"><a name="OBJFUN_RUSER" id="OBJFUN_RUSER"/>8: &#160;&#160;&#8194; RUSER(<m:math><m:mo>*</m:mo></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">User Workspace</span></dt><dd><div class="paramtext"><a class="arg" href="#OBJFUN">OBJFUN</a> is called from E04XAF/E04XAA with the parameters <a class="arg" href="../E04/e04xaf.xml#OBJFUN_IUSER">IUSER</a> and <a class="arg" href="../E04/e04xaf.xml#OBJFUN_RUSER">RUSER</a> as supplied to E04XAF/E04XAA.  You are free to use arrays <a class="arg" href="../E04/e04xaf.xml#OBJFUN_IUSER">IUSER</a> and <a class="arg" href="../E04/e04xaf.xml#OBJFUN_RUSER">RUSER</a> to supply information to <a class="arg" href="#OBJFUN">OBJFUN</a> as an alternative to using 
COMMON. 

</div></dd></dl>
</div>
<div class="paramtext"><a class="arg" href="#OBJFUN">OBJFUN</a> must be declared as EXTERNAL in the (sub)program from which E04XAF/E04XAA 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="LDH" id="LDH"/>7: &#160;&#160;&#8194; LDH &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the first dimension of the array <a class="arg" href="#H">H</a> as declared in the (sub)program from which E04XAF/E04XAA is called.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LDH"><m:mi mathcolor="#EE0000" mathvariant="bold">LDH</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="HFORW" id="HFORW"/>8: &#160;&#160;&#8194; HFORW(<a class="arg" href="#N">N</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input/Output</span></dt><dd><div class="paramtext"><i>On entry</i>: the initial trial interval for computing the appropriate partial derivative to the <m:math><m:mi>j</m:mi></m:math>th variable.
<div class="paramtext">If <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#HFORW"><m:mi mathcolor="#EE0000" mathvariant="bold">HFORW</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>j</m:mi></m:mfenced></m:mrow><m:mo>&#8804;</m:mo><m:mn>0.0</m:mn></m:math>, then the initial trial interval is computed by E04XAF/E04XAA (see <a class="sec" href="#description">Section 3</a>).</div>
</div>
<div class="paramtext"><i>On exit</i>: <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#HFORW"><m:mi mathcolor="#EE0000" mathvariant="bold">HFORW</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>&#160;is the best interval found for computing a forward-difference approximation to the appropriate partial derivative for the <m:math><m:mi>j</m:mi></m:math>th variable.</div></dd><dt class="paramhead"><a name="OBJF" id="OBJF"/>9: &#160;&#160;&#8194; OBJF &#8211; <span class="bitalic">double precision</span><span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: the value of the objective function evaluated at the input vector in <a class="arg" href="#X">X</a>.</div></dd><dt class="paramhead"><a name="OBJGRD" id="OBJGRD"/>10: &#8194; OBJGRD(<a class="arg" href="#N">N</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="#MODE"><m:mi mathcolor="#EE0000" mathvariant="bold">MODE</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn></m:math>&#160;or <m:math><m:mn>2</m:mn></m:math>, <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#OBJGRD"><m:mi mathcolor="#EE0000" mathvariant="bold">OBJGRD</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>&#160;contains the best estimate of the first partial derivative for the <m:math><m:mi>j</m:mi></m:math>th variable.  
<div class="paramtext">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>1</m:mn></m:math>, <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#OBJGRD"><m:mi mathcolor="#EE0000" mathvariant="bold">OBJGRD</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>&#160;contains the first partial derivative for the <m:math><m:mi>j</m:mi></m:math>th variable evaluated at the input vector in <a class="arg" href="#X">X</a>.</div>
</div></dd><dt class="paramhead"><a name="HCNTRL" id="HCNTRL"/>11: &#8194; HCNTRL(<a class="arg" href="#N">N</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#HCNTRL"><m:mi mathcolor="#EE0000" mathvariant="bold">HCNTRL</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>&#160;is the best interval found for computing a central-difference approximation to the appropriate partial derivative for the <m:math><m:mi>j</m:mi></m:math>th variable.</div></dd><dt class="paramhead"><a name="H" id="H"/>12: &#8194; H(<a class="arg" href="#LDH">LDH</a>,<m:math><m:mo>*</m:mo></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Output</span></dt><dd><div class="paramtext"><b>Note:</b> the second dimension of the array <a class="arg" href="#H">H</a>
must be at least
<m:math><m:mn>1</m:mn></m:math>&#160;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>0</m:mn></m:math>&#160;and at least <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:math>&#160;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>1</m:mn></m:math>&#160;or <m:math><m:mn>2</m:mn></m:math>.</div>
<div class="paramtext"><i>On exit</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>0</m:mn></m:math>, the estimated Hessian diagonal elements are contained in the first column of this array.
<div class="paramtext">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>1</m:mn></m:math>&#160;or <m:math><m:mn>2</m:mn></m:math>, the estimated Hessian matrix is contained in the leading <m:math><m:mi>n</m:mi></m:math>&#160;by <m:math><m:mi>n</m:mi></m:math>&#160;part of this array.</div>
</div></dd><dt class="paramhead"><a name="IWARN" id="IWARN"/>13: &#8194; IWARN &#8211; INTEGER<span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IWARN"><m:mi mathcolor="#EE0000" mathvariant="bold">IWARN</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn></m:math>&#160;on successful exit.
<div class="paramtext">If the value of <a class="arg" href="#EPSRF">EPSRF</a> on entry is too small or too large then <a class="arg" href="#IWARN">IWARN</a> is set to <m:math><m:mn>1</m:mn></m:math>&#160;or <m:math><m:mn>2</m:mn></m:math>&#160;respectively on exit and the default value for <a class="arg" href="#EPSRF">EPSRF</a> is used within E04XAF/E04XAA.</div>
<div class="paramtext">If <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#MSGLVL"><m:mi mathcolor="#EE0000" mathvariant="bold">MSGLVL</m:mi></m:maction><m:mo>&gt;</m:mo><m:mn>0</m:mn></m:math>&#160;then warnings will be printed if <a class="arg" href="#EPSRF">EPSRF</a> is too small or too large.</div>
</div></dd><dt class="paramhead"><a name="WORK" id="WORK"/>14: &#8194; WORK(<m:math><m:mo>*</m:mo></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Workspace</span></dt><dd><div class="paramtext"><b>Note:</b> the dimension of the array <a class="arg" href="#WORK">WORK</a>
must be at least
<m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:math>&#160;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>0</m:mn></m:math>&#160;and at least <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>&#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:math>&#160;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>1</m:mn></m:math>&#160;or <m:math><m:mn>2</m:mn></m:math>.</div></dd><dt class="paramhead"><a name="IUSER" id="IUSER"/>15: &#8194; IUSER(<m:math><m:mo>*</m:mo></m:math>) &#8211; INTEGER array<span class="pclass">User Workspace</span></dt><dd>
<div class="paramtext"><b>Note:</b> the dimension of the array <a class="arg" href="#IUSER">IUSER</a>
must be at least
<m:math><m:mn>1</m:mn></m:math>.</div><div class="paramtext">This array is not used by E04XAF/E04XAA, but is passed directly to <a class="arg" href="#OBJFUN">OBJFUN</a> and may be used to supply information to <a class="arg" href="#OBJFUN">OBJFUN</a>.</div></dd><dt class="paramhead"><a name="RUSER" id="RUSER"/>16: &#8194; RUSER(<m:math><m:mo>*</m:mo></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">User Workspace</span></dt><dd>
<div class="paramtext"><b>Note:</b> the dimension of the array <a class="arg" href="#RUSER">RUSER</a>
must be at least
<m:math><m:mn>1</m:mn></m:math>.</div><div class="paramtext">This array is not used by E04XAF/E04XAA, but is passed directly to <a class="arg" href="#OBJFUN">OBJFUN</a> and may be used to supply information to <a class="arg" href="#OBJFUN">OBJFUN</a>.</div></dd><dt class="paramhead"><a name="INFO" id="INFO"/>17: &#8194; INFO(<a class="arg" href="#N">N</a>) &#8211; INTEGER array<span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#INFO"><m:mi mathcolor="#EE0000" mathvariant="bold">INFO</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>&#160;represents diagnostic information on variable <m:math><m:mi>j</m:mi></m:math>.  (See <a class="sec" href="#errors">Section 6</a> for more details.)</div></dd><dt class="paramhead"><a name="IFAIL" id="IFAIL"/>18: &#8194; IFAIL &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><b>Note:</b> <span class="italic">for E04XAA, <a class="arg" href="#IFAIL">IFAIL</a> does not occur in this position in the parameter list.  See the additional parameters described below</span>.</div><div class="paramtext"><i>On entry</i>: <a class="arg" href="#IFAIL">IFAIL</a> must be set to <m:math><m:mn>0</m:mn></m:math>, <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>. If you are unfamiliar with this parameter you should refer to <a class="sec" href="../GENINT/essint.xml#library3">Section 3.3</a> in  the Essential Introduction for details.</div>
<div class="paramtext"><i>On exit</i>: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;unless the routine detects an error (see <a class="sec" href="#errors">Section 6</a>). <div class="paramtext">For environments where it might be inappropriate to halt program execution when an error is detected, the value <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>&#160;is recommended.  If the output of error messages is undesirable, then the value <m:math><m:mn>1</m:mn></m:math>&#160;is recommended.  Otherwise, if you are not familiar with this parameter, the recommended value is <m:math><m:mn>0</m:mn></m:math>.  <b>When the value <m:math><m:mrow><m:mo>-</m:mo><m:mn mathvariant="bold">1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn mathvariant="bold">1</m:mn></m:math>&#160;is used it is essential to test the value of <a class="arg" href="#IFAIL">IFAIL</a> on exit.</b></div></div></dd><dd class="note"><b>Note:</b> <span class="italic"> the following are additional parameters for specific use with E04XAA.  Users of E04XAF therefore need not read the remainder of this description</span>.</dd><dt class="paramhead"><a name="LWSAV" id="LWSAV"/>18: &#8194; LWSAV(<m:math><m:mn>1</m:mn></m:math>) &#8211; LOGICAL array<span class="pclass">Input</span></dt><dt class="multi-paramhead"><a name="IWSAV" id="IWSAV"/>19: &#8194; IWSAV(<m:math><m:mn>1</m:mn></m:math>) &#8211; INTEGER array<span class="pclass">Input</span></dt><dt class="multi-paramhead"><a name="RWSAV" id="RWSAV"/>20: &#8194; RWSAV(<m:math><m:mn>1</m:mn></m:math>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd>
<div class="paramtext">These parameters are no longer required by E04XAF/E04XAA.</div>
</dd><dt class="paramhead"><a name="IFAIL2" id="IFAIL2"/>21: &#8194; IFAIL &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd><div class="paramtext"><b>Note:</b> see the parameter description for <a class="arg" href="#IFAIL">IFAIL</a> above.</div></dd></dl><h2 class="standard"><a class="sec" name="errors" id="errors"/>6&#160;&#160;Error Indicators and Warnings</h2>
<div class="paramtext">On exit from E04XAF/E04XAA both diagnostic parameters <a class="arg" href="#INFO">INFO</a> and <a class="arg" href="#IFAIL">IFAIL</a> should be tested.  <a class="arg" href="#IFAIL">IFAIL</a> represents an overall diagnostic indicator, whereas the integer array <a class="arg" href="#INFO">INFO</a> represents diagnostic information on each variable.</div><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="IFlt0" id="IFlt0"/><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>&lt;</m:mo><m:mn>0</m:mn></m:math></dt>
<dd>
<div class="paramtext">A negative value of <a class="arg" href="#IFAIL">IFAIL</a> indicates an exit from E04XAF/E04XAA because you set <a class="arg" href="../E04/e04xaf.xml#OBJFUN_MODE">MODE</a> negative in <a class="arg" href="#OBJFUN">OBJFUN</a>.  The value of <a class="arg" href="#IFAIL">IFAIL</a> will be the same as your setting of <a class="arg" href="../E04/e04xaf.xml#OBJFUN_MODE">MODE</a>.</div>
</dd>
</dl><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">On entry, one or more of the following conditions are satisfied: <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>&lt;</m:mo><m:mn>1</m:mn></m:math>, <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LDH"><m:mi mathcolor="#EE0000" mathvariant="bold">LDH</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:mtext>&#8203; or &#8203;</m:mtext><m:maction actiontype="link" dsi:type="simple" dsi:href="#MODE"><m:mi mathcolor="#EE0000" mathvariant="bold">MODE</m:mi></m:maction></m:math>&#160;is invalid.</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">One or more variables have a nonzero <a class="arg" href="#INFO">INFO</a> value.  This may not necessarily represent an unsuccessful exit &#8211; see diagnostic information on <a class="arg" href="#INFO">INFO</a>.</div>
</dd>
</dl>
<div class="paramtext">Diagnostic information returned via <a class="arg" href="#INFO">INFO</a> is as follows:</div>
<dl class="ifail">
<dt class="errorhead"><a name="INieq1" id="INieq1"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#INFO"><m:mi mathcolor="#EE0000" mathvariant="bold">INFO</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math></dt>
<dd>
<div class="paramtext">The appropriate function appears to be constant.  <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#HFORW"><m:mi mathcolor="#EE0000" mathvariant="bold">HFORW</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi></m:mfenced></m:mrow></m:math>&#160;is set to the initial trial interval value (see <a class="sec" href="#description">Section 3</a>) corresponding to a well-scaled problem and <span class="mono">Error est</span>.  in the printed output is set to zero.  This value occurs when the estimated relative condition error in the first derivative approximation is unacceptably large for every value of the finite-difference interval.  If this happens when the function is not constant the initial interval may be too small; in this case, it may be worthwhile to rerun E04XAF/E04XAA with larger initial trial interval values supplied in <a class="arg" href="#HFORW">HFORW</a> (see <a class="sec" href="#description">Section 3</a>).  This error may also occur if the function evaluation includes an inordinately large constant term or if <a class="arg" href="#EPSRF">EPSRF</a> is too large.</div>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="INieq2" id="INieq2"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#INFO"><m:mi mathcolor="#EE0000" mathvariant="bold">INFO</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn></m:math></dt>
<dd>
<div class="paramtext">The appropriate function appears to be linear or odd.  <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#HFORW"><m:mi mathcolor="#EE0000" mathvariant="bold">HFORW</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi></m:mfenced></m:mrow></m:math>&#160;is set to the smallest interval with acceptable bounds on the relative condition error in the forward- and backward-difference estimates.  In this case, the estimated relative condition error in the second derivative approximation remained large for every trial interval, but the estimated error in the first derivative approximation was acceptable for at least one interval.  If the function is not linear or odd the relative condition error in the second derivative may be decreasing very slowly, it may be worthwhile to rerun E04XAF/E04XAA with larger initial trial interval values supplied in <a class="arg" href="#HFORW">HFORW</a> (see <a class="sec" href="#description">Section 3</a>).</div>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="INieq3" id="INieq3"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#INFO"><m:mi mathcolor="#EE0000" mathvariant="bold">INFO</m:mi></m:maction><m:mo>=</m:mo><m:mn>3</m:mn></m:math></dt>
<dd>
<div class="paramtext">The second derivative of the appropriate function appears to be so large that it cannot be reliably estimated (i.e., near a singularity).  <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#HFORW"><m:mi mathcolor="#EE0000" mathvariant="bold">HFORW</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>i</m:mi></m:mfenced></m:mrow></m:math>&#160;is set to the smallest trial interval.</div>
<div class="paramtext">This value occurs when the relative condition error estimate in the second derivative remained very small for every trial interval.</div>
<div class="paramtext">If the second derivative is not large the relative condition error in the second derivative may be increasing very slowly.  It may be worthwhile to rerun E04XAF/E04XAA with smaller initial trial interval values supplied in <a class="arg" href="#HFORW">HFORW</a> (see <a class="sec" href="#description">Section 3</a>).  This error may also occur when the given value of <a class="arg" href="#EPSRF">EPSRF</a> is not a good estimate of a bound on the absolute error in the appropriate function (i.e., <a class="arg" href="#EPSRF">EPSRF</a> is too small).</div>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="INieq4" id="INieq4"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#INFO"><m:mi mathcolor="#EE0000" mathvariant="bold">INFO</m:mi></m:maction><m:mo>=</m:mo><m:mn>4</m:mn></m:math></dt>
<dd>
<div class="paramtext">The algorithm terminated with an apparently acceptable estimate of the second derivative.  However the forward-difference estimates of the appropriate first derivatives (computed with the final estimate of the &#8216;optimal&#8217; forward-difference interval) and the central difference estimates (computed with the interval used to compute the final estimate of the second derivative) do not agree to half a decimal place.  The usual reason that the forward- and central-difference estimates fail to agree is that the first derivative is small.</div>
<div class="paramtext">If the first derivative is not small, it may be helpful to execute the procedure at a different point.</div>
</dd>
</dl><h2 class="standard"><a class="sec" name="accuracy" id="accuracy"/>7&#160;&#160;Accuracy</h2>
<div class="paramtext">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="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;on exit the algorithm terminated successfully, i.e., the forward-difference estimates of the appropriate first derivatives (computed with the final estimate of the &#8216;optimal&#8217; forward-difference interval <m:math><m:msub><m:mi>h</m:mi><m:mi>F</m:mi></m:msub></m:math>) and the central-difference estimates (computed with the interval <m:math><m:msub><m:mi>h</m:mi><m:mi>&#981;</m:mi></m:msub></m:math>&#160;used to compute the final estimate of the second derivative) agree to at least half a decimal place.</div><div class="paramtext">In short word length implementations when computing the full Hessian matrix given function values only (i.e., <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>) the elements of the computed Hessian will have at best <m:math><m:mn>1</m:mn></m:math>&#160;to <m:math><m:mn>2</m:mn></m:math>&#160;figures of accuracy.</div><h2 class="standard"><a class="sec" name="fcomments" id="fcomments"/>8&#160;&#160;Further Comments</h2>
<div class="paramtext">To evaluate an acceptable set of finite-difference intervals for a well-scaled problem, the routine will require around two function evaluations per variable; in a badly scaled problem however, as many as six function evaluations per variable may be needed.</div><div class="paramtext">If you request the full Hessian matrix supplying both function and gradients (i.e., <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>1</m:mn></m:math>) or function only (i.e., <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>) then a further <a class="arg" href="#N">N</a> or <m:math><m:mn>3</m:mn><m:mo>&#215;</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>&#160;function evaluations respectively are required.</div><h3 class="standard"><a class="sec" name="fc-printedoutput" id="fc-printedoutput"/>8.1&#160;&#160;Description of the Printed Output</h3>
<div class="paramtext">The following is a description of the printed output from E04XAF/E04XAA as controlled by the parameter <a class="arg" href="#MSGLVL">MSGLVL</a>.</div><div class="paramtext">Output when <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#MSGLVL"><m:mi mathcolor="#EE0000" mathvariant="bold">MSGLVL</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math>&#160;is as follows:
<table class="standard-100"><tr>
<td style="width:12.0em;" valign="baseline"><span class="mono">J</span></td>
<td valign="top">number of variable for which the difference interval has been computed.</td>
</tr><tr>
<td style="width:12.0em;" valign="baseline"><m:math><m:mi mathvariant="monospace">X</m:mi><m:mfenced separators=""><m:mi>j</m:mi></m:mfenced></m:math></td>
<td valign="top"><m:math><m:mi>j</m:mi></m:math>th variable of <m:math><m:mi>x</m:mi></m:math>&#160;as set by you.</td>
</tr><tr>
<td style="width:12.0em;" valign="baseline"><span class="mono">F.  dif.  int.</span></td>
<td valign="top">the best interval found for computing a forward-difference approximation to the appropriate partial derivative with respect to the <m:math><m:mi>j</m:mi></m:math>th variable.</td>
</tr><tr>
<td style="width:12.0em;" valign="baseline"><span class="mono">C.  dif.  int.</span></td>
<td valign="top">the best interval found for computing a central-difference approximation to the appropriate partial derivative with respect to the <m:math><m:mi>j</m:mi></m:math>th variable.</td>
</tr><tr>
<td style="width:12.0em;" valign="baseline"><span class="mono">Error est.</span></td>
<td valign="top">a bound on the estimated error in the final forward-difference approximation.  When <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#INFO"><m:mi mathcolor="#EE0000" mathvariant="bold">INFO</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>j</m:mi></m:mfenced></m:mrow><m:mo>=</m:mo><m:mn>1</m:mn></m:math>, <span class="mono">Error est</span>. is set to zero.</td>
</tr><tr>
<td style="width:12.0em;" valign="baseline"><span class="mono">Grad.  est.</span></td>
<td valign="top">best estimate of the first partial derivative with respect to the <m:math><m:mi>j</m:mi></m:math>th variable.</td>
</tr><tr>
<td style="width:12.0em;" valign="baseline"><span class="mono">Hess diag est.</span></td>
<td valign="top">best estimate of the second partial derivative with respect to the <m:math><m:mi>j</m:mi></m:math>th variable.</td>
</tr><tr>
<td style="width:12.0em;" valign="baseline"><span class="mono">fun evals.</span></td>
<td valign="top">the number of function evaluations used to compute the final difference intervals for the <m:math><m:mi>j</m:mi></m:math>th variable.</td>
</tr><tr>
<td style="width:12.0em;" valign="baseline"><m:math><m:mi mathvariant="monospace">info</m:mi><m:mfenced separators=""><m:mi>j</m:mi></m:mfenced></m:math></td>
<td valign="top">the value of <a class="arg" href="#INFO">INFO</a> for the <m:math><m:mi>j</m:mi></m:math>th variable.</td>
</tr></table>
</div><h2 class="standard"><a class="sec" name="example" id="example"/>9&#160;&#160;Example</h2>
<div class="paramtext">This example computes the gradient vector and the Hessian matrix of the following function:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi>F</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:msup>
<m:mfenced separators=""><m:msub><m:mi>x</m:mi><m:mn>1</m:mn></m:msub><m:mo>+</m:mo><m:mn>10</m:mn><m:msub><m:mi>x</m:mi><m:mn>2</m:mn></m:msub></m:mfenced>
<m:mn>2</m:mn></m:msup><m:mo>+</m:mo><m:mn>5</m:mn><m:mo>&#8290;</m:mo><m:msup>
<m:mfenced separators=""><m:msub><m:mi>x</m:mi><m:mn>3</m:mn></m:msub><m:mo>-</m:mo><m:msub><m:mi>x</m:mi><m:mn>4</m:mn></m:msub></m:mfenced>
<m:mn>2</m:mn></m:msup><m:mo>+</m:mo><m:msup>
<m:mfenced separators=""><m:msub><m:mi>x</m:mi><m:mn>2</m:mn></m:msub><m:mo>-</m:mo><m:mn>2</m:mn><m:msub><m:mi>x</m:mi><m:mn>3</m:mn></m:msub></m:mfenced>
<m:mn>4</m:mn></m:msup><m:mo>+</m:mo><m:mn>10</m:mn><m:mo>&#8290;</m:mo><m:msup>
<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>4</m:mn></m:msub></m:mfenced>
<m:mn>4</m:mn></m:msup>
</m:math></td><td class="formula2"/></tr></table></div>

at the point <m:math><m:mfenced separators=""><m:mn>3</m:mn><m:mo>,</m:mo><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mo>,</m:mo><m:mn>0</m:mn><m:mo>,</m:mo><m:mn>1</m:mn></m:mfenced></m:math>.</div><h3 class="standard"><a class="sec" name="examtext" id="examtext"/>9.1&#160;&#160;Program Text</h3>
<div class="paramtext"><b>Note:</b> <span class="italic">the following programs illustrate the use of E04XAF and E04XAA</span>.</div><p><a class="verbatimref" href="../../examples/source/e04xafe.f">Program Text (e04xafe.f)</a></p><p><a class="verbatimref" href="../../examples/source/e04xaae.f">Program Text (e04xaae.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/e04xafe.r">Program Results (e04xafe.r)</a></p><p><a class="verbatimref" href="../../examples/baseresults/e04xaae.r">Program Results (e04xaae.r)</a></p>
<hr/><div><a class="rout" href="../../pdf/E04/e04xaf.pdf">E04XAF/E04XAA (PDF version)</a></div><div><a class="chap" href="e04conts.xml">E04 Chapter Contents</a></div><div><a class="chapint" href="e04intro.xml">E04 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>
