E04KDF (PDF version)
E04 Chapter Contents
E04 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

E04KDF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

E04KDF is a comprehensive modified Newton algorithm for finding:
First derivatives are required. The routine is intended for functions which have continuous first and second derivatives (although it will usually work even if the derivatives have occasional discontinuities).

2  Specification

SUBROUTINE E04KDF ( N, FUNCT, MONIT, IPRINT, MAXCAL, ETA, XTOL, DELTA, STEPMX, IBOUND, BL, BU, X, HESL, LH, HESD, ISTATE, F, G, IW, LIW, W, LW, IFAIL)
INTEGER  N, IPRINT, MAXCAL, IBOUND, LH, ISTATE(N), IW(LIW), LIW, LW, IFAIL
REAL (KIND=nag_wp)  ETA, XTOL, DELTA, STEPMX, BL(N), BU(N), X(N), HESL(LH), HESD(N), F, G(N), W(LW)
EXTERNAL  FUNCT, MONIT

3  Description

E04KDF is applicable to problems of the form:
MinimizeFx1,x2,,xn  subject to  ljxjuj,  j=1,2,,n.
Special provision is made for unconstrained minimization (i.e., problems which actually have no bounds on the xj), problems which have only non-negativity bounds, and problems in which l1=l2==ln and u1=u2==un. It is possible to specify that a particular xj should be held constant. You must supply a starting point, and a FUNCT to calculate the value of Fx and its first derivatives F xj  at any point x.
A typical iteration starts at the current point x where nz (say) variables are free from their bounds. The vector gz, whose elements are the derivatives of Fx with respect to the free variables, is known. The matrix of second derivatives with respect to the free variables, H, is estimated by finite differences. (Note that gz and H are both of dimension nz.) The equations
H+Epz=-gz
are solved to give a search direction pz. (The matrix E is chosen so that H+E is positive definite.)
pz is then expanded to an n-vector p by the insertion of appropriate zero elements, α is found such that Fx+αp is approximately a minimum (subject to the fixed bounds) with respect to α; and x is replaced by x+αp. (If a saddle point is found, a special search is carried out so as to move away from the saddle point.) If any variable actually reaches a bound, it is fixed and nz is reduced for the next iteration.
There are two sets of convergence criteria – a weaker and a stronger. Whenever the weaker criteria are satisfied, the Lagrange multipliers are estimated for all the active constraints. If any Lagrange multiplier estimate is significantly negative, then one of the variables associated with a negative Lagrange multiplier estimate is released from its bound and the next search direction is computed in the extended subspace (i.e., nz is increased). Otherwise minimization continues in the current subspace until the stronger convergence criteria are satisfied. If at this point there are no negative or near-zero Lagrange multiplier estimates, the process is terminated.
If you specify that the problem is unconstrained, E04KDF sets the lj to -106 and the uj to 106. Thus, provided that the problem has been sensibly scaled, no bounds will be encountered during the minimization process and E04KDF will act as an unconstrained minimization algorithm.

4  References

Gill P E and Murray W (1973) Safeguarded steplength algorithms for optimization using descent methods NPL Report NAC 37 National Physical Laboratory
Gill P E and Murray W (1974) Newton-type methods for unconstrained and linearly constrained optimization Math. Program. 7 311–350
Gill P E and Murray W (1976) Minimization subject to bounds on the variables NPL Report NAC 72 National Physical Laboratory

5  Parameters

1:     N – INTEGERInput
On entry: the number n of independent variables.
Constraint: N1.
2:     FUNCT – SUBROUTINE, supplied by the user.External Procedure
FUNCT must evaluate the function Fx and its first derivatives F xj  at a specified point. (However, if you do not wish to calculate F or its first derivatives at a particular x, there is the option of setting a parameter to cause E04KDF to terminate immediately.)
The specification of FUNCT is:
SUBROUTINE FUNCT ( IFLAG, N, XC, FC, GC, IW, LIW, W, LW)
INTEGER  IFLAG, N, IW(LIW), LIW, LW
REAL (KIND=nag_wp)  XC(N), FC, GC(N), W(LW)
1:     IFLAG – INTEGERInput/Output
On entry: will have been set to 1 or 2. The value 1 indicates that only the first derivatives of F need be supplied, and the value 2 indicates that both F itself and its first derivatives must be calculated.
On exit: if it is not possible to evaluate F or its first derivatives at the point given in XC (or if it is wished to stop the calculations for any other reason) you should reset IFLAG to a negative number and return control to E04KDF. E04KDF will then terminate immediately, with IFAIL set to your setting of IFLAG.
2:     N – INTEGERInput
On entry: the number n of variables.
3:     XC(N) – REAL (KIND=nag_wp) arrayInput
On entry: the point x at which the F xj , or F and the F xj , are required.
4:     FC – REAL (KIND=nag_wp)Output
On exit: unless IFLAG=1 on entry or IFLAG is reset, FUNCT must set FC to the value of the objective function F at the current point x.
5:     GC(N) – REAL (KIND=nag_wp) arrayOutput
On exit: unless FUNCT resets IFLAG, it must set GCj to the value of the first derivative F xj  at the point x, for j=1,2,,n.
6:     IW(LIW) – INTEGER arrayWorkspace
7:     LIW – INTEGERInput
8:     W(LW) – REAL (KIND=nag_wp) arrayWorkspace
9:     LW – INTEGERInput
FUNCT is called with the same parameters IW, LIW, W, LW as for E04KDF. They are present so that, when other library routines require the solution of a minimization subproblem, constants needed for the function evaluation can be passed through IW and W. Similarly, you could use elements 3,4,,LIW of IW and elements from max8,7×N+N×N-1/2+1 onwards of W for passing quantities to FUNCT from the subroutine which calls E04KDF. However, because of the danger of mistakes in partitioning, it is recommended that you should pass information to FUNCT via COMMON global variables and not use IW or W at all. In any case you must not change the first 2 elements of IW or the first max8,7×N+N×N-1/2 elements of W.
FUNCT must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which E04KDF is called. Parameters denoted as Input must not be changed by this procedure.
Note:  FUNCT should be tested separately before being used in conjunction with E04KDF.
3:     MONIT – SUBROUTINE, supplied by the user.External Procedure
If IPRINT0, you must supply MONIT which is suitable for monitoring the minimization process. MONIT must not change the values of any of its parameters.
If IPRINT<0, a MONIT with the correct parameter list must still be supplied, although it will not be called.
The specification of MONIT is:
SUBROUTINE MONIT ( N, XC, FC, GC, ISTATE, GPJNRM, COND, POSDEF, NITER, NF, IW, LIW, W, LW)
INTEGER  N, ISTATE(N), NITER, NF, IW(LIW), LIW, LW
REAL (KIND=nag_wp)  XC(N), FC, GC(N), GPJNRM, COND, W(LW)
LOGICAL  POSDEF
1:     N – INTEGERInput
On entry: the number n of variables.
2:     XC(N) – REAL (KIND=nag_wp) arrayInput
On entry: the coordinates of the current point x.
3:     FC – REAL (KIND=nag_wp)Input
On entry: the value of Fx at the current point x.
4:     GC(N) – REAL (KIND=nag_wp) arrayInput
On entry: the value of F xj  at the current point x, for j=1,2,,n.
5:     ISTATE(N) – INTEGER arrayInput
On entry: information about which variables are currently fixed on their bounds and which are free.
If ISTATEj is negative, xj is currently:
fixed on its upper bound if ISTATEj=-1
fixed on its lower bound if ISTATEj=-2
effectively a constant (i.e., lj=uj) if ISTATEj=-3
If ISTATEj is positive, its value gives the position of xj in the sequence of free variables.
6:     GPJNRM – REAL (KIND=nag_wp)Input
On entry: the Euclidean norm of the current projected gradient vector gz.
7:     COND – REAL (KIND=nag_wp)Input
On entry: the ratio of the largest to the smallest elements of the diagonal factor D of the approximated projected Hessian matrix. This quantity is usually a good estimate of the condition number of the projected Hessian matrix. (If no variables are currently free, COND is set to zero.)
8:     POSDEF – LOGICALInput
On entry: specifies .TRUE. or .FALSE. according to whether or not the approximation to the second derivative matrix for the current subspace, H, is positive definite.
9:     NITER – INTEGERInput
On entry: the number of iterations (as outlined in Section 3) which have been performed by E04KDF so far.
10:   NF – INTEGERInput
On entry: the number of evaluations of Fx so far, i.e., the number of calls of FUNCT with IFLAG set to 2. Each such call of FUNCT also calculates the first derivatives of F. (In addition to these calls monitored by NF, FUNCT is called with IFLAG set to 1 not more than N times per iteration.)
11:   IW(LIW) – INTEGER arrayWorkspace
12:   LIW – INTEGERInput
13:   W(LW) – REAL (KIND=nag_wp) arrayWorkspace
14:   LW – INTEGERInput
As in FUNCT, these parameters correspond to the parameters IW, LIW, W, LW of E04KDF. They are included in MONIT's parameter list primarily for when E04KDF is called by other library routines.
MONIT must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which E04KDF is called. Parameters denoted as Input must not be changed by this procedure.
You should normally print FC, GPJNRM and COND to be able to compare the quantities mentioned in Section 7. It is usually helpful to examine XC, POSDEF and NF too.
4:     IPRINT – INTEGERInput
On entry: the frequency with which MONIT is to be called.
IPRINT>0
MONIT is called once every IPRINT iterations and just before exit from E04KDF.
IPRINT=0
MONIT is just called at the final point.
IPRINT<0
MONIT is not called at all.
IPRINT should normally be set to a small positive number.
Suggested value: IPRINT=1.
5:     MAXCAL – INTEGERInput
On entry: the maximum permitted number of evaluations of Fx, i.e., the maximum permitted number of calls of FUNCT with IFLAG set to 2. It should be borne in mind that, in addition to the calls of FUNCT which are limited directly by MAXCAL, there will be calls of FUNCT (with IFLAG set to 1) to evaluate only first derivatives.
Suggested value: MAXCAL=50×N.
Constraint: MAXCAL1.
6:     ETA – REAL (KIND=nag_wp)Input
On entry: every iteration of E04KDF involves a linear minimization (i.e., minimization of Fx+αp with respect to α). ETA specifies how accurately these linear minimizations are to be performed. The minimum with respect to α will be located more accurately for small values of ETA (say, 0.01) than large values (say, 0.9).
Although accurate linear minimizations will generally reduce the number of iterations (and hence the number of calls of FUNCT to estimate the second derivatives), they will tend to increase the number of calls of FUNCT needed for each linear minimization. On balance, it is usually more efficient to perform a low accuracy linear minimization when n is small and a high accuracy minimization when n is large.
Suggested values:
  • ETA=0.5 if 1<n<10;
  • ETA=0.1 if 10n20;
  • ETA=0.01 if n>20.
If N=1, ETA should be set to 0.0 (also when the problem is effectively one-dimensional even though n>1; i.e., if for all except one of the variables the lower and upper bounds are equal).
Constraint: 0.0ETA<1.0.
7:     XTOL – REAL (KIND=nag_wp)Input
On entry: the accuracy in x to which the solution is required.
If xtrue is the true value of x at the minimum, then xsol, the estimated position before a normal exit, is such that xsol-xtrue<XTOL×1.0+xtrue where y=j=1nyj2. For example, if the elements of xsol are not much larger than 1.0 in modulus, and if XTOL is set to 10-5, then xsol is usually accurate to about five decimal places. (For further details see Section 7.)
If the problem is scaled as described in Section 8.2 and ε is the machine precision, then ε is probably the smallest reasonable choice for XTOL. This is because, normally, to machine accuracy, Fx+εej=Fx, for any j where ej is the jth column of the identity matrix. If you set XTOL to 0.0 (or any positive value less than ε), E04KDF will use 10.0×ε instead of XTOL.
Suggested value: XTOL=0.0.
Constraint: XTOL0.0.
8:     DELTA – REAL (KIND=nag_wp)Input
On entry: the differencing interval to be used for approximating the second derivatives of Fx. Thus, for the finite difference approximations, the first derivatives of Fx are evaluated at points which are DELTA apart. If ε is the machine precision, then ε will usually be a suitable setting for DELTA. If you set DELTA to 0.0 (or to any positive value less than ε), E04KDF will automatically use ε as the differencing interval.
Suggested value: DELTA=0.0.
Constraint: DELTA0.0.
9:     STEPMX – REAL (KIND=nag_wp)Input
On entry: an estimate of the Euclidean distance between the solution and the starting point supplied by you. (For maximum efficiency a slight overestimate is preferable.)
E04KDF will ensure that, for each iteration,
j=1n xj k -xj k-1 2 STEPMX,
where k is the iteration number. Thus, if the problem has more than one solution, E04KDF is most likely to find the one nearest to the starting point. On difficult problems, a realistic choice can prevent the sequence of x k  entering a region where the problem is ill-behaved and can also help to avoid possible overflow in the evaluation of Fx. However, an underestimate of STEPMX can lead to inefficiency.
Suggested value: STEPMX=100000.0.
Constraint: STEPMXXTOL.
10:   IBOUND – INTEGERInput
On entry: indicates whether the problem is unconstrained or bounded. If there are bounds on the variables, IBOUND can be used to indicate whether the facility for dealing with bounds of special forms is to be used. It must be set to one of the following values:
IBOUND=0
If the variables are bounded and you are supplying all the lj and uj individually.
IBOUND=1
If the problem is unconstrained.
IBOUND=2
If the variables are bounded, but all the bounds are of the form 0xj.
IBOUND=3
If all the variables are bounded, and l1=l2==ln and u1=u2==un.
IBOUND=4
If the problem is unconstrained. (The IBOUND=4 option is provided for consistency with other routines. In E04KDF it produces the same effect as IBOUND=1.)
Constraint: 0IBOUND4.
11:   BL(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the fixed lower bounds lj.
If IBOUND is set to 0, you must set BLj to lj, for j=1,2,,n. (If a lower bound is not specified for any xj, the corresponding BLj should be set to a large negative number, e.g., -106.)
If IBOUND is set to 3, you must set BL1 to l1; E04KDF will then set the remaining elements of BL equal to BL1.
If IBOUND is set to 1, 2 or 4, BL will be initialized by E04KDF.
On exit: the lower bounds actually used by E04KDF, e.g., if IBOUND=2, BL1=BL2==BLn=0.0.
12:   BU(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the fixed upper bounds uj.
If IBOUND is set to 0, you must set BUj to uj, for j=1,2,,n. (If an upper bound is not specified for any variable, the corresponding BUj should be set to a large positive number, e.g., 106.)
If IBOUND is set to 3, you must set BU1 to u1; E04KDF will then set the remaining elements of BU equal to BU1.
If IBOUND is set to 1, 2 or 4, BU will be initialized by E04KDF.
On exit: the upper bounds actually used by E04KDF, e.g., if IBOUND=2, BU1=BU2==BUn=106.
13:   X(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: Xj must be set to a guess at the jth component of the position of the minimum, for j=1,2,,n.
On exit: the final point x k . Thus, if IFAIL=0 on exit, Xj is the jth component of the estimated position of the minimum.
14:   HESL(LH) – REAL (KIND=nag_wp) arrayOutput
On exit: during the determination of a direction pz (see Section 3), H+E is decomposed into the product LDLT, where L is a unit lower triangular matrix and D is a diagonal matrix. (The matrices H, E, L and D are all of dimension nz, where nz is the number of variables free from their bounds. H consists of those rows and columns of the full estimated second derivative matrix which relate to free variables. E is chosen so that H+E is positive definite.)
HESL and HESD are used to store the factors L and D. The elements of the strict lower triangle of L are stored row by row in the first nznz-1/2 positions of HESL. The diagonal elements of D are stored in the first nz positions of HESD. In the last factorization before a normal exit, the matrix E will be zero, so that HESL and HESD will contain, on exit, the factors of the final estimated second derivative matrix H. The elements of HESD are useful for deciding whether to accept the results produced by E04KDF (see Section 7).
15:   LH – INTEGERInput
On entry: the dimension of the array HESL as declared in the (sub)program from which E04KDF is called.
Constraint: LHmaxN×N-1/2,1.
16:   HESD(N) – REAL (KIND=nag_wp) arrayOutput
On exit: during the determination of a direction pz (see Section 3), H+E is decomposed into the product LDLT, where L is a unit lower triangular matrix and D is a diagonal matrix. (The matrices H, E, L and D are all of dimension nz, where nz is the number of variables free from their bounds. H consists of those rows and columns of the full estimated second derivative matrix which relate to free variables. E is chosen so that H+E is positive definite.)
HESL and HESD are used to store the factors L and D. The elements of the strict lower triangle of L are stored row by row in the first nznz-1/2 positions of HESL. The diagonal elements of D are stored in the first nz positions of HESD. In the last factorization before a normal exit, the matrix E will be zero, so that HESL and HESD will contain, on exit, the factors of the final estimated second derivative matrix H. The elements of HESD are useful for deciding whether to accept the results produced by E04KDF (see Section 7).
17:   ISTATE(N) – INTEGER arrayOutput
On exit: information about which variables are currently on their bounds and which are free. If ISTATEj is:
  • – equal to -1, xj is fixed on its upper bound;
  • – equal to -2, xj is fixed on its lower bound;
  • – equal to -3, xj is effectively a constant (i.e., lj=uj);
  • – positive, ISTATEj gives the position of xj in the sequence of free variables.
18:   F – REAL (KIND=nag_wp)Output
On exit: the function value at the final point given in X.
19:   G(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the first derivative vector corresponding to the final point given in X. The components of G corresponding to free variables should normally be close to zero.
20:   IW(LIW) – INTEGER arrayCommunication Array
21:   LIW – INTEGERInput
On entry: the dimension of the array IW as declared in the (sub)program from which E04KDF is called.
Constraint: LIW2.
22:   W(LW) – REAL (KIND=nag_wp) arrayCommunication Array
23:   LW – INTEGERInput
On entry: the dimension of the array W as declared in the (sub)program from which E04KDF is called.
Constraint: LWmax7×N+N×N-1/2,8.
24:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if IFAIL0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: E04KDF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
IFAIL<0
A negative value of IFAIL indicates an exit from E04KDF because you have set IFLAG negative in FUNCT. The value of IFAIL will be the same as your setting of IFLAG.
IFAIL=1
On entry,N<1,
orMAXCAL<1,
orETA<0.0,
orETA1.0,
orXTOL<0.0,
orDELTA<0.0,
orSTEPMX<XTOL,
orIBOUND<0,
orIBOUND>4,
orBLj>BUj for some j if IBOUND=0,
orBL1>BU1 if IBOUND=3,
or LH < max1,N×N-1/2 ,
orLIW<2,
or LW < max8,7×N+N×N-1/2 .
(Note that if you have set XTOL or DELTA to 0.0, E04KDF uses the default values and continues without failing.) When this exit occurs, no values will have been assigned to F or to the elements of HESL, HESD or G.
IFAIL=2
There have been MAXCAL function evaluations. If steady reductions in Fx were monitored up to the point where this exit occurred, then the exit probably occurred simply because MAXCAL was set too small, so the calculations should be restarted from the final point held in X. This exit may also indicate that Fx has no minimum.
IFAIL=3
The conditions for a minimum have not all been met, but a lower point could not be found.
Provided that, on exit, the first derivatives of Fx with respect to the free variables are sufficiently small, and that the estimated condition number of the second derivative matrix is not too large, this error exit may simply mean that, although it has not been possible to satisfy the specified requirements, the algorithm has in fact found the minimum as far as the accuracy of the machine permits. Such a situation can arise, for instance, if XTOL has been set so small that rounding errors in the evaluation of Fx or its derivatives make it impossible to satisfy the convergence conditions.
If the estimated condition number of the second derivative matrix at the final point is large, it could be that the final point is a minimum, but that the smallest eigenvalue of the Hessian matrix is so close to zero that it is not possible to recognize the point as a minimum.
IFAIL=4
Not used. (This is done to make the significance of IFAIL=5 similar for E04KDF and E04LBF.)
IFAIL=5
All the Lagrange multiplier estimates which are not indisputably positive lie relatively close to zero, but it is impossible either to continue minimizing on the current subspace or to find a feasible lower point by releasing and perturbing any of the fixed variables. You should investigate as for IFAIL=3.
The values IFAIL=2, 3 or 5 may also be caused by mistakes in FUNCT, by the formulation of the problem or by an awkward function. If there are no such mistakes, it is worth restarting the calculations from a different starting point (not the point at which the failure occurred) in order to avoid the region which caused the failure.

7  Accuracy

A successful exit (IFAIL=0) is made from E04KDF when H k  is positive definite and when (B1, B2 and B3) or B4 hold, where
B1 α k ×p k <XTOL+ε×1.0+x k B2 F k -F k-1 <XTOL2+ε×1.0+F k B3 gz k <ε1/3+XTOL×1.0+F k B4 gz k <0.01×ε.
(Quantities with superscript k are the values at the kth iteration of the quantities mentioned in Section 3, ε is the machine precision and . denotes the Euclidean norm.)
If IFAIL=0, then the vector in X on exit, xsol, is almost certainly an estimate of the position of the minimum, xtrue, to the accuracy specified by XTOL.
If IFAIL=3 or 5, xsol may still be a good estimate of xtrue, but the following checks should be made. Let the largest of the first nz elements of HESD be HESDb, let the smallest be HESDs, and define k=HESDb/HESDs. The scalar k is usually a good estimate of the condition number of the projected Hessian matrix at xsol. If
(i) the sequence Fx k  converges to Fxsol at a superlinear or fast linear rate,
(ii) gzxsol2<10.0×ε, and
(iii) k<1.0/gzxsol,
then it is almost certain that xsol is a close approximation to the position of a minimum. When (ii) is true, then usually Fxsol is a close approximation to Fxtrue. The quantities needed for these checks are all available via MONIT; in particular the value of COND in the last call of MONIT before exit gives k.
Further suggestions about confirmation of a computed solution are given in the E04 Chapter Introduction.

8  Further Comments

8.1  Timing

The number of iterations required depends on the number of variables, the behaviour of Fx, the accuracy demanded and the distance of the starting point from the solution. The number of multiplications performed in an iteration of E04KDF is nz36+Onz2. In addition, each iteration makes nz calls of FUNCT (with IFLAG set to 1) in approximating the projected Hessian matrix, and at least one other call of FUNCT (with IFLAG set to 2). So, unless Fx and its first derivatives can be evaluated very quickly, the run time will be dominated by the time spent in FUNCT.

8.2  Scaling

Ideally, the problem should be scaled so that, at the solution, Fx and the corresponding values of xj are each in the range -1,+1, and so that at points one unit away from the solution, Fx differs from its value at the solution by approximately one unit. This will usually imply that the Hessian matrix at the solution is well-conditioned. It is unlikely that you will be able to follow these recommendations very closely, but it is worth trying (by guesswork), as sensible scaling will reduce the difficulty of the minimization problem, so that E04KDF will take less computer time.

8.3  Unconstrained Minimization

If a problem is genuinely unconstrained and has been scaled sensibly, the following points apply:
(a) nz will always be n,
(b) HESL and HESD will be factors of the full estimated second derivative matrix with elements stored in the natural order,
(c) the elements of g should all be close to zero at the final point,
(d) the values of the ISTATEj given by MONIT and on exit from E04KDF are unlikely to be of interest (unless they are negative, which would indicate that the modulus of one of the xj has reached 106 for some reason),
(e) MONIT's parameter GPJNRM simply gives the norm of the first derivative vector.
So the following routine (in which partitions of extended workspace arrays are used as BL, BU and ISTATE) could be used for unconstrained problems:
      SUBROUTINE UNCKDF(N,FUNCT,MONIT,IPRINT,MAXCAL,ETA,XTOL,DELTA,      &
                        STEPMX,X,HESL,LH,HESD,F,G,IWORK,LIWORK,WORK,     &
                        LWORK,IFAIL)

!     A ROUTINE TO APPLY E04KDF TO UNCONSTRAINED PROBLEMS.

!     THE REAL ARRAY WORK MUST BE OF DIMENSION AT LEAST
!     (9*N + MAX(1, N*(N-1)/2)).  ITS FIRST 7*N + MAX(1, N*(N-1)/2)
!     ELEMENTS WILL BE USED BY E04KDF AS THE ARRAY W.  ITS LAST
!     2*N ELEMENTS WILL BE USED AS THE ARRAYS BL AND BU.

!     THE INTEGER ARRAY IWORK MUST BE OF DIMENSION AT LEAST (N+2)
!     ITS FIRST 2 ELEMENTS WILL BE USED BY E04KDF AS THE ARRAY IW.
!     ITS LAST N ELEMENTS WILL BE USED AS THE ARRAY ISTATE.

!     LIWORK AND LWORK MUST BE SET TO THE ACTUAL LENGTHS OF IWORK
!     AND WORK RESPECTIVELY, AS DECLARED IN THE CALLING SEGMENT.

!     OTHER PARAMETERS ARE AS FOR E04KDF.


!     ..  Parameters ..
      INTEGER NOUT
      PARAMETER (NOUT=6)
!     ..  Scalar Arguments ..
      REAL (KIND=nag_wp) DELTA, ETA, F, STEPMX, XTOL
      INTEGER            IFAIL, IPRINT, LH, LIWORK, LWORK, MAXCAL, N
!     ..  Array Arguments ..
      REAL (KIND=nag_wp) G(N), HESD(N), HESL(LH), WORK(LWORK), X(N)
      INTEGER            IWORK(LIWORK)
!     ..  Subroutine Arguments ..
      EXTERNAL FUNCT, MONIT
!     ..  Local Scalars ..
      INTEGER IBOUND, J, JBL, JBU, NH
      LOGICAL TOOBIG
!     ..  External Subroutines ..
      EXTERNAL E04KDF
!     ..  Executable Statements ..
!     CHECK THAT SUFFICIENT WORKSPACE HAS BEEN SUPPLIED
      NH = N*(N-1)/2
      IF (NH.EQ.0) NH = 1
      IF (LWORK.LT.9*N+NH .OR.  LIWORK.LT.N+2) THEN
         WRITE (NOUT,FMT=99999)
         STOP
      END IF
!     JBL AND JBU SPECIFY THE PARTS OF WORK USED AS BL AND BU
      JBL = 7*N + NH + 1
      JBU = JBL + N
!     SPECIFY THAT THE PROBLEM IS UNCONSTRAINED
      IBOUND = 4
      CALL E04KDF(N,FUNCT,MONIT,IPRINT,MAXCAL,ETA,XTOL,DELTA,STEPMX,     &
      	          IBOUND,WORK(JBL),WORK(JBU),X,HESL,LH,HESD,IWORK(3),    &
         	  F,G,IWORK,LIWORK,WORK,LWORK,IFAIL)
!     CHECK THE PART OF IWORK WHICH WAS USED AS ISTATE IN CASE
!     THE MODULUS OF SOME X(J) HAS REACHED E+6
      TOOBIG = .FALSE.
      DO 20 J = 1, N
         IF (IWORK(2+J).LT.0) TOOBIG = .TRUE.
   20 CONTINUE
      IF ( .NOT.  TOOBIG) RETURN
      WRITE (NOUT,FMT=99998)
      STOP

99999 FORMAT (' ***** INSUFFICIENT WORKSPACE HAS BEEN SUPPLIED *****')
99998 FORMAT (' ***** A VARIABLE HAS REACHED E+6 IN MODULUS - NO UNCON', &
      	      'STRAINED MINIMUM HAS BEEN FOUND *****')
      END

9  Example

A program to minimize
F= x1+10x2 2+5 x3-x4 2+ x2-2x3 4+10 x1-x4 4
subject to the bounds
1 x1 3 -2 x2 0 1 x4 3,
starting from the initial guess 3,-1,0,1 . Before calling E04KDF, the program calls E04HCF to check the first derivatives calculated by FUNCT.

9.1  Program Text

Program Text (e04kdfe.f90)

9.2  Program Data

None.

9.3  Program Results

Program Results (e04kdfe.r)


E04KDF (PDF version)
E04 Chapter Contents
E04 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012