e04zc Method
関数リスト一覧   NagLibrary Namespaceへ  ライブラリイントロダクション  本ヘルプドキュメントのchm形式版

e04zc checks that user-supplied delegates for evaluating an objective function, constraint functions and their first derivatives, produce derivative values which are consistent with the function and constraint values calculated.

Syntax

C#
public static void e04zc(
	int n,
	int ncnln,
	E04..::.E04ZC_CONFUN confun,
	E04..::.E04ZC_OBJFUN objfun,
	double[] c,
	double[,] cjac,
	out double objf,
	double[] objgrd,
	double[] x,
	out int ifail
)
Visual Basic (Declaration)
Public Shared Sub e04zc ( _
	n As Integer, _
	ncnln As Integer, _
	confun As E04..::.E04ZC_CONFUN, _
	objfun As E04..::.E04ZC_OBJFUN, _
	c As Double(), _
	cjac As Double(,), _
	<OutAttribute> ByRef objf As Double, _
	objgrd As Double(), _
	x As Double(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void e04zc(
	int n, 
	int ncnln, 
	E04..::.E04ZC_CONFUN^ confun, 
	E04..::.E04ZC_OBJFUN^ objfun, 
	array<double>^ c, 
	array<double,2>^ cjac, 
	[OutAttribute] double% objf, 
	array<double>^ objgrd, 
	array<double>^ x, 
	[OutAttribute] int% ifail
)
F#
static member e04zc : 
        n:int * 
        ncnln:int * 
        confun:E04..::.E04ZC_CONFUN * 
        objfun:E04..::.E04ZC_OBJFUN * 
        c:float[] * 
        cjac:float[,] * 
        objf:float byref * 
        objgrd:float[] * 
        x:float[] * 
        ifail:int byref -> unit 

Parameters

n
Type: System..::.Int32
On entry: the number n of independent variables in the objective and constraint functions.
Constraint: n1.
ncnln
Type: System..::.Int32
On entry: the number m of constraint functions.
Constraint: ncnln0.
confun
Type: NagLibrary..::.E04..::.E04ZC_CONFUN
confun must calculate the vector cx of nonlinear constraint functions and its Jacobian for a specified n-vector x. If there are no nonlinear constraints (ncnln=0), confun will not be called by e04zc and confun may be the dummy method e04vdm. (e04vdm is included in the nAG Library.) If there are nonlinear constraints, e04zc always calls confun and objfun together, in that order.

A delegate of type E04ZC_CONFUN.

objfun
Type: NagLibrary..::.E04..::.E04ZC_OBJFUN
objfun must calculate the objective function Fx and its gradient for a specified n-element vector x.

A delegate of type E04ZC_OBJFUN.

c
Type: array< System..::.Double >[]()[]
An array of size [ldcjac]
Note: ldcjac must satisfy the constraint: ldcjacmax1,ncnln
On exit: unless you set mode<0 in the first call of confun, c[i-1] contains the value of cix at the point given in x, for i=1,2,,m.
If ncnln=0, c is not referenced.
cjac
Type: array< System..::.Double ,2>[,](,)[,]
An array of size [ldcjac, n]
Note: ldcjac must satisfy the constraint: ldcjacmax1,ncnln
On exit: unless you set mode<0 in the first call of confun, cjac[i-1,j-1] contains the value of the derivative ci xj  at the point given in x, as calculated by confun, for j=1,2,,n and i=1,2,,m.
If ncnln=0, cjac is not referenced.
objf
Type: System..::.Double %
On exit: unless you set mode<0 in the first call of objfun, objf contains the value of the objective function Fx at the point given in x.
objgrd
Type: array< System..::.Double >[]()[]
An array of size [n]
On exit: unless you set mode<0 in the first call of objfun, objgrd[j-1] contains the value of the derivative F xj  at the point given in x, as calculated by objfun, for j=1,2,,n.
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 x to check the derivatives calculated by confun and objfun. ‘Obvious’ settings such as 0 or 1, should not be used since, at such points, incorrect terms may take correct values (particularly zero), so that errors could go undetected. Similarly, it is preferable that no two elements of x should be equal.
ifail
Type: System..::.Int32 %
On exit: ifail=0 unless the method detects an error (see [Error Indicators and Warnings]).

Description

Routines for minimizing a function of several variables subject to general equality and/or inequality constraints may require you to provide methods to evaluate the objective function Fx1,x2,,xn, constraint functions cix1,x2,,xn, for i=1,2,,m, and their first derivatives. e04zc is designed to check the derivatives calculated by such user-supplied delegates . As well as the methods to be checked (confun and objfun), you must supply a point x=x1,x2,,xnT at which the checks will be made.
To check the first derivatives of F, the method first calls objfun to evaluate F and its first derivatives gj= F xj , for j=1,2,,n, at x. The components of the user-supplied derivatives along two orthogonal directions (defined by unit vectors p1 and p2, say) are then calculated; these will be gTp1 and gTp2 respectively. The same components are also estimated by finite differences, giving quantities
vk=Fx+hpk-Fxh,  k=1,2
where h is a small positive scalar. If the relative difference between v1 and gTp1 or between v2 and gTp2 is ‘judged’ too large, the error indicator ifail (see [Error Indicators and Warnings]) is set to 2.
When n=1 only p1 and v1 are generated.
Similar checks are made of whether components of the first derivatives
c i x j ,   i = 1 , 2 , , m ​ and ​ j = 1 , 2 , , n
(as calculated by confun at x) are consistent with difference approximations to the same quantities.

References

Error Indicators and Warnings

Accuracy

ifail is set to 2 if
vk-gTpk 2h× gTpk 2+1
for k=1​ or ​2. (See [Description] for definitions of the quantities involved.) The scalar h is set equal to ε, where ε is the machine precision (see x02aj).
ifail is set to 2+i if a relation analogous to that given above holds for ci and its calculated derivatives.

Further Comments

The user-supplied delegates confun and objfun are both called three times unless ncnln=0, in which case confun is not called.
Before using e04zc to check the calculation of first derivatives, you should be confident that confun and objfun are calculating F and the ci correctly. The usual way of checking the calculation of these function values is to compare values of Fx and the cix calculated by objfun and confun at nontrivial points x with values calculated independently. (‘Non-trivial’ means that, as when setting x before calling e04zc, coordinates such as 0 or 1 should be avoided.)

Example

See Also