nag_check_deriv (c05zbc) 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.
nag_check_deriv (c05zbc) checks the derivatives calculated by user-supplied C functions, e.g., functions of the form required for nag_zero_nonlin_eqns_deriv (c05pbc)
. As well as the C function to be checked f
, you must supply a point
at which the check will be made.
nag_check_deriv (c05zbc) first calls f
to evaluate both the
and their first derivatives, and uses these to calculate the sum of squares
and its first derivatives
The components of
along two orthogonal directions (defined by unit vectors
, say) are then calculated; these will be
respectively. The same components are also estimated by finite differences, giving quantities
is a small positive scalar. If the relative difference between
is judged too large, an error indicator is set.
is set to NE_DERIV_ERRORS
or 2. (See Section 3
for definitions of the quantities involved.) The scalar
is set equal to
is the machine precision
Before using nag_check_deriv (c05zbc) to check the calculation of the first derivatives, you should be confident that f
is evaluating the functions correctly.
This example checks the Jacobian matrix for the problem solved in the example program for nag_zero_nonlin_eqns_deriv (c05pbc)