NAG Library Routine Document
E04LBF
1 Purpose
E04LBF is a comprehensive modified Newton algorithm for finding:
 an unconstrained minimum of a function of several variables
 a minimum of a function of several variables subject to fixed upper and/or lower bounds on the variables.
First and second 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 E04LBF ( 
N, FUNCT, H, MONIT, IPRINT, MAXCAL, ETA, XTOL, 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, STEPMX, BL(N), BU(N), X(N), HESL(LH), HESD(N), F, G(N), W(LW) 
EXTERNAL 
FUNCT, H, MONIT 

3 Description
E04LBF is applicable to problems of the form:
Special provision is made for unconstrained minimization (i.e., problems which actually have no bounds on the
${x}_{j}$), problems which have only nonnegativity bounds, and problems in which
${l}_{1}={l}_{2}=\cdots ={l}_{n}$ and
${u}_{1}={u}_{2}=\cdots ={u}_{n}$. It is possible to specify that a particular
${x}_{j}$ should be held constant. You must supply a starting point, a
FUNCT to calculate the value of
$F\left(x\right)$ and its first derivatives
$\frac{\partial F}{\partial {x}_{j}}$ at any point
$x$, and a
H to calculate the second derivatives
$\frac{{\partial}^{2}F}{\partial {x}_{i}\partial {x}_{j}}$.
A typical iteration starts at the current point $x$ where ${n}_{z}$ (say) variables are free from both their bounds. The vector of first derivatives of $F\left(x\right)$ with respect to the free variables, ${g}_{z}$, and the matrix of second derivatives with respect to the free variables, $H$, are obtained. (These both have dimension ${n}_{z}$.)
The equations
are solved to give a search direction
${p}_{z}$. (The matrix
$E$ is chosen so that
$H+E$ is positive definite.)
${p}_{z}$ is then expanded to an $n$vector $p$ by the insertion of appropriate zero elements; $\alpha $ is found such that $F\left(x+\alpha p\right)$ is approximately a minimum (subject to the fixed bounds) with respect to $\alpha $, and $x$ is replaced by $x+\alpha 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 ${n}_{z}$ 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 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., ${n}_{z}$ is increased). Otherwise, minimization continues in the current subspace until the stronger criteria are satisfied. If at this point there are no negative or nearzero Lagrange multiplier estimates, the process is terminated.
If you specify that the problem is unconstrained, E04LBF sets the ${l}_{j}$ to ${10}^{6}$ and the ${u}_{j}$ to ${10}^{6}$. Thus, provided that the problem has been sensibly scaled, no bounds will be encountered during the minimization process and E04LBF 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) Newtontype 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:
${\mathbf{N}}\ge 1$.
 2: FUNCT – SUBROUTINE, supplied by the user.External Procedure
FUNCT must evaluate the function
$F\left(x\right)$ and its first derivatives
$\frac{\partial F}{\partial {x}_{j}}$ at any point
$x$. (However, if you do not wish to calculate
$F\left(x\right)$ or its first derivatives at a particular
$x$, there is the option of setting a parameter to cause E04LBF to terminate immediately.)
The specification of
FUNCT is:
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 $2$.
On exit: if it is not possible to evaluate
$F\left(x\right)$ or its first derivatives at the point
$x$ given in
XC (or if it is wished to stop the calculation for any other reason) you should reset
IFLAG to some negative number and return control to E04LBF. E04LBF 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 $F$ and the $\frac{\partial F}{\partial {x}_{j}}$ are required.
 4: FC – REAL (KIND=nag_wp)Output
On exit: unless
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
IFLAG is reset,
FUNCT must set
${\mathbf{GC}}\left(j\right)$ to the value of the first derivative
$\frac{\partial F}{\partial {x}_{\mathit{j}}}$ at the point
$x$, for
$\mathit{j}=1,2,\dots ,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 and
LW as for E04LBF. 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,\dots ,{\mathbf{LIW}}$ of
IW and elements from
$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(8,7\times {\mathbf{N}}+{\mathbf{N}}\times \left({\mathbf{N}}1\right)/2\right)+1$ onwards of
W for passing quantities to
FUNCT from the subroutine which calls E04LBF. 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
FUNCT must not change the first
$2$ elements of
IW or the first
$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(8,7\times {\mathbf{N}}+{\mathbf{N}}\times \left({\mathbf{N}}1\right)/2\right)$ elements of
W.
FUNCT must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which E04LBF 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 E04LBF.
 3: H – SUBROUTINE, supplied by the user.External Procedure
H must calculate the second derivatives of
$F$ at any point
$x$. (As with
FUNCT, there is the option of causing E04LBF to terminate immediately.)
The specification of
H is:
INTEGER 
IFLAG, N, LH, IW(LIW), LIW, LW 
REAL (KIND=nag_wp) 
XC(N), FHESL(LH), FHESD(N), W(LW) 

 1: IFLAG – INTEGERInput/Output
On entry: is set to a nonnegative number.
On exit: if
H resets
IFLAG to some negative number, E04LBF will 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 second derivatives of $F$ are required.
 4: FHESL(LH) – REAL (KIND=nag_wp) arrayOutput
On exit: unless
IFLAG is reset,
H must place the strict lower triangle of the second derivative matrix of
$F$ (evaluated at the point
$x$) in
FHESL, stored by rows, i.e., set
${\mathbf{FHESL}}\left(\left(\mathit{i}1\right)\left(\mathit{i}2\right)/2+\mathit{j}\right)={\left.\frac{{\partial}^{2}F}{\partial {x}_{\mathit{i}}\partial {x}_{\mathit{j}}}\right}_{{\mathbf{XC}}}$, for
$\mathit{i}=2,3,\dots ,n$ and
$\mathit{j}=1,2,\dots ,i1$. (The upper triangle is not required because the matrix is symmetric.)
 5: LH – INTEGERInput
On entry: the length of the array
FHESL.
 6: FHESD(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the value of
$\frac{\partial F}{\partial {x}_{\mathit{j}}}$ at the point
$x$, for
$\mathit{j}=1,2,\dots ,n$.
These values may be useful in the evaluation of the second derivatives.
On exit: unless
IFLAG is reset,
H must place the diagonal elements of the second derivative matrix of
$F$ (evaluated at the point
$x$) in
FHESD, i.e., set
${\mathbf{FHESD}}\left(j\right)={\left.\frac{{\partial}^{2}F}{\partial {x}_{j}^{2}}\right}_{{\mathbf{XC}}}$,
$j=1,2,\dots ,n$.
 7: IW(LIW) – INTEGER arrayWorkspace
 8: LIW – INTEGERInput
 9: W(LW) – REAL (KIND=nag_wp) arrayWorkspace
 10: LW – INTEGERInput
As in
FUNCT, these parameters correspond to the parameters
IW,
LIW,
W,
LW of E04LBF.
H must not change the first two elements of
IW or the first
$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(8,7\times {\mathbf{N}}+{\mathbf{N}}\times \left({\mathbf{N}}1\right)/2\right)$ elements of
W. Again, it is recommended that you should pass quantities to
H via COMMON global variables and not use
IW or
W at all.
H must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which E04LBF is called. Parameters denoted as
Input must
not be changed by this procedure.
Note: H should be tested separately before being used in conjunction with E04LBF.
 4: MONIT – SUBROUTINE, supplied by the user.External Procedure
If
${\mathbf{IPRINT}}\ge 0$, you must supply
MONIT which is suitable for monitoring the minimization process.
MONIT must not change the values of any of its parameters.
If
${\mathbf{IPRINT}}<0$, a
MONIT with the correct parameter list should 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 $F\left(x\right)$ at the current point $x$.
 4: GC(N) – REAL (KIND=nag_wp) arrayInput
On entry: the value of
$\frac{\partial F}{\partial {x}_{\mathit{j}}}$ at the current point $x$, for $\mathit{j}=1,2,\dots ,n$.
 5: ISTATE(N) – INTEGER arrayInput
On entry: information about which variables are currently fixed on their bounds and which are free.
If
${\mathbf{ISTATE}}\left(j\right)$ is negative,
${x}_{j}$ is currently:
– 
fixed on its upper bound if ${\mathbf{ISTATE}}\left(j\right)=1$; 
– 
fixed on its lower bound if ${\mathbf{ISTATE}}\left(j\right)=2$; 
– 
effectively a constant (i.e., ${l}_{j}={u}_{j}$) if ${\mathbf{ISTATE}}\left(j\right)=3$. 
If
ISTATE is positive, its value gives the position of
${x}_{j}$ in the sequence of free variables.
 6: GPJNRM – REAL (KIND=nag_wp)Input
On entry: the Euclidean norm of the projected gradient vector ${g}_{z}$.
 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 projected Hessian matrix (see specification of
H). 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: is set .TRUE. or .FALSE. according to whether the second derivative matrix for the current subspace, $H$, is positive definite or not.
 9: NITER – INTEGERInput
On entry: the number of iterations (as outlined in
Section 3) which have been performed by E04LBF so far.
 10: NF – INTEGERInput
On entry: the number of times that
FUNCT has been called so far. Thus
NF is the number of function and gradient evaluations made so far.
 11: IW(LIW) – INTEGER arrayWorkspace
 12: LIW – INTEGERInput
 13: W(LW) – REAL (KIND=nag_wp) arrayWorkspace
 14: LW – INTEGERInput
As in
FUNCT, and
H, these parameters correspond to the parameters
IW,
LIW,
W,
LW of E04LBF. They are included in
MONIT's parameter list primarily for when E04LBF 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 E04LBF is called. Parameters denoted as
Input must
not be changed by this procedure.
You should normally print out
FC,
GPJNRM and
COND so as to be able to compare the quantities mentioned in
Section 7. It is normally helpful to examine
XC,
POSDEF and
NF as well.
 5: IPRINT – INTEGERInput
On entry: the frequency with which
MONIT is to be called.
 ${\mathbf{IPRINT}}>0$
 MONIT is called once every IPRINT iterations and just before exit from E04LBF.
 ${\mathbf{IPRINT}}=0$
 MONIT is just called at the final point.
 ${\mathbf{IPRINT}}<0$
 MONIT is not called at all.
IPRINT should normally be set to a small positive number.
Suggested value:
${\mathbf{IPRINT}}=1$.
 6: MAXCAL – INTEGERInput
On entry: the maximum permitted number of evaluations of
$F\left(x\right)$, i.e., the maximum permitted number of calls of
FUNCT.
Suggested value:
${\mathbf{MAXCAL}}=50\times {\mathbf{N}}$.
Constraint:
${\mathbf{MAXCAL}}\ge 1$.
 7: ETA – REAL (KIND=nag_wp)Input
On entry: every iteration of E04LBF involves a linear minimization (i.e., minimization of
$F\left(x+\alpha p\right)$ with respect to
$\alpha $).
ETA specifies how accurately these linear minimizations are to be performed. The minimum with respect to
$\alpha $ will be located more accurately for small values of
ETA (say,
$0.01$) than for large values (say,
$0.9$).
Although accurate linear minimizations will generally reduce the number of iterations of E04LBF, this usually results in an increase in the number of function and gradient evaluations required for each iteration. On balance, it is usually more efficient to perform a low accuracy linear minimization.
Suggested value:
${\mathbf{ETA}}=0.9$ is usually a good choice although a smaller value may be warranted if the matrix of second derivatives is expensive to compute compared with the function and first derivatives.
If ${\mathbf{N}}=1$, ETA should be set to $0.0$ (also when the problem is effectively onedimensional even though
$n>1$; i.e., if for all except one of the variables the lower and upper bounds are equal).
Constraint:
$0.0\le {\mathbf{ETA}}<1.0$.
 8: XTOL – REAL (KIND=nag_wp)Input
On entry: the accuracy in
$x$ to which the solution is required.
If
${x}_{\mathrm{true}}$ is the true value of
$x$ at the minimum, then
${x}_{\mathrm{sol}}$, the estimated position before a normal exit, is such that
$\Vert {x}_{\mathrm{sol}}{x}_{\mathrm{true}}\Vert <{\mathbf{XTOL}}\times \left(1.0+\Vert {x}_{\mathrm{true}}\Vert \right)$, where
$\Vert y\Vert =\sqrt{{\displaystyle \sum _{j=1}^{n}}{y}_{j}^{2}}$. For example, if the elements of
${x}_{\mathrm{sol}}$ are not much larger than
$1.0$ in modulus, and if
XTOL is set to
${10}^{5}$ then
${x}_{\mathrm{sol}}$ is usually accurate to about five decimal places. (For further details see
Section 7.)
If the problem is scaled roughly as described in
Section 8 and
$\epsilon $ is the
machine precision, then
$\sqrt{\epsilon}$ is probably the smallest reasonable choice for
XTOL. (This is because, normally, to machine accuracy,
$F\left(x+\sqrt{\epsilon},{e}_{j}\right)=F\left(x\right)$ where
${e}_{j}$ is any column of the identity matrix.)
If you set
XTOL to
$0.0$ (or any positive value less than
$\epsilon $), E04LBF will use
$10.0\times \sqrt{\epsilon}$ instead of
XTOL.
Suggested value:
${\mathbf{XTOL}}=0.0$.
Constraint:
${\mathbf{XTOL}}\ge 0.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.)
E04LBF will ensure that, for each iteration,
where
$k$ is the iteration number. Thus, if the problem has more than one solution, E04LBF is most likely to find the one nearest to the starting point. On difficult problems, a realistic choice can prevent the sequence of
${x}^{\left(k\right)}$ entering a region where the problem is illbehaved and can also help to avoid possible overflow in the evaluation of
$F\left(x\right)$. However, an underestimate of
STEPMX can lead to inefficiency.
Suggested value:
${\mathbf{STEPMX}}=100000.0$.
Constraint:
${\mathbf{STEPMX}}\ge {\mathbf{XTOL}}$.
 10: IBOUND – INTEGERInput
On entry: specifies 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:
 ${\mathbf{IBOUND}}=0$
 If the variables are bounded and you are supplying all the ${l}_{j}$ and ${u}_{j}$ individually.
 ${\mathbf{IBOUND}}=1$
 If the problem is unconstrained.
 ${\mathbf{IBOUND}}=2$
 If the variables are bounded, but all the bounds are of the form $0\le {x}_{j}$.
 ${\mathbf{IBOUND}}=3$
 If all the variables are bounded, and ${l}_{1}={l}_{2}=\cdots ={l}_{n}$ and ${u}_{1}={u}_{2}=\cdots ={u}_{n}$.
 ${\mathbf{IBOUND}}=4$
 If the problem is unconstrained. (The ${\mathbf{IBOUND}}=4$ option is provided purely for consistency with other routines. In E04LBF it produces the same effect as ${\mathbf{IBOUND}}=1$.)
Constraint:
$0\le {\mathbf{IBOUND}}\le 4$.
 11: BL(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the fixed lower bounds
${l}_{j}$.
If
IBOUND is set to
$0$, you must set
${\mathbf{BL}}\left(\mathit{j}\right)$ to
${l}_{\mathit{j}}$, for
$\mathit{j}=1,2,\dots ,n$. (If a lower bound is not specified for any
${x}_{j}$, the corresponding
${\mathbf{BL}}\left(j\right)$ should be set to a large negative number, e.g.,
${10}^{6}$.)
If
IBOUND is set to
$3$, you must set
${\mathbf{BL}}\left(1\right)$ to
${l}_{1}$; E04LBF will then set the remaining elements of
BL equal to
${\mathbf{BL}}\left(1\right)$.
If
IBOUND is set to
$1$,
$2$ or
$4$,
BL will be initialized by E04LBF.
On exit: the lower bounds actually used by E04LBF, e.g., if ${\mathbf{IBOUND}}=2$, ${\mathbf{BL}}\left(1\right)={\mathbf{BL}}\left(2\right)=\cdots ={\mathbf{BL}}\left({\mathbf{N}}\right)=0.0$.
 12: BU(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the fixed upper bounds
${u}_{j}$.
If
IBOUND is set to
$0$, you must set
${\mathbf{BU}}\left(\mathit{j}\right)$ to
${u}_{\mathit{j}}$, for
$\mathit{j}=1,2,\dots ,n$. (If an upper bound is not specified for any variable, the corresponding
${\mathbf{BU}}\left(j\right)$ should be set to a large positive number, e.g.,
${10}^{6}$.)
If
IBOUND is set to
$3$, you must set
${\mathbf{BU}}\left(1\right)$ to
${u}_{1}$; E04LBF will then set the remaining elements of
BU equal to
${\mathbf{BU}}\left(1\right)$.
If
IBOUND is set to
$1$,
$2$ or
$4$,
BU will then be initialized by E04LBF.
On exit: the upper bounds actually used by E04LBF, e.g., if ${\mathbf{IBOUND}}=2$, ${\mathbf{BU}}\left(1\right)={\mathbf{BU}}\left(2\right)=\cdots ={\mathbf{BU}}\left({\mathbf{N}}\right)={10}^{6}$.
 13: X(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: ${\mathbf{X}}\left(\mathit{j}\right)$ must be set to a guess at the $\mathit{j}$th component of the position of the minimum, for $\mathit{j}=1,2,\dots ,n$.
On exit: the final point ${x}^{\left(k\right)}$. Thus, if ${\mathbf{IFAIL}}={\mathbf{0}}$ on exit, ${\mathbf{X}}\left(j\right)$ is the $j$th component of the estimated position of the minimum.
 14: HESL(LH) – REAL (KIND=nag_wp) arrayOutput
On exit: during the determination of a direction
${p}_{z}$ (see
Section 3),
$H+E$ is decomposed into the product
$LD{L}^{\mathrm{T}}$, 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
${n}_{z}$, where
${n}_{z}$ 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
${n}_{z}\left({n}_{z}1\right)/2$ positions of
HESL. The diagonal elements of
$D$ are stored in the first
${n}_{z}$ 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 E04LBF (see
Section 7).
 15: LH – INTEGERInput
On entry: the dimension of the array
HESL as declared in the (sub)program from which E04LBF is called.
Constraint:
${\mathbf{LH}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{N}}\times \left({\mathbf{N}}1\right)/2,1\right)$.
 16: HESD(N) – REAL (KIND=nag_wp) arrayOutput
On exit: during the determination of a direction
${p}_{z}$ (see
Section 3),
$H+E$ is decomposed into the product
$LD{L}^{\mathrm{T}}$, 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
${n}_{z}$, where
${n}_{z}$ is the number of variables free from their bounds.
$H$ consists of those rows and columns of the full 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
${n}_{z}\left({n}_{z}1\right)/2$ positions of
HESL. The diagonal elements of
$D$ are stored in the first
${n}_{z}$ 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 second derivative matrix
$H$. The elements of
HESD are useful for deciding whether to accept the result produced by E04LBF (see
Section 7).
 17: ISTATE(N) – INTEGER arrayOutput
On exit: information about which variables are currently on their bounds and which are free. If
${\mathbf{ISTATE}}\left(j\right)$ is:
 – equal to $1$, ${x}_{j}$ is fixed on its upper bound;
 – equal to $2$, ${x}_{j}$ is fixed on its lower bound;
 – equal to $3$, ${x}_{j}$ is effectively a constant (i.e., ${l}_{j}={u}_{j}$);
 – positive, ${\mathbf{ISTATE}}\left(j\right)$ gives the position of ${x}_{j}$ 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 E04LBF is called.
Constraint:
${\mathbf{LIW}}\ge 2$.
 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 E04LBF is called.
Constraint:
${\mathbf{LW}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(7\times {\mathbf{N}}+{\mathbf{N}}\times \left({\mathbf{N}}1\right)/2,8\right)$.
 24: IFAIL – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ 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\text{ 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
${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is
$1$.
When the value $\mathbf{1}\text{ or}1$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Note: E04LBF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}<0$
A negative value of
IFAIL indicates an exit from E04LBF because you have set
IFLAG negative in
FUNCT or
H. The value of
IFAIL will be the same as your setting of
IFLAG.
 ${\mathbf{IFAIL}}=1$
On entry,  ${\mathbf{N}}<1$, 
or  ${\mathbf{MAXCAL}}<1$, 
or  ${\mathbf{ETA}}<0.0$, 
or  ${\mathbf{ETA}}\ge 1.0$, 
or  ${\mathbf{XTOL}}<0.0$, 
or  ${\mathbf{STEPMX}}<{\mathbf{XTOL}}$, 
or  ${\mathbf{IBOUND}}<0$, 
or  ${\mathbf{IBOUND}}>4$, 
or  ${\mathbf{BL}}\left(j\right)>{\mathbf{BU}}\left(j\right)$ for some $j$ if ${\mathbf{IBOUND}}=0$, 
or  ${\mathbf{BL}}\left(1\right)>{\mathbf{BU}}\left(1\right)$ if ${\mathbf{IBOUND}}=3$, 
or  ${\mathbf{LH}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\times \left({\mathbf{N}}1\right)/2\right)$, 
or  ${\mathbf{LIW}}<2$, 
or  ${\mathbf{LW}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(8,7\times {\mathbf{N}}+{\mathbf{N}}\times \left({\mathbf{N}}1\right)/2\right)$. 
(Note that if you have set
XTOL to
$0.0$, E04LBF uses the default value 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.
 ${\mathbf{IFAIL}}=2$
There have been
MAXCAL function evaluations. If steady reductions in
$F\left(x\right)$ 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
$F\left(x\right)$ has no minimum.
 ${\mathbf{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
$F\left(x\right)$ 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
$F\left(x\right)$ 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.
 ${\mathbf{IFAIL}}=4$
Not used. (This is done to make the significance of
${\mathbf{IFAIL}}={\mathbf{5}}$ similar for
E04KDF and E04LBF.)
 ${\mathbf{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 ${\mathbf{IFAIL}}={\mathbf{3}}$.
The values
${\mathbf{IFAIL}}={\mathbf{2}}$,
${\mathbf{3}}$ or
${\mathbf{5}}$ may also be caused by mistakes in usersupplied subroutines
FUNCT or
H, 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 (
${\mathbf{IFAIL}}={\mathbf{0}}$) is made from E04LBF when
${H}^{\left(k\right)}$ is positive definite and when (B1, B2 and B3) or B4 hold, where
(Quantities with superscript
$k$ are the values at the
$k$th iteration of the quantities mentioned in
Section 3.
$\epsilon $ is the
machine precision and
$\Vert .\Vert $ denotes the Euclidean norm.)
If
${\mathbf{IFAIL}}={\mathbf{0}}$, then the vector in
X on exit,
${x}_{\mathrm{sol}}$, is almost certainly an estimate of the position of the minimum,
${x}_{\mathrm{true}}$, to the accuracy specified by
XTOL.
If
${\mathbf{IFAIL}}={\mathbf{3}}$ or
${\mathbf{5}}$,
${x}_{\mathrm{sol}}$ may still be a good estimate of
${x}_{\mathrm{true}}$, but the following checks should be made. Let the largest of the first
${n}_{z}$ elements of
HESD be
${\mathbf{HESD}}\left(b\right)$, let the smallest be
${\mathbf{HESD}}\left(s\right)$, and define
$k={\mathbf{HESD}}\left(b\right)/{\mathbf{HESD}}\left(s\right)$. The scalar
$k$ is usually a good estimate of the condition number of the projected Hessian matrix at
${x}_{\mathrm{sol}}$. If
(i) 
the sequence $\left\{F\left({x}^{\left(k\right)}\right)\right\}$ converges to $F\left({x}_{\mathrm{sol}}\right)$ at a superlinear or fast linear rate, 
(ii) 
${\Vert {g}_{z}\left({x}_{\mathrm{sol}}\right)\Vert}^{2}<10.0\times \epsilon $, and 
(iii) 
$k<1.0/\Vert {g}_{z}\left({x}_{\mathrm{sol}}\right)\Vert $, 
then it is almost certain that
${x}_{\mathrm{sol}}$ is a close approximation to the position of a minimum. When (ii) is true, then usually
$F\left({x}_{\mathrm{sol}}\right)$ is a close approximation to
$F\left({x}_{\mathrm{true}}\right)$. 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.
The number of iterations required depends on the number of variables, the behaviour of
$F\left(x\right)$, the accuracy demanded and the distance of the starting point from the solution. The number of multiplications performed in an iteration of E04LBF is
$\frac{{n}_{z}^{3}}{6}+\mathit{O}\left({n}_{z}^{2}\right)$. In addition, each iteration makes one call of
H and at least one call of
FUNCT. So, unless
$F\left(x\right)$ and its derivatives can be evaluated very quickly, the run time will be dominated by the time spent in
FUNCT and
H.
Ideally, the problem should be scaled so that, at the solution, $F\left(x\right)$ and the corresponding values of the ${x}_{j}$ are each in the range $\left(1,+1\right)$, and so that at points one unit away from the solution, $F\left(x\right)$ differs from its value at the solution by approximately one unit. This will usually imply that the Hessian matrix at the solution is wellconditioned. 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 E04LBF will take less computer time.
If a problem is genuinely unconstrained and has been scaled sensibly, the following points apply:
(a) 
${n}_{z}$ will always be $n$, 
(b) 
HESL and HESD will be factors of the full 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 ${\mathbf{ISTATE}}\left(j\right)$ given by MONIT and on exit from E04LBF are unlikely to be of interest (unless they are negative, which would indicate that the modulus of one of the ${x}_{j}$ has reached ${10}^{6}$ 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 UNCLBF(N,FUNCT,H,MONIT,IPRINT,MAXCAL,ETA,XTOL, &
STEPMX,X,HESL,LH,HESD,F,G,IWORK,LIWORK,WORK, &
LWORK,IFAIL)
! A ROUTINE TO APPLY E04LBF TO UNCONSTRAINED PROBLEMS.
! THE REAL ARRAY WORK MUST BE OF DIMENSION AT LEAST
! (9*N + MAX(1, N*(N1)/2)). ITS FIRST 7*N + MAX(1, N*(N1)/2)
! ELEMENTS WILL BE USED BY E04LBF 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 E04LBF 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 E04LBF.
! .. Parameters ..
INTEGER NOUT
PARAMETER (NOUT=6)
! .. Scalar Arguments ..
REAL (KIND=nag_wp) 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, H, MONIT
! .. Local Scalars ..
INTEGER IBOUND, J, JBL, JBU, NH
LOGICAL TOOBIG
! .. External Subroutines ..
EXTERNAL E04LBF
! .. Executable Statements ..
! CHECK THAT SUFFICIENT WORKSPACE HAS BEEN SUPPLIED
NH = N*(N1)/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 E04LBF(N,FUNCT,H,MONIT,IPRINT,MAXCAL,ETA,XTOL,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
subject to the bounds
starting from the initial guess
$\left(3,1,0,1\right)$. Before calling E04LBF, the program calls
E04HCF and
E04HDF to check the derivatives calculated by usersupplied subroutines
FUNCT and
H.
9.1 Program Text
Program Text (e04lbfe.f90)
9.2 Program Data
None.
9.3 Program Results
Program Results (e04lbfe.r)