E04YBF checks that a user-supplied subroutine for evaluating the second derivative term of the Hessian matrix of a sum of squares is consistent with a user-supplied subroutine for calculating the corresponding first derivatives.
Routines for minimizing a sum of squares of
$m$ nonlinear functions (or ‘residuals’),
${f}_{\mathit{i}}\left({x}_{1},{x}_{2},\dots ,{x}_{n}\right)$, for
$\mathit{i}=1,2,\dots ,m$ and
$m\ge n$, may require you to supply a subroutine to evaluate the quantities
for
$j=1,2,\dots ,n$ and
$k=1,2,\dots ,j$. E04YBF is designed to check the
${b}_{jk}$ calculated by such user-supplied subroutines. As well as the routine to be checked (
LSQHES), you must supply a subroutine (
LSQFUN) to evaluate the
${f}_{i}$ and their first derivatives, and a point
$x={\left({x}_{1},{x}_{2},\dots ,{x}_{n}\right)}^{\mathrm{T}}$ at which the checks will be made. Note that E04YBF checks routines of the form required by
E04HEF. E04YBF is essentially identical to CHKLSH in the NPL Algorithms Library.
E04YBF first calls user-supplied subroutines
LSQFUN and
LSQHES to evaluate the first derivatives and the
${b}_{jk}$ at
$x$. Let
$J$ denote the
$m$ by
$n$ matrix of first derivatives of the residuals. The Hessian matrix of the sum of squares,
is calculated and projected onto two orthogonal vectors
$y$ and
$z$ to give the scalars
${y}^{\mathrm{T}}Gy$ and
${z}^{\mathrm{T}}Gz$ respectively. The same projections of the Hessian matrix are also estimated by finite differences, giving
respectively, where
$g\left(\right)$ denotes the gradient vector of the sum of squares at the point in brackets and
$h$ is a small positive scalar. If the relative difference between
$p$ and
${y}^{\mathrm{T}}Gy$ or between
$q$ and
${z}^{\mathrm{T}}Gz$ is judged too large, an error indicator is set.
None.
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${-{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
IFAIL is set to
$2$ if
where
$h$ is set equal to
$\sqrt{\epsilon}$ (
$\epsilon $ being the
machine precision as given by
X02AJF) and other quantities are defined as in
Section 3.
Suppose that it is intended to use
E04HEF to find least squares estimates of
${x}_{1},{x}_{2}$ and
${x}_{3}$ in the model
using the
$15$ sets of data given in the following table.
This example program could be used to check the
${b}_{jk}$ calculated by
LSQHES required. (The call of E04YBF is preceded by a call of
E04YAF to check
LSQFUN which calculates the first derivatives.)