e04hc checks that a method for evaluating an objective function and its first derivatives produces derivative values which are consistent with the function values calculated.
Syntax
C# |
---|
public static void e04hc( int n, E04..::..E04HC_FUNCT funct, double[] x, out double f, double[] g, out int ifail ) |
Visual Basic |
---|
Public Shared Sub e04hc ( _ n As Integer, _ funct As E04..::..E04HC_FUNCT, _ x As Double(), _ <OutAttribute> ByRef f As Double, _ g As Double(), _ <OutAttribute> ByRef ifail As Integer _ ) |
Visual C++ |
---|
public: static void e04hc( int n, E04..::..E04HC_FUNCT^ funct, array<double>^ x, [OutAttribute] double% f, array<double>^ g, [OutAttribute] int% ifail ) |
F# |
---|
static member e04hc : n : int * funct : E04..::..E04HC_FUNCT * x : float[] * f : float byref * g : float[] * ifail : int byref -> unit |
Parameters
- n
- Type: System..::..Int32On entry: the number of independent variables in the objective function.Constraint: .
- funct
- Type: NagLibrary..::..E04..::..E04HC_FUNCTfunct must evaluate the function and its first derivatives at a given point. (The minimization methods mentioned in [Description] gives you the option of resetting parameters of funct to cause the minimization process to terminate immediately. e04hc will also terminate immediately, without finishing the checking process, if the parameter in question is reset.)
A delegate of type E04HC_FUNCT.
- x
- Type: array<System..::..Double>[]()[][]An array of size [n]On entry: , for , must be set to the coordinates of a suitable point at which to check the derivatives calculated by funct. ‘Obvious’ settings, such as , 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 preferable that no two elements of x should be the same.
- f
- Type: System..::..Double%
- g
- Type: array<System..::..Double>[]()[][]An array of size [n]
- ifail
- Type: System..::..Int32%On exit: unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).
Description
Routines for minimizing a function of several variables may require you to supply a method to evaluate the objective function and its first derivatives. e04hc is designed to check the derivatives calculated by such user-supplied delegates . As well as the method to be checked ( funct), you must supply a point at which the check will be made. Note that e04hc checks methods of the form required for e04kd and e04lb.
e04hc first calls funct to evaluate and its first derivatives , for at . The components of the user-supplied derivatives along two orthogonal directions (defined by unit vectors and , say) are then calculated; these will be and respectively. The same components are also estimated by finite differences, giving quantities
where is a small positive scalar. If the relative difference between and or between and is judged too large, an error indicator is set.
References
None.
Error Indicators and Warnings
Note: e04hc may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
On entry, , or , or .
- You should check carefully the derivation and programming of expressions for the derivatives of , because it is very unlikely that funct is calculating them correctly.
Accuracy
ifail is set to if
for . (See [Description] for definitions of the quantities involved.) The scalar is set equal to , where is the machine precision as given by x02aj.
Parallelism and Performance
None.
Further Comments
funct is called times.
Before using e04hc to check the calculation of first derivatives, you should be confident that funct is calculating correctly. The usual way of checking the calculation of the function is to compare values of calculated by funct at nontrivial points with values calculated independently. (‘Non-trivial’ means that, as when setting before calling e04hc, coordinates such as or should be avoided.)