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, fix, and the number n of variables, xj.
Constraint: 1nm.
n
Type: System..::..Int32
On entry: the number m of residuals, fix, and the number n of variables, xj.
Constraint: 1nm.
lsqfun
Type: NagLibrary..::..E04..::..E04YB_LSQFUN
lsqfun must calculate the vector of values fix and their first derivatives fixj 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 bjk 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 Gix is the Hessian matrix of fix. (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: x[j-1], for j=1,2,,n, must be set to the coordinates of a suitable point at which to check the bjk 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, fvec[i-1] contains the value of fi at the point supplied by you in x, for i=1,2,,m.
fjac
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: dim1m
On exit: unless you set iflag negative in the first call of lsqfun, fjac[i-1,j-1] contains the value of the first derivative fixj at the point given in x, as calculated by lsqfun, for i=1,2,,m and j=1,2,,n.
b
Type: array<System..::..Double>[]()[][]
An array of size [lb]
On exit: unless you set iflag negative in lsqhes, b[j×j-1/2+k-1] contains the value of bjk at the point given in x as calculated by lsqhes, for j=1,2,,n and k=1,2,,j.
ifail
Type: System..::..Int32%
On exit: 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’), fix1,x2,,xn, for i=1,2,,m and mn, may require you to supply a method to evaluate the quantities
bjk=i=1mfi2fixjxk
for j=1,2,,n and k=1,2,,j. e04yb is designed to check the bjk calculated by such user-supplied delegates. As well as the method to be checked (lsqhes), you must supply a method (lsqfun) to evaluate the fi and their first derivatives, and a point x=x1,x2,,xnT 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 bjk 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 yTGy and zTGz 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 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 yTGy or between q and zTGz is judged too large, an error indicator is set.

References

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.
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.
ifail=1
On entry,m<n,
orn<1,
orlb<n+1×n/2,
ifail=2
You should check carefully the derivation and programming of expressions for the bjk, because it is very unlikely that lsqhes is calculating them correctly.
ifail=-9000
An error occured, see message report.
ifail=-6000
Invalid Parameters value
ifail=-4000
Invalid dimension for array value
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

ifail is set to 2 if
yTGy-phyTGy+1.0orzTGz-qhzTGz+1.0
where h is set equal to ε (ε being the machine precision as given by x02aj) and other quantities are defined as in [Description].

Parallelism and Performance

None.

Further Comments

e04yb calls lsqhes once and lsqfun three times.

Example

See Also