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

# Syntax

C#
```public static void c05zd(
int mode,
int m,
int n,
double[] x,
double[] fvec,
double[,] fjac,
double[] xp,
double[] fvecp,
double[] err,
out int ifail
)```
Visual Basic
```Public Shared Sub c05zd ( _
mode As Integer, _
m As Integer, _
n As Integer, _
x As Double(), _
fvec As Double(), _
fjac As Double(,), _
xp As Double(), _
fvecp As Double(), _
err As Double(), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void c05zd(
int mode,
int m,
int n,
array<double>^ x,
array<double>^ fvec,
array<double,2>^ fjac,
array<double>^ xp,
array<double>^ fvecp,
array<double>^ err,
[OutAttribute] int% ifail
)```
F#
```static member c05zd :
mode : int *
m : int *
n : int *
x : float[] *
fvec : float[] *
fjac : float[,] *
xp : float[] *
fvecp : float[] *
err : float[] *
ifail : int byref -> unit
```

#### Parameters

mode
Type: System..::..Int32
On entry: the value $1$ on the first call and the value $2$ on the second call of c05zd.
Constraint: ${\mathbf{mode}}=1$ or $2$.
m
Type: System..::..Int32
On entry: $m$, the number of functions.
Constraint: ${\mathbf{m}}\ge 1$.
n
Type: System..::..Int32
On entry: $n$, the number of variables. For use with c05rbc05rc and c05rd, ${\mathbf{m}}={\mathbf{n}}$.
Constraint: ${\mathbf{n}}\ge 1$.
x
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: the components of a point $x$, at which the consistency check is to be made. (See [Accuracy].)
fvec
Type: array<System..::..Double>[]()[][]
An array of size [m]
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.
fjac
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [m, n]
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.
xp
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: if ${\mathbf{mode}}=1$, xp is set to a point neighbouring x. If ${\mathbf{mode}}=2$, xp is undefined.
fvecp
Type: array<System..::..Double>[]()[][]
An array of size [m]
On entry: if ${\mathbf{mode}}=2$, fvecp must contain the value of the functions evaluated at xp (as output by a preceding call to c05zd with ${\mathbf{mode}}=1$). If ${\mathbf{mode}}=1$, fvecp is not referenced.
err
Type: array<System..::..Double>[]()[][]
An array of size [m]
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 [Accuracy]), then if ${\mathbf{err}}\left[i-1\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-1\right]$ is $0.0$ the $i$th gradient is incorrect. For values of ${\mathbf{err}}\left[i-1\right]$ between $0.0$ and $1.0$ the categorisation is less certain. In general, a value of ${\mathbf{err}}\left[i-1\right]>0.5$ indicates that the $i$th gradient is probably correct.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

c05zd 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 c05zd is its invariance under changes in scale of the variables or functions.

# 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

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{mode}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mode}}=1$ or $2$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 1$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

c05zd 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 x02aj.

# Parallelism and Performance

None.

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