C05 Chapter Contents
C05 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentC05ZDF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

C05ZDF checks the user-supplied gradients of a set of nonlinear functions in several variables, for consistency with the functions themselves. The routine must be called twice.

## 2  Specification

 SUBROUTINE C05ZDF ( MODE, M, N, X, FVEC, FJAC, XP, FVECP, ERR, IFAIL)
 INTEGER MODE, M, N, IFAIL REAL (KIND=nag_wp) X(N), FVEC(M), FJAC(M,N), XP(N), FVECP(M), ERR(M)

## 3  Description

C05ZDF is based on the MINPACK routine CHKDER (see Moré et al. (1980)). It checks the $i$th gradient for consistency with the $i$th 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 C05ZDF 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  Parameters

1:     MODE – INTEGERInput
On entry: the value $1$ on the first call and the value $2$ on the second call of C05ZDF.
Constraint: ${\mathbf{MODE}}=1$ or $2$.
2:     M – INTEGERInput
On entry: $m$, the number of functions.
Constraint: ${\mathbf{M}}\ge 1$.
3:     N – INTEGERInput
On entry: $n$, the number of variables. For use with C05RBF, C05RCF and C05RDF, ${\mathbf{M}}={\mathbf{N}}$.
Constraint: ${\mathbf{N}}\ge 1$.
4:     X(N) – REAL (KIND=nag_wp) arrayInput
On entry: the components of a point $x$, at which the consistency check is to be made. (See Section 7.)
5:     FVEC(M) – REAL (KIND=nag_wp) arrayInput
On entry: if ${\mathbf{MODE}}=2$, FVEC must contain the value of the functions evaluated at $x$. If ${\mathbf{MODE}}=1$, FVEC is not referenced.
6:     FJAC(M,N) – REAL (KIND=nag_wp) arrayInput
On entry: if ${\mathbf{MODE}}=2$, FJAC must contain the value of $\frac{\partial {f}_{i}}{\partial {x}_{j}}$ at the point $x$, for $\mathit{i}=1,2,\dots ,m$ and $\mathit{j}=1,2,\dots ,n$. If ${\mathbf{MODE}}=1$, FJAC is not referenced.
7:     XP(N) – REAL (KIND=nag_wp) arrayOutput
On exit: if ${\mathbf{MODE}}=1$, XP is set to a point neighbouring X. If ${\mathbf{MODE}}=2$, XP is undefined.
8:     FVECP(M) – REAL (KIND=nag_wp) arrayInput
On entry: if ${\mathbf{MODE}}=2$, FVECP must contain the value of the functions evaluated at XP (as output by a preceding call to C05ZDF with ${\mathbf{MODE}}=1$). If ${\mathbf{MODE}}=1$, FVECP is not referenced.
9:     ERR(M) – REAL (KIND=nag_wp) arrayOutput
On exit: if ${\mathbf{MODE}}=2$, ERR contains measures of correctness of the respective gradients. If ${\mathbf{MODE}}=1$, ERR is undefined. If there is no loss of significance (see Section 7), then if ${\mathbf{ERR}}\left(i\right)$ is $1.0$ the $i$th user-supplied gradient $\frac{\partial {f}_{i}}{\partial {x}_{j}}$, for $\mathit{j}=1,2,\dots ,n$ is correct, whilst if ${\mathbf{ERR}}\left(i\right)$ is $0.0$ the $i$th gradient is incorrect. For values of ${\mathbf{ERR}}\left(i\right)$ between $0.0$ and $1.0$ the categorisation is less certain. In general, a value of ${\mathbf{ERR}}\left(i\right)>0.5$ indicates that the $i$th gradient is probably correct.
10:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{MODE}}\ne 1$ or $2$.
${\mathbf{IFAIL}}=2$
On entry, ${\mathbf{M}}<1$.
${\mathbf{IFAIL}}=3$
On entry, ${\mathbf{N}}<1$.

## 7  Accuracy

C05ZDF 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 X02AJF.

The time required by C05ZDF 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 (c05zdfe.f90)

None.

### 9.3  Program Results

Program Results (c05zdfe.r)