e04hd checks that a method for calculating second derivatives of an objective function is consistent with a method for calculating the corresponding first derivatives.

Syntax

C#
public static void e04hd(
	int n,
	E04..::..E04HD_FUNCT funct,
	E04..::..E04HD_H h,
	double[] x,
	double[] g,
	double[] hesl,
	double[] hesd,
	out int ifail
)
Visual Basic
Public Shared Sub e04hd ( _
	n As Integer, _
	funct As E04..::..E04HD_FUNCT, _
	h As E04..::..E04HD_H, _
	x As Double(), _
	g As Double(), _
	hesl As Double(), _
	hesd As Double(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void e04hd(
	int n, 
	E04..::..E04HD_FUNCT^ funct, 
	E04..::..E04HD_H^ h, 
	array<double>^ x, 
	array<double>^ g, 
	array<double>^ hesl, 
	array<double>^ hesd, 
	[OutAttribute] int% ifail
)
F#
static member e04hd : 
        n : int * 
        funct : E04..::..E04HD_FUNCT * 
        h : E04..::..E04HD_H * 
        x : float[] * 
        g : float[] * 
        hesl : float[] * 
        hesd : float[] * 
        ifail : int byref -> unit 

Parameters

n
Type: System..::..Int32
On entry: the number n of independent variables in the objective function.
Constraint: n1.
funct
Type: NagLibrary..::..E04..::..E04HD_FUNCT
funct must evaluate the function and its first derivatives at a given point. (e04lb gives you the option of resetting parameters of funct to cause the minimization process to terminate immediately. e04hd will also terminate immediately, without finishing the checking process, if the parameter in question is reset.)

A delegate of type E04HD_FUNCT.

e04hc should be used to check the first derivatives calculated by funct before e04hd is used to check the second derivatives, since e04hd assumes that the first derivatives are correct.
h
Type: NagLibrary..::..E04..::..E04HD_H
h must evaluate the second derivatives of the function at a given point. (As with funct, a parameter can be set to cause immediate termination.)

A delegate of type E04HD_H.

x
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: x[j-1], for j=1,2,,n must contain the coordinates of a suitable point at which to check the derivatives calculated by funct. ‘Obvious’ settings, such as 0.0​ or ​1.0, should not be used since, at such particular points, incorrect terms may take correct values (particularly zero), so that errors could go undetected. Similarly, it is advisable that no two elements of x should be the same.
g
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: unless you set iflag negative in the first call of funct, g[j-1] contains the value of the first derivative Fxj at the point given in x, as calculated by funct, for j=1,2,,n.
hesl
Type: array<System..::..Double>[]()[][]
An array of size [lh]
On exit: unless you set iflag negative in h, hesl contains the strict lower triangle of the second derivative matrix of F, as evaluated by h at the point given in x, stored by rows.
hesd
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: unless you set iflag negative in h, hesd contains the diagonal elements of the second derivative matrix of F, as evaluated by h at the point given in x.
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

Routines for minimizing a function Fx1,x2,,xn of the variables x1,x2,,xn may require you to provide a method to evaluate the second derivatives of F. e04hd is designed to check the second derivatives calculated by such user-supplied delegates. As well as the method to be checked (h), you must supply a method (funct) to evaluate the first derivatives, and a point x=x1,x2,,xnT at which the checks will be made. Note that e04hd checks methods of the form required for e04lb.
e04hd first calls user-supplied delegates funct and h to evaluate the first and second derivatives of F at x. The user-supplied Hessian matrix (H, say) is projected onto two orthogonal vectors y and z to give the scalars yTHy and zTHz respectively. The same projections of the Hessian matrix are also estimated by finite differences, giving
p=yTgx+hy-yTgx/handq=zTgx+hz-zTgx/h
respectively, where g denotes the vector of first derivatives at the point in brackets and h is a small positive scalar. If the relative difference between p and yTHy or between q and zTHz is judged too large, an error indicator is set.

References

None.

Error Indicators and Warnings

Note: e04hd 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 (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 e04hd because you have set iflag negative in funct or h. The value of ifail will be the same as the value you set for iflag. The check on h will not have been completed.
ifail=1
On entry,n<1,
orlh<max1,n×n-1/2,
ifail=2
You should check carefully the derivation and programming of expressions for the second derivatives of Fx, because it is very unlikely that h is calculating them correctly.
ifail=-9000
An error occured, see message report.
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

ifail is set to 2 if
yTHy-ph×yTHy+1.0  or ​zTHz-qh×zTHz+1.0
where h is set equal to ε (ε being the machine precision as given by x02aj) and other quantities are as defined in [Description].

Parallelism and Performance

None.

Further Comments

e04hd calls h once and funct three times.

Example

See Also