nag_opt_lsq_check_deriv (e04yac) checks that a user-supplied C function for evaluating a vector of functions and the matrix of their first derivatives produces derivative values which are consistent with the function values calculated.
The function
nag_opt_lsq_deriv (e04gbc) for minimizing a sum of squares of
nonlinear functions (or ‘residuals’),
, for
and
, requires you to supply a C function to evaluate the
and their first derivatives. nag_opt_lsq_check_deriv (e04yac) checks the derivatives calculated by such a user-supplied function. As well as the C function to be checked (
lsqfun), you must supply a point
at which the check is to be made.
nag_opt_lsq_check_deriv (e04yac) 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.
fail.
code is set to
NE_DERIV_ERRORS if
for
or 2. (See
Section 3 for definitions of the quantities involved.) The scalar
is set equal to
, where
is the
machine precision as given by
nag_machine_precision (X02AJC).
nag_opt_lsq_check_deriv (e04yac) is not threaded in any implementation.
nag_opt_lsq_check_deriv (e04yac) calls
lsqfun three times.
Before using nag_opt_lsq_check_deriv (e04yac) to check the calculation of the first derivatives, you should be confident that
lsqfun is calculating the residuals correctly.
Suppose that it is intended to use
nag_opt_lsq_deriv (e04gbc) to find least squares estimates of
,
and
in the model
using the 15 sets of data given in the following table:
The following program could be used to check the first derivatives calculated by the required function
lsqfun. (The tests of whether
or 1 in
lsqfun are present for when
lsqfun is called by
nag_opt_lsq_deriv (e04gbc). nag_opt_lsq_check_deriv (e04yac) will always call
lsqfun with
set to 2.)