The function
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.
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.
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
. (See
Section 3 for definitions of the quantities involved.) The scalar
is set equal to
, where
is the
machine precision as given by
X02AJC.
Before using
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
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
e04gbc.
e04yac will always call
lsqfun with
set to 2.)