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.
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 _ )
public: static void e04hc( int n, E04..::..E04HC_FUNCT^ funct, array<double>^ x, [OutAttribute] double% f, array<double>^ g, [OutAttribute] int% ifail )
- Type: System..::..Int32On entry: the number of independent variables in the objective function.Constraint: .
- 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.
- 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.
- Type: System..::..Double%
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.
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.
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.)