e04yb checks that a user-supplied method for evaluating the second derivative term of the Hessian matrix of a sum of squares is consistent with a user-supplied method for calculating the corresponding first derivatives.

# Syntax

C#
```public static void e04yb(
int m,
int n,
E04..::..E04YB_LSQFUN lsqfun,
E04..::..E04YB_LSQHES lsqhes,
double[] x,
double[] fvec,
double[,] fjac,
double[] b,
out int ifail
)```
Visual Basic
```Public Shared Sub e04yb ( _
m As Integer, _
n As Integer, _
lsqfun As E04..::..E04YB_LSQFUN, _
lsqhes As E04..::..E04YB_LSQHES, _
x As Double(), _
fvec As Double(), _
fjac As Double(,), _
b As Double(), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void e04yb(
int m,
int n,
E04..::..E04YB_LSQFUN^ lsqfun,
E04..::..E04YB_LSQHES^ lsqhes,
array<double>^ x,
array<double>^ fvec,
array<double,2>^ fjac,
array<double>^ b,
[OutAttribute] int% ifail
)```
F#
```static member e04yb :
m : int *
n : int *
lsqfun : E04..::..E04YB_LSQFUN *
lsqhes : E04..::..E04YB_LSQHES *
x : float[] *
fvec : float[] *
fjac : float[,] *
b : float[] *
ifail : int byref -> unit
```

#### Parameters

m
Type: System..::..Int32
On entry: the number $m$ of residuals, ${f}_{i}\left(x\right)$, and the number $n$ of variables, ${x}_{j}$.
Constraint: $1\le {\mathbf{n}}\le {\mathbf{m}}$.
n
Type: System..::..Int32
On entry: the number $m$ of residuals, ${f}_{i}\left(x\right)$, and the number $n$ of variables, ${x}_{j}$.
Constraint: $1\le {\mathbf{n}}\le {\mathbf{m}}$.
lsqfun
Type: NagLibrary..::..E04..::..E04YB_LSQFUN
lsqfun must calculate the vector of values ${f}_{i}\left(x\right)$ and their first derivatives $\frac{\partial {f}_{i}}{\partial {x}_{j}}$ at any point $x$. (e04he gives you the option of resetting parameters of lsqfun to cause the minimization process to terminate immediately. e04yb will also terminate immediately, without finishing the checking process, if the parameter in question is reset.)

A delegate of type E04YB_LSQFUN.

Note:  e04ya should be used to check the first derivatives calculated by lsqfun before e04yb is used to check the ${b}_{jk}$ since e04yb assumes that the first derivatives are correct.
lsqhes
Type: NagLibrary..::..E04..::..E04YB_LSQHES
lsqhes must calculate the elements of the symmetric matrix
 $Bx=∑i=1mfixGix,$
at any point $x$, where ${G}_{i}\left(x\right)$ is the Hessian matrix of ${f}_{i}\left(x\right)$. (As with lsqfun, a parameter can be set to cause immediate termination.)

A delegate of type E04YB_LSQHES.

x
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: ${\mathbf{x}}\left[\mathit{j}-1\right]$, for $\mathit{j}=1,2,\dots ,n$, must be set to the coordinates of a suitable point at which to check the ${b}_{jk}$ calculated by lsqhes. ‘Obvious’ settings, such as $0$ or $1$, should not be used since, at such particular points, incorrect terms may take correct values (particularly zero), so that errors could go undetected. For a similar reason, it is preferable that no two elements of x should have the same value.
fvec
Type: array<System..::..Double>[]()[][]
An array of size [m]
On exit: unless you set iflag negative in the first call of lsqfun, ${\mathbf{fvec}}\left[\mathit{i}-1\right]$ contains the value of ${f}_{\mathit{i}}$ at the point supplied by you in x, for $\mathit{i}=1,2,\dots ,m$.
fjac
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{m}}$
On exit: unless you set iflag negative in the first call of lsqfun, ${\mathbf{fjac}}\left[\mathit{i}-1,\mathit{j}-1\right]$ contains the value of the first derivative $\frac{\partial {f}_{\mathit{i}}}{\partial {x}_{\mathit{j}}}$ at the point given in x, as calculated by lsqfun, for $\mathit{i}=1,2,\dots ,m$ and $\mathit{j}=1,2,\dots ,n$.
b
Type: array<System..::..Double>[]()[][]
An array of size [lb]
On exit: unless you set iflag negative in lsqhes, ${\mathbf{b}}\left[\mathit{j}×\left(\mathit{j}-1\right)/2+\mathit{k}-1\right]$ contains the value of ${b}_{\mathit{j}\mathit{k}}$ at the point given in x as calculated by lsqhes, for $\mathit{j}=1,2,\dots ,n$ and $\mathit{k}=1,2,\dots ,\mathit{j}$.
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

Methods for minimizing a sum of squares of $m$ nonlinear functions (or ‘residuals’), ${f}_{\mathit{i}}\left({x}_{1},{x}_{2},\dots ,{x}_{n}\right)$, for $\mathit{i}=1,2,\dots ,m$ and $m\ge n$, may require you to supply a method to evaluate the quantities
 $bjk=∑i=1mfi∂2fi∂xj∂xk$
for $j=1,2,\dots ,n$ and $k=1,2,\dots ,j$. e04yb is designed to check the ${b}_{jk}$ calculated by such user-supplied delegates. As well as the method to be checked (lsqhes), you must supply a method (lsqfun) to evaluate the ${f}_{i}$ and their first derivatives, and a point $x={\left({x}_{1},{x}_{2},\dots ,{x}_{n}\right)}^{\mathrm{T}}$ at which the checks will be made. Note that e04yb checks methods of the form required by e04he. e04yb is essentially identical to CHKLSH in the NPL Algorithms Library.
e04yb first calls user-supplied delegates lsqfun and lsqhes to evaluate the first derivatives and the ${b}_{jk}$ at $x$. Let $J$ denote the $m$ by $n$ matrix of first derivatives of the residuals. The Hessian matrix of the sum of squares,
 $G=JTJ+B,$
is calculated and projected onto two orthogonal vectors $y$ and $z$ to give the scalars ${y}^{\mathrm{T}}Gy$ and ${z}^{\mathrm{T}}Gz$ respectively. The same projections of the Hessian matrix are also estimated by finite differences, giving
 $p=yTgx+hy-yTgx/h andq=zTgx+hz-zTgx/h$
respectively, where $g\left(\right)$ denotes the gradient vector of the sum of squares at the point in brackets and $h$ is a small positive scalar. If the relative difference between $p$ and ${y}^{\mathrm{T}}Gy$ or between $q$ and ${z}^{\mathrm{T}}Gz$ is judged too large, an error indicator is set.

None.

# Error Indicators and Warnings

Note: e04yb may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDFJAC, IW, LIW, W, LW) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}<0$
A negative value of ifail indicates an exit from e04yb because you have set iflag negative in user-supplied delegates lsqfun or lsqhes. The setting of ifail will be the same as your setting of iflag. The check on lsqhes will not have been completed.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{m}}<{\mathbf{n}}$, or ${\mathbf{n}}<1$, or ${\mathbf{lb}}<\left({\mathbf{n}}+1\right)×{\mathbf{n}}/2$,
${\mathbf{ifail}}=2$
You should check carefully the derivation and programming of expressions for the ${b}_{jk}$, because it is very unlikely that lsqhes is calculating them correctly.
${\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

ifail is set to $2$ if
 $yTGy-p≥hyTGy+1.0orzTGz-q≥hzTGz+1.0$
where $h$ is set equal to $\sqrt{\epsilon }$ ($\epsilon$ being the machine precision as given by x02aj) and other quantities are defined as in [Description].

None.