E04YAF checks that a user-supplied subroutine for evaluating a vector of functions and the matrix of their first derivatives produces derivative values which are consistent with the function values calculated.
Routines for minimizing a sum of squares of
nonlinear functions (or ‘residuals’),
, for
and
, may require you to supply a subroutine to evaluate the
and their first derivatives. E04YAF checks the derivatives calculated by such user-supplied subroutines, e.g., routines of the form required for
E04GBF,
E04GDF and
E04HEF. As well as the routine to be checked (
LSQFUN), you must supply a point
at which the check will be made. E04YAF is essentially identical to CHKLSJ in the NPL Algorithms Library.
E04YAF first calls
LSQFUN to evaluate the
and their first derivatives, and uses these to calculate the sum of squares
,
and its first derivatives
, for
. The components of
along two orthogonal directions (defined by unit vectors
and
, say) are then calculated; these will be
and
respectively. The same components are also estimated by finite differences, giving quantities
where
is a small positive scalar. If the relative difference between
and
or between
and
is judged too large, an error indicator is set.
None.
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
IFAIL is set to
if
for
. (See
Section 3 for definitions of the quantities involved.) The scalar
is set equal to
, where
is the
machine precision as given by
X02AJF.
Not applicable.
Before using E04YAF to check the calculation of the first derivatives, you should be confident that
LSQFUN is calculating the residuals correctly.
E04YAF only checks the derivatives calculated by a user-supplied routine when
. So, if
LSQFUN is intended for use in conjunction with a minimization routine which may set
IFLAG to
, you must check that, for given settings of the
,
LSQFUN produces the same values for the
when
IFLAG is set to
as when
IFLAG is set to
.
Suppose that it is intended to use
E04GBF or
E04GDF to find least squares estimates of
and
in the model
using the
sets of data given in the following table.
The following program could be used to check the first derivatives calculated by
LSQFUN. (The tests of whether
or
in
LSQFUN are present ready for when
LSQFUN is called by
E04GBF or
E04GDF. E04YAF will always call
LSQFUN with
IFLAG set to 2.)