E04HCF checks that a subroutine for evaluating an objective function and its first derivatives produces derivative values which are consistent with the function values calculated.
Routines for minimizing a function of several variables may require you to supply a subroutine to evaluate the objective function
$F\left({x}_{1},{x}_{2},\dots ,{x}_{n}\right)$ and its first derivatives. E04HCF is designed to check the derivatives calculated by such user-supplied subroutines . As well as the routine to be checked (
FUNCT), you must supply a point
$x={\left({x}_{1},{x}_{2},\dots ,{x}_{n}\right)}^{\mathrm{T}}$ at which the check will be made. Note that E04HCF checks routines of the form required for
E04KDF and
E04LBF.
E04HCF first calls
FUNCT to evaluate
$F$ and its first derivatives
${g}_{\mathit{j}}=\frac{\partial F}{\partial {x}_{\mathit{j}}}$, for
$\mathit{j}=1,2,\dots ,n$ at
$x$. The components of the user-supplied derivatives along two orthogonal directions (defined by unit vectors
${p}_{1}$ and
${p}_{2}$, say) are then calculated; these will be
${g}^{\mathrm{T}}{p}_{1}$ and
${g}^{\mathrm{T}}{p}_{2}$ respectively. The same components are also estimated by finite differences, giving quantities
where
$h$ is a small positive scalar. If the relative difference between
${v}_{1}$ and
${g}^{\mathrm{T}}{p}_{1}$ or between
${v}_{2}$ and
${g}^{\mathrm{T}}{p}_{2}$ 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
for
$k=1\text{ or}2$. (See
Section 3 for definitions of the quantities involved.) The scalar
$h$ is set equal to
$\sqrt{\epsilon}$, where
$\epsilon $ is the
machine precision as given by
X02AJF.
Before using E04HCF to check the calculation of first derivatives, you should be confident that
FUNCT is calculating
$F$ correctly. The usual way of checking the calculation of the function is to compare values of
$F\left(x\right)$ calculated by
FUNCT at nontrivial points
$x$ with values calculated independently. (‘Non-trivial’ means that, as when setting
$x$ before calling E04HCF, coordinates such as
$0.0$ or
$1.0$ should be avoided.)
E04HCF only checks the derivatives calculated when
${\mathbf{IFLAG}}=2$. So, if
FUNCT is intended for use in conjunction with a minimization routine which may set
IFLAG to
$1$, you must check that, for given settings of the
${\mathbf{XC}}\left(j\right)$,
FUNCT produces the same values for the
${\mathbf{GC}}\left(j\right)$ when
IFLAG is set to
$1$ as when
IFLAG is set to
$2$.
Suppose that it is intended to use
E04KDF to minimize
The following program could be used to check the first derivatives calculated by
FUNCT. (The tests of whether
${\mathbf{IFLAG}}=0$ or
$1$ in
FUNCT are present ready for when
FUNCT is called by
E04KDF. E04HCF will always call
FUNCT with
IFLAG set to 2.)
None.