<?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>E02BEF : 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/E02/e02bef.pdf">E02BEF (PDF version)</a></div><div><a class="chap" href="e02conts.xml">E02 Chapter Contents</a></div><div><a class="chapint" href="e02intro.xml">E02 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/>E02BEF</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="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-timing">8.1&#160;&#160;<b>Timing</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#fc-choice">8.2&#160;&#160;<b>Choice of S
</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#fc-method">8.3&#160;&#160;<b>Outline of Method Used</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#fc-evaluation">8.4&#160;&#160;<b>Evaluation of Computed Spline</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">E02BEF computes a cubic spline approximation to an arbitrary set of data points.  The knots of the spline are located automatically, but a single parameter must be specified to control the trade-off between closeness of fit and smoothness of fit.</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;E02BEF&#160;(</td><td class="tdfspec2"><a class="arg" href="#START">START</a>, <a class="arg" href="#M">M</a>, <a class="arg" href="#X">X</a>, <a class="arg" href="#Y">Y</a>, <a class="arg" href="#W">W</a>, <a class="arg" href="#S">S</a>, <a class="arg" href="#NEST">NEST</a>, <a class="arg" href="#N">N</a>, <a class="arg" href="#LAMDA">LAMDA</a>, <a class="arg" href="#C">C</a>, <a class="arg" href="#FP">FP</a>, <a class="arg" href="#WRK">WRK</a>, <a class="arg" href="#LWRK">LWRK</a>, <a class="arg" href="#IWRK">IWRK</a>, <a class="arg" href="#IFAIL">IFAIL</a>)</td></tr><tr><td class="tdfspec1">INTEGER</td><td class="tdfspec2">M, NEST, N, LWRK, IWRK(NEST), IFAIL</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">X(M), Y(M), W(M), S, LAMDA(NEST), C(NEST), FP, WRK(LWRK)</td></tr><tr><td class="tdfspec1">CHARACTER*1</td><td class="tdfspec2">START</td></tr></table><h2 class="standard"><a class="sec" name="description" id="description"/>3&#160;&#160;Description</h2>
<div class="paramtext">E02BEF determines a smooth cubic spline approximation <m:math><m:mi>s</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;to the set of data points <m:math><m:mfenced separators=""><m:msub><m:mi>x</m:mi><m:mi>r</m:mi></m:msub><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mi>r</m:mi></m:msub></m:mfenced></m:math>, with weights <m:math><m:msub><m:mi>w</m:mi><m:mi>r</m:mi></m:msub></m:math>, for <m:math><m:mi>r</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>m</m:mi>
</m:math>.</div><div class="paramtext">The spline is given in the B-spline representation

<div class="formula-eqn"><a name="eqn1" id="eqn1"/><table class="formula-eqn"><tr><td class="formula-eqn"><m:math display="block">
<m:mi>s</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow>
  <m:mrow><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>4</m:mn></m:mrow></m:munderover><m:msub><m:mi>c</m:mi><m:mi>i</m:mi></m:msub><m:msub><m:mi>N</m:mi><m:mi>i</m:mi></m:msub><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mtext>,</m:mtext>
</m:math></td><td class="formula-eqn2">
      (1)
     </td></tr></table></div>

where <m:math><m:msub><m:mi>N</m:mi><m:mi>i</m:mi></m:msub><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;denotes the normalized cubic B-spline defined upon the knots <m:math><m:msub><m:mi>&#955;</m:mi><m:mi>i</m:mi></m:msub><m:mo>,</m:mo><m:msub><m:mi>&#955;</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:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>&#955;</m:mi><m:mrow><m:mi>i</m:mi><m:mo>+</m:mo><m:mn>4</m:mn></m:mrow></m:msub></m:math>.</div><div class="paramtext">The total number <m:math><m:mi>n</m:mi>
</m:math>&#160;of these knots and their values <m:math><m:msub><m:mi>&#955;</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>&#955;</m:mi><m:mi>n</m:mi></m:msub></m:math>&#160;are chosen automatically by the routine.  The knots <m:math><m:msub><m:mi>&#955;</m:mi><m:mn>5</m:mn></m:msub><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>&#955;</m:mi><m:mrow><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>4</m:mn></m:mrow></m:msub></m:math>&#160;are the interior knots; they divide the approximation interval <m:math><m:mfenced separators="" open="[" close="]"><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:mi>m</m:mi></m:msub></m:mfenced></m:math>&#160;into <m:math><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>7</m:mn></m:math>&#160;sub-intervals.  The coefficients <m:math><m:msub><m:mi>c</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:msub><m:mi>c</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>c</m:mi><m:mrow><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>4</m:mn></m:mrow></m:msub></m:math>&#160;are then determined as the solution of the following constrained minimization problem:</div><div class="paramtext">minimize

<div class="formula-eqn"><a name="eqn2" id="eqn2"/><table class="formula-eqn"><tr><td class="formula-eqn"><m:math display="block">
<m:mi>&#951;</m:mi><m:mo>=</m:mo><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>5</m:mn></m:mrow>
  <m:mrow><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>4</m:mn></m:mrow></m:munderover><m:msubsup><m:mi>&#948;</m:mi><m:mi>i</m:mi><m:mn>2</m:mn></m:msubsup>
</m:math></td><td class="formula-eqn2">
      (2)
     </td></tr></table></div>

subject to the constraint

<div class="formula-eqn"><a name="eqn3" id="eqn3"/><table class="formula-eqn"><tr><td class="formula-eqn"><m:math display="block">
<m:mi>&#952;</m:mi><m:mo>=</m:mo><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>r</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow><m:mi>m</m:mi></m:munderover><m:msubsup><m:mi>&#949;</m:mi><m:mi>r</m:mi><m:mn>2</m:mn></m:msubsup><m:mo>&#8804;</m:mo><m:mi>S</m:mi><m:mtext>,</m:mtext>
</m:math></td><td class="formula-eqn2">
      (3)
     </td></tr></table></div><div class="left-tablediv"><table class="frame-none">
  
  
  
  <tbody>
   <tr>
    <td class="libdoc" valign="top" align="left">where</td>
    <td class="libdoc" valign="top" align="left"><m:math><m:msub><m:mi>&#948;</m:mi><m:mi>i</m:mi></m:msub></m:math></td>
    <td class="libdoc" valign="top" align="left">stands for the discontinuity jump in the third order derivative of <m:math><m:mi>s</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;at the interior knot <m:math><m:msub><m:mi>&#955;</m:mi><m:mi>i</m:mi></m:msub></m:math>,</td>
   </tr><tr>
    <td class="libdoc" valign="top" align="left">&#160;</td>
    <td class="libdoc" valign="top" align="left"><m:math><m:msub><m:mi>&#949;</m:mi><m:mi>r</m:mi></m:msub></m:math></td>
    <td class="libdoc" valign="top" align="left">denotes the weighted residual <m:math><m:msub><m:mi>w</m:mi><m:mi>r</m:mi></m:msub><m:mfenced separators=""><m:msub><m:mi>y</m:mi><m:mi>r</m:mi></m:msub><m:mo>-</m:mo><m:mi>s</m:mi><m:mfenced separators=""><m:msub><m:mi>x</m:mi><m:mi>r</m:mi></m:msub></m:mfenced></m:mfenced></m:math>,</td>
   </tr><tr>
    <td class="libdoc" valign="top" align="left">and</td>
    <td class="libdoc" valign="top" align="left"><m:math><m:mi>S</m:mi>
</m:math></td>
    <td class="libdoc" valign="top" align="left">is a non-negative number to be specified by you.</td>
   </tr>
  </tbody>
 </table></div>
</div><div class="paramtext">The quantity <m:math><m:mi>&#951;</m:mi></m:math>&#160;can be seen as a measure of the (lack of) smoothness of <m:math><m:mi>s</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>, while closeness of fit is measured through <m:math><m:mi>&#952;</m:mi></m:math>.  By means of the parameter <m:math>
 <m:mi>S</m:mi>
</m:math>, &#8216;the smoothing factor&#8217;, you can then control the balance between these two (usually conflicting) properties.  If <m:math><m:mi>S</m:mi>
</m:math>&#160;is too large, the spline will be too smooth and signal will be lost (underfit); if <m:math><m:mi>S</m:mi>
</m:math>&#160;is too small, the spline will pick up too much noise (overfit).  In the extreme cases the routine will return an interpolating spline <m:math><m:mfenced separators=""><m:mi>&#952;</m:mi><m:mo>=</m:mo><m:mn>0</m:mn></m:mfenced></m:math>&#160;if <m:math><m:mi>S</m:mi>
</m:math>&#160;is set to zero, and the weighted least-squares cubic polynomial <m:math><m:mfenced separators=""><m:mi>&#951;</m:mi><m:mo>=</m:mo><m:mn>0</m:mn></m:mfenced></m:math>&#160;if <m:math><m:mi>S</m:mi>
</m:math>&#160;is set very large.  Experimenting with <m:math><m:mi>S</m:mi>
</m:math>&#160;values between these two extremes should result in a good compromise.  (See <a class="sec" href="#fc-choice">Section 8.2</a> for advice on choice of <m:math><m:mi>S</m:mi>
</m:math>.)</div><div class="paramtext">The method employed is outlined in <a class="sec" href="#fc-method">Section 8.3</a> and fully described in <a class="ref" href="#ref070">Dierckx (1975)</a>, <a class="ref" href="#ref072">Dierckx (1981)</a> and <a class="ref" href="#ref071">Dierckx (1982)</a>.  It involves an adaptive strategy for locating the knots of the cubic spline (depending on the function underlying the data and on the value of <m:math><m:mi>S</m:mi>
</m:math>), and an iterative method for solving the constrained minimization problem once the knots have been determined.</div><div class="paramtext">Values of the computed spline, or of its derivatives or definite integral, can subsequently be computed by calling <a class="rout" href="../E02/e02bbf.xml">E02BBF</a>, <a class="rout" href="../E02/e02bcf.xml">E02BCF</a> or <a class="rout" href="../E02/e02bdf.xml">E02BDF</a>, as described in <a class="sec" href="#fc-evaluation">Section 8.4</a>.</div><h2 class="standard"><a class="sec" name="references" id="references"/>4&#160;&#160;References</h2><div class="paramtext"><a name="ref070" id="ref070"/>Dierckx P (1975)  An algorithm for smoothing, differentiating and integration of experimental data using spline functions <i>J. Comput. Appl. Math.</i> <b>1</b> 165&#8211;184 </div>
<div class="paramtext"><a name="ref072" id="ref072"/>Dierckx P (1981)  An improved algorithm for curve fitting with spline functions <i>Report TW54</i> Department of Computer Science, Katholieke Univerciteit Leuven </div>
<div class="paramtext"><a name="ref071" id="ref071"/>Dierckx P (1982)  A fast algorithm for smoothing data on a rectangular grid while using spline functions <i>SIAM J. Numer. Anal.</i> <b>19</b> 1286&#8211;1304 </div>
<div class="paramtext"><a name="ref073" id="ref073"/>Reinsch C H (1967)  Smoothing by spline functions <i>Numer. Math.</i> <b>10</b> 177&#8211;183 </div><h2 class="standard"><a class="sec" name="parameters" id="parameters"/>5&#160;&#160;Parameters</h2>
<dl><dt class="paramhead"><a name="START" id="START"/>1: &#160;&#160;&#8194; START &#8211; CHARACTER*1<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: must be set to 'C' or 'W'.

<dl>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#START"><m:mi mathcolor="#EE0000" mathvariant="bold">START</m:mi></m:maction><m:mo>=</m:mo><m:mtext>'C'</m:mtext></m:math></dt>
<dd>The routine will build up the knot set starting with no interior knots. No values need be assigned to the parameters <a class="arg" href="#N">N</a>, <a class="arg" href="#LAMDA">LAMDA</a>, <a class="arg" href="#WRK">WRK</a> or <a class="arg" href="#IWRK">IWRK</a>.</dd>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#START"><m:mi mathcolor="#EE0000" mathvariant="bold">START</m:mi></m:maction><m:mo>=</m:mo><m:mtext>'W'</m:mtext></m:math></dt>
<dd>The routine will restart the knot-placing strategy using the knots found in a previous call of the routine. In this case, the parameters <a class="arg" href="#N">N</a>, <a class="arg" href="#LAMDA">LAMDA</a>, <a class="arg" href="#WRK">WRK</a>, and <a class="arg" href="#IWRK">IWRK</a> must be unchanged from that previous call. This warm start can save much time in searching for a satisfactory value of <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#S"><m:mi mathcolor="#EE0000" mathvariant="bold">S</m:mi></m:maction> </m:math>.</dd></dl></div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#START"><m:mi mathcolor="#EE0000" mathvariant="bold">START</m:mi></m:maction><m:mo>=</m:mo><m:mtext>'C'</m:mtext></m:math>&#160;or <m:math><m:mtext>'W'</m:mtext></m:math>.
</div></dd><dt class="paramhead"><a name="M" id="M"/>2: &#160;&#160;&#8194; M &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: 

<m:math><m:mi>m</m:mi> </m:math>, the number of data points.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>4</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="X" id="X"/>3: &#160;&#160;&#8194; X(<a class="arg" href="#M">M</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: 
the values <m:math><m:msub><m:mi>x</m:mi><m:mi>r</m:mi></m:msub></m:math>&#160;of the independent variable (abscissa) <m:math><m:mi>x</m:mi> </m:math>, for <m:math><m:mi>r</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>m</m:mi> </m:math>.
</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:msub><m:mi>x</m:mi><m:mn>1</m:mn></m:msub><m:mo>&lt;</m:mo><m:msub><m:mi>x</m:mi><m:mn>2</m:mn></m:msub><m:mo>&lt;</m:mo><m:mo>&#8943;</m:mo><m:mo>&lt;</m:mo><m:msub><m:mi>x</m:mi><m:mi>m</m:mi></m:msub></m:math>.
</div></dd><dt class="paramhead"><a name="Y" id="Y"/>4: &#160;&#160;&#8194; Y(<a class="arg" href="#M">M</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: 
the values <m:math><m:msub><m:mi>y</m:mi><m:mi>r</m:mi></m:msub></m:math>&#160;of the dependent variable (ordinate) <m:math><m:mi>y</m:mi> </m:math>, for <m:math><m:mi>r</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>m</m:mi> </m:math>.

</div></dd><dt class="paramhead"><a name="W" id="W"/>5: &#160;&#160;&#8194; W(<a class="arg" href="#M">M</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the values <m:math><m:msub><m:mi>w</m:mi><m:mi>r</m:mi></m:msub></m:math>&#160;of the weights, for <m:math><m:mi>r</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>m</m:mi> </m:math>. For advice on the choice of weights, see <a class="sec" href="../E02/e02intro.xml#background12">Section 2.1.2</a> in  the E02 Chapter Introduction.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#W"><m:mi mathcolor="#EE0000" mathvariant="bold">W</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi mathvariant="italic">r</m:mi></m:mfenced></m:mrow><m:mo>&gt;</m:mo><m:mn>0</m:mn></m:math>,  for <m:math><m:mi mathvariant="italic">r</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>m</m:mi></m:math>.</div></dd><dt class="paramhead"><a name="S" id="S"/>6: &#160;&#160;&#8194; S &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the smoothing factor, <m:math><m:mi>S</m:mi> </m:math>.
<div class="paramtext">If <m:math><m:mi>S</m:mi><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>, the routine returns an interpolating spline.</div>
<div class="paramtext">If <m:math><m:mi>S</m:mi></m:math>&#160;is smaller than <span class="bitalic">machine precision</span>, it is assumed equal to zero.</div>
<div class="paramtext">For advice on the choice of <m:math><m:mi>S</m:mi></m:math>, see <a class="sec" href="#description">Sections 3</a> and <a class="sec" href="#fc-choice">8.2</a>.</div>
</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#S"><m:mi mathcolor="#EE0000" mathvariant="bold">S</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>0.0</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="NEST" id="NEST"/>7: &#160;&#160;&#8194; NEST &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: 

an overestimate for the number, <m:math><m:mi>n</m:mi></m:math>, of knots required.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#NEST"><m:mi mathcolor="#EE0000" mathvariant="bold">NEST</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>8</m:mn></m:math>. In most practical situations, <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#NEST"><m:mi mathcolor="#EE0000" mathvariant="bold">NEST</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>/</m:mo><m:mn>2</m:mn></m:math>&#160;is sufficient. <a class="arg" href="#NEST">NEST</a> never needs to be larger than <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>+</m:mo><m:mn>4</m:mn></m:math>, the number of knots needed for interpolation <m:math><m:mfenced separators=""><m:maction actiontype="link" dsi:type="simple" dsi:href="#S"><m:mi mathcolor="#EE0000" mathvariant="bold">S</m:mi></m:maction><m:mo>=</m:mo><m:mn>0.0</m:mn></m:mfenced></m:math>.
</div></dd><dt class="paramhead"><a name="N" id="N"/>8: &#160;&#160;&#8194; N &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd><div class="paramtext"><i>On entry</i>: if the warm start option is used, the value of <a class="arg" href="#N">N</a> must be left unchanged from the previous call.</div>
<div class="paramtext"><i>On exit</i>: the total number, <m:math><m:mi>n</m:mi> </m:math>, of knots of the computed spline.</div></dd><dt class="paramhead"><a name="LAMDA" id="LAMDA"/>9: &#160;&#160;&#8194; LAMDA(<a class="arg" href="#NEST">NEST</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input/Output</span></dt><dd><div class="paramtext"><i>On entry</i>: if the warm start option is used, the values <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>1</m:mn></m:mfenced></m:mrow><m:mo>,</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>2</m:mn></m:mfenced></m:mrow><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"> <m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction> </m:mfenced></m:mrow></m:math>&#160;must be left unchanged from the previous call.</div>
<div class="paramtext"><i>On exit</i>: the knots of the spline, i.e., the positions of the interior knots <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>5</m:mn></m:mfenced></m:mrow><m:mo>,</m:mo><m:mspace linebreak="newline"/> <m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>6</m:mn></m:mfenced></m:mrow><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mrow> <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>4</m:mn></m:mrow></m:mfenced></m:mrow> </m:math>&#160;as well as the positions of the additional knots

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block"><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>1</m:mn></m:mfenced></m:mrow><m:mo>=</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>2</m:mn></m:mfenced></m:mrow><m:mo>=</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>3</m:mn></m:mfenced></m:mrow><m:mo>=</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>4</m:mn></m:mfenced></m:mrow><m:mo>=</m:mo><m:msub><m:mi>x</m:mi><m:mn>1</m:mn></m:msub></m:math></td><td class="formula2"/></tr></table></div>

and

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block"><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mrow> <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>3</m:mn></m:mrow></m:mfenced></m:mrow><m:mo>=</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mrow> <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>2</m:mn></m:mrow></m:mfenced></m:mrow><m:mo>=</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mrow> <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:mrow></m:mfenced></m:mrow><m:mo>=</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#LAMDA"><m:mi mathcolor="#EE0000" mathvariant="bold">LAMDA</m:mi></m:maction><m:mfenced separators="," open="(" close=")"> <m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction> </m:mfenced></m:mrow><m:mo>=</m:mo><m:msub><m:mi>x</m:mi><m:mi>m</m:mi></m:msub></m:math></td><td class="formula2"/></tr></table></div>

needed for the B-spline representation.
</div></dd><dt class="paramhead"><a name="C" id="C"/>10: &#8194; C(<a class="arg" href="#NEST">NEST</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: the coefficient <m:math><m:msub><m:mi>c</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;of the B-spline <m:math><m:msub><m:mi>N</m:mi><m:mi>i</m:mi></m:msub><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>&#160;in the spline approximation <m:math><m:mi>s</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>, for <m:math><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>4</m:mn></m:math>.</div></dd><dt class="paramhead"><a name="FP" id="FP"/>11: &#8194; FP &#8211; <span class="bitalic">double precision</span><span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: the sum of the squared weighted residuals, <m:math><m:mi>&#952;</m:mi></m:math>, of the computed spline approximation. If <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#FP"><m:mi mathcolor="#EE0000" mathvariant="bold">FP</m:mi></m:maction><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>, this is an interpolating spline. <a class="arg" href="#FP">FP</a> should equal <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#S"><m:mi mathcolor="#EE0000" mathvariant="bold">S</m:mi></m:maction> </m:math>&#160;within a relative tolerance of <m:math><m:mn>0.001</m:mn></m:math>&#160;unless <m:math><m:mi>n</m:mi><m:mo>=</m:mo><m:mn>8</m:mn></m:math>&#160;when the spline has no interior knots and so is simply a cubic polynomial. For knots to be inserted, <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#S"><m:mi mathcolor="#EE0000" mathvariant="bold">S</m:mi></m:maction> </m:math>&#160;must be set to a value below the value of <a class="arg" href="#FP">FP</a> produced in this case.</div></dd><dt class="paramhead"><a name="WRK" id="WRK"/>12: &#8194; WRK(<a class="arg" href="#LWRK">LWRK</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Communication Array</span></dt><dd><div class="paramtext">If the warm start option is used on entry, the values <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#WRK"><m:mi mathcolor="#EE0000" mathvariant="bold">WRK</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>1</m:mn></m:mfenced></m:mrow><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#WRK"><m:mi mathcolor="#EE0000" mathvariant="bold">WRK</m:mi></m:maction><m:mfenced separators="," open="(" close=")"> <m:mi>n</m:mi> </m:mfenced></m:mrow> </m:math>&#160;must be left unchanged from the previous call.</div></dd><dt class="paramhead"><a name="LWRK" id="LWRK"/>13: &#8194; LWRK &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the dimension of the array <a class="arg" href="#WRK">WRK</a> as declared in the (sub)program from which E02BEF is called.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LWRK"><m:mi mathcolor="#EE0000" mathvariant="bold">LWRK</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>4</m:mn><m:mo>&#215;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>+</m:mo><m:mn>16</m:mn><m:mo>&#215;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#NEST"><m:mi mathcolor="#EE0000" mathvariant="bold">NEST</m:mi></m:maction><m:mo>+</m:mo><m:mn>41</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="IWRK" id="IWRK"/>14: &#8194; IWRK(<a class="arg" href="#NEST">NEST</a>) &#8211; INTEGER array<span class="pclass">Communication Array</span></dt><dd><div class="paramtext">If the warm start option is used, on entry, the values <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#IWRK"><m:mi mathcolor="#EE0000" mathvariant="bold">IWRK</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>1</m:mn></m:mfenced></m:mrow><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#IWRK"><m:mi mathcolor="#EE0000" mathvariant="bold">IWRK</m:mi></m:maction><m:mfenced separators="," open="(" close=")"> <m:mi>n</m:mi> </m:mfenced></m:mrow> </m:math>&#160;must be left unchanged from the previous call.</div>
<div class="paramtext">This array is used as workspace.</div></dd><dt class="paramhead"><a name="IFAIL" id="IFAIL"/>15: &#8194; IFAIL &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On entry</i>: <a class="arg" href="#IFAIL">IFAIL</a> must be set to <m:math><m:mn>0</m:mn></m:math>, <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>. If you are unfamiliar with this parameter you should refer to <a class="sec" href="../GENINT/essint.xml#library3">Section 3.3</a> in  the Essential Introduction for details.</div>
<div class="paramtext"><i>On exit</i>: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;unless the routine detects an error (see <a class="sec" href="#errors">Section 6</a>). <div class="paramtext">For environments where it might be inappropriate to halt program execution when an error is detected, the value <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>&#160;is recommended.  If the output of error messages is undesirable, then the value <m:math><m:mn>1</m:mn></m:math>&#160;is recommended.  Otherwise, if you are not familiar with this parameter, the recommended value is <m:math><m:mn>0</m:mn></m:math>.  <b>When the value <m:math><m:mrow><m:mo>-</m:mo><m:mn mathvariant="bold">1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn mathvariant="bold">1</m:mn></m:math>&#160;is used it is essential to test the value of <a class="arg" href="#IFAIL">IFAIL</a> on exit.</b></div></div></dd></dl><h2 class="standard"><a class="sec" name="errors" id="errors"/>6&#160;&#160;Error Indicators and Warnings</h2>
<div class="paramtext">If on entry <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;or <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">-1</m:mn></m:maction></m:math>, explanatory error messages are output on the current error message unit (as defined by <a class="rout" href="../X04/x04aaf.xml">X04AAF</a>).</div><div class="paramtext">Errors or warnings detected by the routine:</div>
<dl class="ifail">
<dt class="errorhead"><a name="IFeq1" id="IFeq1"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math></dt>
<dd>
<table class="ifail"><tr><td class="ifail1">On&#160;entry,</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#START"><m:mi mathcolor="#EE0000" mathvariant="bold">START</m:mi></m:maction><m:mo>&#8800;</m:mo><m:mtext>'C'</m:mtext></m:math>&#160;or <m:math><m:mtext>'W'</m:mtext></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>&lt;</m:mo><m:mn>4</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="#S"><m:mi mathcolor="#EE0000" mathvariant="bold">S</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="#S"><m:mi mathcolor="#EE0000" mathvariant="bold">S</m:mi></m:maction><m:mo>=</m:mo><m:mn>0.0</m:mn></m:math>&#160;and <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#NEST"><m:mi mathcolor="#EE0000" mathvariant="bold">NEST</m:mi></m:maction><m:mo>&lt;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>+</m:mo><m:mn>4</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="#NEST"><m:mi mathcolor="#EE0000" mathvariant="bold">NEST</m:mi></m:maction><m:mo>&lt;</m:mo><m:mn>8</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="#LWRK"><m:mi mathcolor="#EE0000" mathvariant="bold">LWRK</m:mi></m:maction><m:mo>&lt;</m:mo><m:mn>4</m:mn><m:mo>&#215;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>+</m:mo><m:mn>16</m:mn><m:mo>&#215;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#NEST"><m:mi mathcolor="#EE0000" mathvariant="bold">NEST</m:mi></m:maction><m:mo>+</m:mo><m:mn>41</m:mn></m:math>.</td></tr></table>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq2" id="IFeq2"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn></m:math></dt>
<dd>
<div class="paramtext">The weights are not all strictly positive.</div></dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq3" id="IFeq3"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>3</m:mn></m:math></dt>
<dd>
<div class="paramtext">The values of <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction><m:mfenced separators="," open="(" close=")">
<m:mi>r</m:mi>
</m:mfenced></m:mrow>
</m:math>, for <m:math><m:mi>r</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="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction>
</m:math>, are not in strictly increasing order.</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 number of knots required is greater than <a class="arg" href="#NEST">NEST</a>.  Try increasing <a class="arg" href="#NEST">NEST</a> and, if necessary, supplying larger arrays for the parameters <a class="arg" href="#LAMDA">LAMDA</a>, <a class="arg" href="#C">C</a>, <a class="arg" href="#WRK">WRK</a> and <a class="arg" href="#IWRK">IWRK</a>.  However, if <a class="arg" href="#NEST">NEST</a> is already large, say <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#NEST"><m:mi mathcolor="#EE0000" mathvariant="bold">NEST</m:mi></m:maction><m:mo>&gt;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>/</m:mo><m:mn>2</m:mn></m:math>, then this error exit may indicate that <a class="arg" href="#S">S</a> is too small.</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 iterative process used to compute the coefficients of the approximating spline has failed to converge.  This error exit may occur if <a class="arg" href="#S">S</a> has been set very small.  If the error persists with increased <a class="arg" href="#S">S</a>, consult NAG.</div></dd>
</dl>
<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="#IFeq4"><m:mn mathcolor="#003399" mathvariant="bold">4</m:mn></m:maction></m:math>&#160;or <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFeq5"><m:mn mathcolor="#003399" mathvariant="bold">5</m:mn></m:maction></m:math>, a spline approximation is returned, but it fails to satisfy the fitting criterion (see <a class="eqn" href="#eqn2">(2)</a> and <a class="eqn" href="#eqn3">(3)</a>) &#8211; perhaps by only a small amount, however.</div><h2 class="standard"><a class="sec" name="accuracy" id="accuracy"/>7&#160;&#160;Accuracy</h2>
<div class="paramtext">On successful exit, the approximation returned is such that its weighted sum of squared residuals <m:math><m:mi>&#952;</m:mi></m:math>&#160;(as in <a class="eqn" href="#eqn3">(3)</a>) is equal to the smoothing factor <m:math><m:mi>S</m:mi>
</m:math>, up to a specified relative tolerance of <m:math><m:mn>0.001</m:mn></m:math>&#160;&#8211; except that if <m:math><m:mi>n</m:mi><m:mo>=</m:mo><m:mn>8</m:mn></m:math>, <m:math><m:mi>&#952;</m:mi></m:math>&#160;may be significantly less than <m:math><m:mi>S</m:mi>
</m:math>: in this case the computed spline is simply a weighted least-squares polynomial approximation of degree <m:math><m:mn>3</m:mn></m:math>, i.e., a spline with no interior knots.</div><h2 class="standard"><a class="sec" name="fcomments" id="fcomments"/>8&#160;&#160;Further Comments</h2><h3 class="standard"><a class="sec" name="fc-timing" id="fc-timing"/>8.1&#160;&#160;Timing</h3>
<div class="paramtext">The time taken for a call of E02BEF depends on the complexity of the shape of the data, the value of the smoothing factor <m:math><m:mi>S</m:mi>
</m:math>, and the number of data points.  If E02BEF is to be called for different values of <m:math><m:mi>S</m:mi>
</m:math>, much time can be saved by setting <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#START"><m:mi mathcolor="#EE0000" mathvariant="bold">START</m:mi></m:maction><m:mo>=</m:mo><m:mtext>'W'</m:mtext></m:math>&#160;after the first call.</div><h3 class="standard"><a class="sec" name="fc-choice" id="fc-choice"/>8.2&#160;&#160;Choice of <span class="bitalic">S</span>
</h3>
<div class="paramtext">If the weights have been correctly chosen (see <a class="sec" href="../E02/e02intro.xml#background12">Section 2.1.2</a> in  the E02 Chapter Introduction), the standard deviation of <m:math><m:msub><m:mi>w</m:mi><m:mi>r</m:mi></m:msub><m:msub><m:mi>y</m:mi><m:mi>r</m:mi></m:msub></m:math>&#160;would be the same for all <m:math><m:mi>r</m:mi>
</m:math>, equal to <m:math><m:mi>&#963;</m:mi></m:math>, say.  In this case, choosing the smoothing factor <m:math><m:mi>S</m:mi>
</m:math>&#160;in the range <m:math><m:msup><m:mi>&#963;</m:mi><m:mn>2</m:mn></m:msup><m:mfenced separators=""><m:mi>m</m:mi><m:mo>&#177;</m:mo><m:msqrt><m:mn>2</m:mn><m:mi>m</m:mi></m:msqrt></m:mfenced></m:math>, as suggested by <a class="ref" href="#ref073">Reinsch (1967)</a>, is likely to give a good start in the search for a satisfactory value.  Otherwise, experimenting with different values of <m:math><m:mi>S</m:mi>
</m:math>&#160;will be required from the start, taking account of the remarks in <a class="sec" href="#description">Section 3</a>.</div><div class="paramtext">In that case, in view of computation time and memory requirements, it is recommended to start with a very large value for <m:math><m:mi>S</m:mi>
</m:math>&#160;and so determine the least-squares cubic polynomial; the value returned in  <a class="arg" href="#FP">FP</a>, call it <m:math><m:msub><m:mi>&#952;</m:mi><m:mn>0</m:mn></m:msub></m:math>, gives an upper bound for <m:math><m:mi>S</m:mi>
</m:math>.  Then progressively decrease the value of <m:math><m:mi>S</m:mi>
</m:math>&#160;to obtain closer fits &#8211; say by a factor of <m:math><m:mn>10</m:mn></m:math>&#160;in the beginning, i.e., <m:math><m:mi>S</m:mi><m:mo>=</m:mo><m:msub><m:mi>&#952;</m:mi><m:mn>0</m:mn></m:msub><m:mo>/</m:mo><m:mn>10</m:mn></m:math>, <m:math><m:mi>S</m:mi><m:mo>=</m:mo><m:msub><m:mi>&#952;</m:mi><m:mn>0</m:mn></m:msub><m:mo>/</m:mo><m:mn>100</m:mn></m:math>, and so on, and more carefully as the approximation shows more details.</div><div class="paramtext">The number of knots of the spline returned, and their location, generally depend on the value of <m:math><m:mi>S</m:mi>
</m:math>&#160;and on the behaviour of the function underlying the data.  However, if E02BEF is called with <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#START"><m:mi mathcolor="#EE0000" mathvariant="bold">START</m:mi></m:maction><m:mo>=</m:mo><m:mtext>'W'</m:mtext></m:math>, the knots returned may also depend on the smoothing factors of the previous calls.  Therefore if, after a number of trials with different values of <m:math><m:mi>S</m:mi>
</m:math>&#160;and <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#START"><m:mi mathcolor="#EE0000" mathvariant="bold">START</m:mi></m:maction><m:mo>=</m:mo><m:mtext>'W'</m:mtext></m:math>, a fit can finally be accepted as satisfactory, it may be worthwhile to call E02BEF once more with the selected value for <m:math><m:mi>S</m:mi>
</m:math>&#160;but now using <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#START"><m:mi mathcolor="#EE0000" mathvariant="bold">START</m:mi></m:maction><m:mo>=</m:mo><m:mtext>'C'</m:mtext></m:math>.  Often, E02BEF then returns an approximation with the same quality of fit but with fewer knots, which is therefore better if data reduction is also important.</div><h3 class="standard"><a class="sec" name="fc-method" id="fc-method"/>8.3&#160;&#160;Outline of Method Used</h3>
<div class="paramtext">If <m:math><m:mi>S</m:mi><m:mo>=</m:mo><m:mn>0</m:mn></m:math>, the requisite number of knots is known in advance, i.e., <m:math><m:mi>n</m:mi><m:mo>=</m:mo><m:mi>m</m:mi><m:mo>+</m:mo><m:mn>4</m:mn></m:math>; the interior knots are located immediately as <m:math><m:msub><m:mi>&#955;</m:mi><m:mi>i</m:mi></m:msub><m:mo>=</m:mo><m:msub><m:mi>x</m:mi><m:mrow><m:mi>i</m:mi><m:mo>-</m:mo><m:mn>2</m:mn></m:mrow></m:msub></m:math>, for <m:math><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>5</m:mn><m:mo>,</m:mo><m:mn>6</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>4</m:mn></m:math>.  The corresponding least-squares spline (see <a class="rout" href="../E02/e02baf.xml">E02BAF</a>) is then an interpolating spline and therefore a solution of the problem.</div><div class="paramtext">If <m:math><m:mi>S</m:mi><m:mo>&gt;</m:mo><m:mn>0</m:mn></m:math>, a suitable knot set is built up in stages (starting with no interior knots in the case of a cold start but with the knot set found in a previous call if a warm start is chosen).  At each stage, a spline is fitted to the data by least-squares (see <a class="rout" href="../E02/e02baf.xml">E02BAF</a>) and <m:math><m:mi>&#952;</m:mi></m:math>, the weighted sum of squares of residuals, is computed.  If <m:math><m:mi>&#952;</m:mi><m:mo>&gt;</m:mo><m:mi>S</m:mi>
</m:math>, new knots are added to the knot set to reduce <m:math><m:mi>&#952;</m:mi></m:math>&#160;at the next stage.  The new knots are located in intervals where the fit is particularly poor, their number depending on the value of <m:math><m:mi>S</m:mi>
</m:math>&#160;and on the progress made so far in reducing <m:math><m:mi>&#952;</m:mi></m:math>.  Sooner or later, we find that <m:math><m:mi>&#952;</m:mi><m:mo>&#8804;</m:mo><m:mi>S</m:mi>
</m:math>&#160;and at that point the knot set is accepted.  The routine then goes on to compute the (unique) spline which has this knot set and which satisfies the full fitting criterion specified by <a class="eqn" href="#eqn2">(2)</a> and <a class="eqn" href="#eqn3">(3)</a>.  The theoretical solution has <m:math><m:mi>&#952;</m:mi><m:mo>=</m:mo><m:mi>S</m:mi>
</m:math>.  The routine computes the spline by an iterative scheme which is ended when <m:math><m:mi>&#952;</m:mi><m:mo>=</m:mo><m:mi>S</m:mi>
</m:math>&#160;within a relative tolerance of <m:math><m:mn>0.001</m:mn></m:math>.  The main part of each iteration consists of a linear least-squares computation of special form, done in a similarly stable and efficient manner as in <a class="rout" href="../E02/e02baf.xml">E02BAF</a>.</div><div class="paramtext">An exception occurs when the routine finds at the start that, even with no interior knots <m:math><m:mfenced separators=""><m:mi>n</m:mi><m:mo>=</m:mo><m:mn>8</m:mn></m:mfenced></m:math>, the least-squares spline already has its weighted sum of squares of residuals <m:math><m:mtext/><m:mo>&#8804;</m:mo><m:mi>S</m:mi>
</m:math>.  In this case, since this spline (which is simply a cubic polynomial) also has an optimal value for the smoothness measure <m:math><m:mi>&#951;</m:mi></m:math>, namely zero, it is returned at once as the (trivial) solution.  It will usually mean that <m:math><m:mi>S</m:mi>
</m:math>&#160;has been chosen too large.</div><div class="paramtext">For further details of the algorithm and its use, see <a class="ref" href="#ref072">Dierckx (1981)</a>.</div><h3 class="standard"><a class="sec" name="fc-evaluation" id="fc-evaluation"/>8.4&#160;&#160;Evaluation of Computed Spline</h3>
<div class="paramtext">The value of the computed spline at a given value <a class="arg" href="#X">X</a> may be obtained in the <span class="bitalic">double precision</span> variable <a class="arg" href="../E02/e02bbf.xml#S">S</a> by the call:
<pre class="verbatim">
CALL E02BBF(N,LAMDA,C,X,S,IFAIL)
</pre>


where <a class="arg" href="#N">N</a>, <a class="arg" href="#LAMDA">LAMDA</a> and <a class="arg" href="#C">C</a> are the output parameters of E02BEF.

</div><div class="paramtext">The values of the spline and its first three derivatives at a given value <a class="arg" href="#X">X</a> may be obtained in the <span class="bitalic">double precision</span> array <a class="arg" href="../E02/e02bcf.xml#S">S</a> of dimension at least <m:math><m:mn>4</m:mn></m:math>&#160;by the call:
<pre class="verbatim">
CALL E02BCF(N,LAMDA,C,X,LEFT,S,IFAIL)
</pre>

where if <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="../E02/e02bcf.xml#LEFT"><m:mi mathcolor="#EE0000" mathvariant="bold">LEFT</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math>, left-hand derivatives are computed and if <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="../E02/e02bcf.xml#LEFT"><m:mi mathcolor="#EE0000" mathvariant="bold">LEFT</m:mi></m:maction><m:mo>&#8800;</m:mo><m:mn>1</m:mn></m:math>, right-hand derivatives are calculated.  The value of <a class="arg" href="../E02/e02bcf.xml#LEFT">LEFT</a> is only relevant if <a class="arg" href="#X">X</a> is an interior knot (see <a class="rout" href="../E02/e02bcf.xml">E02BCF</a>).</div><div class="paramtext">The value of the definite integral of the spline over the interval <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mn>1</m:mn></m:mfenced></m:mrow></m:math>&#160;to <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction><m:mfenced separators="," open="(" close=")">
<m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction>
</m:mfenced></m:mrow></m:math>&#160;can be obtained in the <span class="bitalic">double precision</span> variable <a class="arg" href="../E02/e02bdf.xml#DINT">DINT</a> by the call:
<pre class="verbatim">
CALL E02BDF(N,LAMDA,C,DINT,IFAIL)
</pre>

(see <a class="rout" href="../E02/e02bdf.xml">E02BDF</a>).
</div><h2 class="standard"><a class="sec" name="example" id="example"/>9&#160;&#160;Example</h2>
<div class="paramtext">This example reads in a set of data values, followed by a set of values of <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#S"><m:mi mathcolor="#EE0000" mathvariant="bold">S</m:mi></m:maction>
</m:math>.  For each value of <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#S"><m:mi mathcolor="#EE0000" mathvariant="bold">S</m:mi></m:maction>
</m:math>&#160;it calls E02BEF to compute a spline approximation, and prints the values of the knots and the B-spline coefficients <m:math><m:msub><m:mi>c</m:mi><m:mi>i</m:mi></m:msub></m:math>.</div><div class="paramtext">The program includes code to evaluate the computed splines, by calls to <a class="rout" href="../E02/e02bbf.xml">E02BBF</a>, at the points <m:math><m:msub><m:mi>x</m:mi><m:mi>r</m:mi></m:msub></m:math>&#160;and at points mid-way between them.  These values are not printed out, however; instead the results are illustrated by plots of the computed splines, together with the data points (indicated by <m:math><m:mo>&#215;</m:mo></m:math>) and the positions of the knots (indicated by vertical lines): the effect of decreasing <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#S"><m:mi mathcolor="#EE0000" mathvariant="bold">S</m:mi></m:maction>
</m:math>&#160;can be clearly seen.</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/e02befe.f">Program Text (e02befe.f)</a></p><h3 class="standard"><a class="sec" name="examdata" id="examdata"/>9.2&#160;&#160;Program Data</h3>
<p><a class="verbatimref" href="../../examples/data/e02befe.d">Program&#160;Data (e02befe.d)</a></p><h3 class="standard"><a class="sec" name="examresults" id="examresults"/>9.3&#160;&#160;Program Results</h3>
<p><a class="verbatimref" href="../../examples/baseresults/e02befe.r">Program Results (e02befe.r)</a></p><div class="figure"><a name="e02bef1-plot" id="e02bef1-plot"/><img src="../figures/e02bef1-plot.png" alt="Example Program Plot for e02bef1-plot"/></div><div class="figure"><a name="e02bef2-plot" id="e02bef2-plot"/><img src="../figures/e02bef2-plot.png" alt="Example Program Plot for e02bef2-plot"/></div><div class="figure"><a name="e02bef3-plot" id="e02bef3-plot"/><img src="../figures/e02bef3-plot.png" alt="Example Program Plot for e02bef3-plot"/></div>
<hr/><div><a class="rout" href="../../pdf/E02/e02bef.pdf">E02BEF (PDF version)</a></div><div><a class="chap" href="e02conts.xml">E02 Chapter Contents</a></div><div><a class="chapint" href="e02intro.xml">E02 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>