nag_check_derivs (c05zdc) (PDF version)
c05 Chapter Contents
c05 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_check_derivs (c05zdc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_check_derivs (c05zdc) checks the user-supplied gradients of a set of nonlinear functions in several variables, for consistency with the functions themselves. The function must be called twice.

2  Specification

#include <nag.h>
#include <nagc05.h>
void  nag_check_derivs (Integer mode, Integer m, Integer n, const double x[], const double fvec[], const double fjac[], double xp[], const double fvecp[], double err[], NagError *fail)

3  Description

nag_check_derivs (c05zdc) is based on the MINPACK routine CHKDER (see Moré et al. (1980)). It checks the ith gradient for consistency with the ith function by computing a forward-difference approximation along a suitably chosen direction and comparing this approximation with the user-supplied gradient along the same direction. The principal characteristic of nag_check_derivs (c05zdc) is its invariance under changes in scale of the variables or functions.

4  References

Moré J J, Garbow B S and Hillstrom K E (1980) User guide for MINPACK-1 Technical Report ANL-80-74 Argonne National Laboratory

5  Arguments

1:     modeIntegerInput
On entry: the value 1 on the first call and the value 2 on the second call of nag_check_derivs (c05zdc).
Constraint: mode=1 or 2.
2:     mIntegerInput
On entry: m, the number of functions.
Constraint: m1.
3:     nIntegerInput
Constraint: n1.
4:     x[n]const doubleInput
On entry: the components of a point x, at which the consistency check is to be made. (See Section 7.)
5:     fvec[m]const doubleInput
On entry: if mode=2, fvec must contain the value of the functions evaluated at x. If mode=1, fvec is not referenced.
6:     fjac[m×n]const doubleInput
Note: the i,jth element of the matrix is stored in fjac[j-1×m+i-1].
On entry: if mode=2, fjac must contain the value of fi xj  at the point x, for i=1,2,,m and j=1,2,,n. If mode=1, fjac is not referenced.
7:     xp[n]doubleOutput
On exit: if mode=1, xp is set to a point neighbouring x. If mode=2, xp is undefined.
8:     fvecp[m]const doubleInput
On entry: if mode=2, fvecp must contain the value of the functions evaluated at xp (as output by a preceding call to nag_check_derivs (c05zdc) with mode=1). If mode=1, fvecp is not referenced.
9:     err[m]doubleOutput
On exit: if mode=2, err contains measures of correctness of the respective gradients. If mode=1, err is undefined. If there is no loss of significance (see Section 7), then if err[i-1] is 1.0 the ith user-supplied gradient fi xj , for j=1,2,,n is correct, whilst if err[i-1] is 0.0 the ith gradient is incorrect. For values of err[i-1] between 0.0 and 1.0 the categorization is less certain. In general, a value of err[i-1]>0.5 indicates that the ith gradient is probably correct.
10:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

On entry, argument value had an illegal value.
On entry, m=value.
Constraint: m1.
On entry, mode=value.
Constraint: mode=1 or 2.
On entry, n=value.
Constraint: n1.
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.

7  Accuracy

nag_check_derivs (c05zdc) does not perform reliably if cancellation or rounding errors cause a severe loss of significance in the evaluation of a function. Therefore, none of the components of x should be unusually small (in particular, zero) or any other value which may cause loss of significance. The relative differences between corresponding elements of fvecp and fvec should be at least two orders of magnitude greater than the machine precision returned by nag_machine_precision (X02AJC).

8  Further Comments

The time required by nag_check_derivs (c05zdc) increases with m and n.

9  Example

This example checks the Jacobian matrix for a problem with 15 functions of 3 variables (sometimes referred to as the Bard problem).

9.1  Program Text

Program Text (c05zdce.c)

9.2  Program Data


9.3  Program Results

Program Results (c05zdce.r)

nag_check_derivs (c05zdc) (PDF version)
c05 Chapter Contents
c05 Chapter Introduction
NAG C Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012