Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_opt_bounds_mod_deriv2_comp (e04lb)

## Purpose

nag_opt_bounds_mod_deriv2_comp (e04lb) 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 function is intended for functions which have continuous first and second derivatives (although it will usually work even if the derivatives have occasional discontinuities).

## Syntax

[bl, bu, x, hesl, hesd, istate, f, g, iw, w, ifail] = e04lb(funct, h, monit, ibound, bl, bu, x, lh, iw, w, 'n', n, 'iprint', iprint, 'maxcal', maxcal, 'eta', eta, 'xtol', xtol, 'stepmx', stepmx)
[bl, bu, x, hesl, hesd, istate, f, g, iw, w, ifail] = nag_opt_bounds_mod_deriv2_comp(funct, h, monit, ibound, bl, bu, x, lh, iw, w, 'n', n, 'iprint', iprint, 'maxcal', maxcal, 'eta', eta, 'xtol', xtol, 'stepmx', stepmx)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 22: liw, lw have been removed from the interface
.

## Description

nag_opt_bounds_mod_deriv2_comp (e04lb) is applicable to problems of the form:
 MinimizeF(x1,x2, … ,xn)subject to ​lj ≤ xj ≤ uj,  j = 1,2, … ,n. $MinimizeF(x1,x2,…,xn)subject to ​lj≤xj≤uj, j=1,2,…,n.$
Special provision is made for unconstrained minimization (i.e., problems which actually have no bounds on the xj${x}_{j}$), problems which have only non-negativity bounds, and problems in which l1 = l2 = = ln${l}_{1}={l}_{2}=\cdots ={l}_{n}$ and u1 = u2 = = un${u}_{1}={u}_{2}=\cdots ={u}_{n}$. It is possible to specify that a particular xj${x}_{j}$ should be held constant. You must supply a starting point, a funct to calculate the value of F(x)$F\left(x\right)$ and its first derivatives (F)/(xj) $\frac{\partial F}{\partial {x}_{j}}$ at any point x$x$, and a h to calculate the second derivatives (2F)/(xixj) $\frac{{\partial }^{2}F}{\partial {x}_{i}\partial {x}_{j}}$.
A typical iteration starts at the current point x$x$ where nz${n}_{z}$ (say) variables are free from both their bounds. The vector of first derivatives of F(x)$F\left(x\right)$ with respect to the free variables, gz${g}_{z}$, and the matrix of second derivatives with respect to the free variables, H$H$, are obtained. (These both have dimension nz${n}_{z}$.)
The equations
 (H + E)pz = − gz $(H+E)pz=-gz$
are solved to give a search direction pz${p}_{z}$. (The matrix E$E$ is chosen so that H + E$H+E$ is positive definite.)
pz${p}_{z}$ is then expanded to an n$n$-vector p$p$ by the insertion of appropriate zero elements; α$\alpha$ is found such that F(x + αp)$F\left(x+\alpha p\right)$ is approximately a minimum (subject to the fixed bounds) with respect to α$\alpha$, and x$x$ is replaced by x + αp$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 nz${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., nz${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 near-zero Lagrange multiplier estimates, the process is terminated.
If you specify that the problem is unconstrained, nag_opt_bounds_mod_deriv2_comp (e04lb) sets the lj${l}_{j}$ to 106$-{10}^{6}$ and the uj${u}_{j}$ to 106${10}^{6}$. Thus, provided that the problem has been sensibly scaled, no bounds will be encountered during the minimization process and nag_opt_bounds_mod_deriv2_comp (e04lb) will act as an unconstrained minimization algorithm.

## 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. Programming 7 311–350
Gill P E and Murray W (1976) Minimization subject to bounds on the variables NPL Report NAC 72 National Physical Laboratory

## Parameters

### Compulsory Input Parameters

1:     funct – function handle or string containing name of m-file
funct must evaluate the function F(x)$F\left(x\right)$ and its first derivatives (F)/(xj) $\frac{\partial F}{\partial {x}_{j}}$ at any point x$x$. (However, if you do not wish to calculate F(x)$F\left(x\right)$ or its first derivatives at a particular x$x$, there is the option of setting a parameter to cause nag_opt_bounds_mod_deriv2_comp (e04lb) to terminate immediately.)
[iflag, fc, gc, iw, w] = funct(iflag, n, xc, iw, w)

Input Parameters

1:     iflag – int64int32nag_int scalar
Will have been set to 2$2$.
2:     n – int64int32nag_int scalar
The number n$n$ of variables.
3:     xc(n) – double array
The point x$x$ at which F$F$ and the (F)/(xj) $\frac{\partial F}{\partial {x}_{j}}$ are required.
4:     iw(liw) – int64int32nag_int array
5:     w(lw) – double array
funct is called with the same parameters iw, liw, w and lw as for nag_opt_bounds_mod_deriv2_comp (e04lb). They are present so that, when other library functions 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$3,4,\dots ,\mathit{liw}$ of iw and elements from max (8,7 × n + n × (n1) / 2) + 1$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(8,7×{\mathbf{n}}+{\mathbf{n}}×\left({\mathbf{n}}-1\right)/2\right)+1$ onwards of w for passing quantities to funct from the function which calls nag_opt_bounds_mod_deriv2_comp (e04lb). However, because of the danger of mistakes in partitioning, it is recommended that you should pass information to funct via global variables and not use iw or w at all. In any case funct must not change the first 2$2$ elements of iw or the first max (8,7 × n + n × (n1) / 2)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(8,7×{\mathbf{n}}+{\mathbf{n}}×\left({\mathbf{n}}-1\right)/2\right)$ elements of w.

Output Parameters

1:     iflag – int64int32nag_int scalar
If it is not possible to evaluate F(x)$F\left(x\right)$ or its first derivatives at the point x$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 nag_opt_bounds_mod_deriv2_comp (e04lb). nag_opt_bounds_mod_deriv2_comp (e04lb) will then terminate immediately with ifail set to your setting of iflag.
2:     fc – double scalar
Unless iflag is reset, funct must set fc to the value of the objective function F$F$ at the current point x$x$.
3:     gc(n) – double array
Unless iflag is reset, funct must set gc(j)${\mathbf{gc}}\left(j\right)$ to the value of the first derivative (F)/(xj) $\frac{\partial F}{\partial {x}_{\mathit{j}}}$ at the point x$x$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$.
4:     iw(liw) – int64int32nag_int array
5:     w(lw) – double array
Note:  funct should be tested separately before being used in conjunction with nag_opt_bounds_mod_deriv2_comp (e04lb).
2:     h – function handle or string containing name of m-file
h must calculate the second derivatives of F$F$ at any point x$x$. (As with funct, there is the option of causing nag_opt_bounds_mod_deriv2_comp (e04lb) to terminate immediately.)
[iflag, fhesl, fhesd, iw, w] = h(iflag, n, xc, lh, fhesd, iw, w)

Input Parameters

1:     iflag – int64int32nag_int scalar
Is set to a non-negative number.
2:     n – int64int32nag_int scalar
The number n$n$ of variables.
3:     xc(n) – double array
The point x$x$ at which the second derivatives of F$F$ are required.
4:     lh – int64int32nag_int scalar
The length of the array fhesl.
5:     fhesd(n) – double array
The value of (F)/(xj) $\frac{\partial F}{\partial {x}_{\mathit{j}}}$ at the point x$x$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$.
These values may be useful in the evaluation of the second derivatives.
6:     iw(liw) – int64int32nag_int array
7:     w(lw) – double array
As in funct, these parameters correspond to the parameters iw, liw, w, lw of nag_opt_bounds_mod_deriv2_comp (e04lb). h must not change the first two elements of iw or the first max (8,7 × n + n × (n1) / 2)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(8,7×{\mathbf{n}}+{\mathbf{n}}×\left({\mathbf{n}}-1\right)/2\right)$ elements of w. Again, it is recommended that you should pass quantities to h via global variables and not use iw or w at all.

Output Parameters

1:     iflag – int64int32nag_int scalar
If h resets iflag to some negative number, nag_opt_bounds_mod_deriv2_comp (e04lb) will terminate immediately with ifail set to your setting of iflag.
2:     fhesl(lh) – double array
Unless iflag is reset, h must place the strict lower triangle of the second derivative matrix of F$F$ (evaluated at the point x$x$) in fhesl, stored by rows, i.e., set fhesl( (i1) (i2) / 2 + j ) = ( 2 F )/( xi xj )|xc ${\mathbf{fhesl}}\left(\left(\mathit{i}-1\right)\left(\mathit{i}-2\right)/2+\mathit{j}\right)={\frac{{\partial }^{2}F}{\partial {x}_{\mathit{i}}\partial {x}_{\mathit{j}}}|}_{{\mathbf{xc}}}$, for i = 2,3,,n$\mathit{i}=2,3,\dots ,n$ and j = 1,2,,i1$\mathit{j}=1,2,\dots ,i-1$. (The upper triangle is not required because the matrix is symmetric.)
3:     fhesd(n) – double array
Unless iflag is reset, h must place the diagonal elements of the second derivative matrix of F$F$ (evaluated at the point x$x$) in fhesd, i.e., set fhesd(j) = ( 2 F )/( xj2 )|xc ${\mathbf{fhesd}}\left(j\right)={\frac{{\partial }^{2}F}{\partial {x}_{j}^{2}}|}_{{\mathbf{xc}}}$, j = 1,2,,n$j=1,2,\dots ,n$.
4:     iw(liw) – int64int32nag_int array
5:     w(lw) – double array
Note:  h should be tested separately before being used in conjunction with nag_opt_bounds_mod_deriv2_comp (e04lb).
3:     monit – function handle or string containing name of m-file
If iprint0${\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 iprint < 0${\mathbf{iprint}}<0$, a monit with the correct parameter list should still be supplied, although it will not be called.
[iw, w] = monit(n, xc, fc, gc, istate, gpjnrm, cond, posdef, niter, nf, iw, w)

Input Parameters

1:     n – int64int32nag_int scalar
The number n$n$ of variables.
2:     xc(n) – double array
The coordinates of the current point x$x$.
3:     fc – double scalar
The value of F(x)$F\left(x\right)$ at the current point x$x$.
4:     gc(n) – double array
The value of (F)/(xj) $\frac{\partial F}{\partial {x}_{\mathit{j}}}$ at the current point x$x$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$.
5:     istate(n) – int64int32nag_int array
Information about which variables are currently fixed on their bounds and which are free.
If istate(j)${\mathbf{istate}}\left(j\right)$ is negative, xj${x}_{j}$ is currently:
 – fixed on its upper bound if istate(j) = − 1${\mathbf{istate}}\left(j\right)=-1$; – fixed on its lower bound if istate(j) = − 2${\mathbf{istate}}\left(j\right)=-2$; – effectively a constant (i.e., lj = uj${l}_{j}={u}_{j}$) if istate(j) = − 3${\mathbf{istate}}\left(j\right)=-3$.
If istate is positive, its value gives the position of xj${x}_{j}$ in the sequence of free variables.
6:     gpjnrm – double scalar
The Euclidean norm of the projected gradient vector gz${g}_{z}$.
7:     cond – double scalar
The ratio of the largest to the smallest elements of the diagonal factor D$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 – logical scalar
Is set true or false according to whether the second derivative matrix for the current subspace, H$H$, is positive definite or not.
9:     niter – int64int32nag_int scalar
The number of iterations (as outlined in Section [Description]) which have been performed by nag_opt_bounds_mod_deriv2_comp (e04lb) so far.
10:   nf – int64int32nag_int scalar
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) – int64int32nag_int array
12:   w(lw) – double array
As in funct, and h, these parameters correspond to the parameters iw, liw, w, lw of nag_opt_bounds_mod_deriv2_comp (e04lb). They are included in monit's parameter list primarily for when nag_opt_bounds_mod_deriv2_comp (e04lb) is called by other library functions.

Output Parameters

1:     iw(liw) – int64int32nag_int array
2:     w(lw) – double array
You should normally print out fc, gpjnrm and cond so as to be able to compare the quantities mentioned in Section [Accuracy]. It is normally helpful to examine xc, posdef and nf as well.
4:     ibound – int64int32nag_int scalar
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:
ibound = 0${\mathbf{ibound}}=0$
If the variables are bounded and you are supplying all the lj${l}_{j}$ and uj${u}_{j}$ individually.
ibound = 1${\mathbf{ibound}}=1$
If the problem is unconstrained.
ibound = 2${\mathbf{ibound}}=2$
If the variables are bounded, but all the bounds are of the form 0xj$0\le {x}_{j}$.
ibound = 3${\mathbf{ibound}}=3$
If all the variables are bounded, and l1 = l2 = = ln${l}_{1}={l}_{2}=\cdots ={l}_{n}$ and u1 = u2 = = un${u}_{1}={u}_{2}=\cdots ={u}_{n}$.
ibound = 4${\mathbf{ibound}}=4$
If the problem is unconstrained. (The ibound = 4${\mathbf{ibound}}=4$ option is provided purely for consistency with other functions. In nag_opt_bounds_mod_deriv2_comp (e04lb) it produces the same effect as ibound = 1${\mathbf{ibound}}=1$.)
Constraint: 0ibound4$0\le {\mathbf{ibound}}\le 4$.
5:     bl(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The fixed lower bounds lj${l}_{j}$.
If ibound is set to 0$0$, you must set bl(j)${\mathbf{bl}}\left(\mathit{j}\right)$ to lj${l}_{\mathit{j}}$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$. (If a lower bound is not specified for any xj${x}_{j}$, the corresponding bl(j)${\mathbf{bl}}\left(j\right)$ should be set to a large negative number, e.g., 106$-{10}^{6}$.)
If ibound is set to 3$3$, you must set bl(1)${\mathbf{bl}}\left(1\right)$ to l1${l}_{1}$; nag_opt_bounds_mod_deriv2_comp (e04lb) will then set the remaining elements of bl equal to bl(1)${\mathbf{bl}}\left(1\right)$.
If ibound is set to 1$1$, 2$2$ or 4$4$, bl will be initialized by nag_opt_bounds_mod_deriv2_comp (e04lb).
6:     bu(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The fixed upper bounds uj${u}_{j}$.
If ibound is set to 0$0$, you must set bu(j)${\mathbf{bu}}\left(\mathit{j}\right)$ to uj${u}_{\mathit{j}}$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$. (If an upper bound is not specified for any variable, the corresponding bu(j)${\mathbf{bu}}\left(j\right)$ should be set to a large positive number, e.g., 106${10}^{6}$.)
If ibound is set to 3$3$, you must set bu(1)${\mathbf{bu}}\left(1\right)$ to u1${u}_{1}$; nag_opt_bounds_mod_deriv2_comp (e04lb) will then set the remaining elements of bu equal to bu(1)${\mathbf{bu}}\left(1\right)$.
If ibound is set to 1$1$, 2$2$ or 4$4$, bu will then be initialized by nag_opt_bounds_mod_deriv2_comp (e04lb).
7:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
x(j)${\mathbf{x}}\left(\mathit{j}\right)$ must be set to a guess at the j$\mathit{j}$th component of the position of the minimum, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$.
8:     lh – int64int32nag_int scalar
The dimension of the array hesl as declared in the (sub)program from which nag_opt_bounds_mod_deriv2_comp (e04lb) is called.
Constraint: lhmax (n × (n1) / 2,1)${\mathbf{lh}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}}×\left({\mathbf{n}}-1\right)/2,1\right)$.
9:     iw(liw) – int64int32nag_int array
liw, the dimension of the array, must satisfy the constraint liw2$\mathit{liw}\ge 2$.
Constraint: liw2$\mathit{liw}\ge 2$.
10:   w(lw) – double array
lw, the dimension of the array, must satisfy the constraint lwmax (7 × n + n × (n1) / 2,8)$\mathit{lw}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(7×{\mathbf{n}}+{\mathbf{n}}×\left({\mathbf{n}}-1\right)/2,8\right)$.
Constraint: lwmax (7 × n + n × (n1) / 2,8)$\mathit{lw}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(7×{\mathbf{n}}+{\mathbf{n}}×\left({\mathbf{n}}-1\right)/2,8\right)$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays bl, bu, x. (An error is raised if these dimensions are not equal.)
The number n$n$ of independent variables.
Constraint: n1${\mathbf{n}}\ge 1$.
2:     iprint – int64int32nag_int scalar
The frequency with which monit is to be called.
iprint > 0${\mathbf{iprint}}>0$
monit is called once every iprint iterations and just before exit from nag_opt_bounds_mod_deriv2_comp (e04lb).
iprint = 0${\mathbf{iprint}}=0$
monit is just called at the final point.
iprint < 0${\mathbf{iprint}}<0$
monit is not called at all.
iprint should normally be set to a small positive number.
Default: 1$1$
3:     maxcal – int64int32nag_int scalar
The maximum permitted number of evaluations of F(x)$F\left(x\right)$, i.e., the maximum permitted number of calls of funct.
Default: 50 × n$50×{\mathbf{n}}$
Constraint: maxcal1${\mathbf{maxcal}}\ge 1$.
4:     eta – double scalar
Every iteration of nag_opt_bounds_mod_deriv2_comp (e04lb) involves a linear minimization (i.e., minimization of F(x + αp)$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$0.01$) than for large values (say, 0.9$0.9$).
Although accurate linear minimizations will generally reduce the number of iterations of nag_opt_bounds_mod_deriv2_comp (e04lb), 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: eta = 0.9${\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 n = 1${\mathbf{n}}=1$, eta should be set to 0.0$0.0$ (also when the problem is effectively one-dimensional even though n > 1$n>1$; i.e., if for all except one of the variables the lower and upper bounds are equal).
Default:
• if n = 1${\mathbf{n}}=1$, 0.0$0.0$;
• otherwise 0.9$0.9$.
Constraint: 0.0eta < 1.0$0.0\le {\mathbf{eta}}<1.0$.
5:     xtol – double scalar
The accuracy in x$x$ to which the solution is required.
If xtrue${x}_{\mathrm{true}}$ is the true value of x$x$ at the minimum, then xsol${x}_{\mathrm{sol}}$, the estimated position before a normal exit, is such that xsolxtrue < xtol × (1.0 + xtrue)$‖{x}_{\mathrm{sol}}-{x}_{\mathrm{true}}‖<{\mathbf{xtol}}×\left(1.0+‖{x}_{\mathrm{true}}‖\right)$, where y = sqrt(j = 1nyj2)$‖y‖=\sqrt{\sum _{j=1}^{n}{y}_{j}^{2}}$. For example, if the elements of xsol${x}_{\mathrm{sol}}$ are not much larger than 1.0$1.0$ in modulus, and if xtol is set to 105${10}^{-5}$ then xsol${x}_{\mathrm{sol}}$ is usually accurate to about five decimal places. (For further details see Section [Accuracy].)
If the problem is scaled roughly as described in Section [Further Comments] and ε$\epsilon$ is the machine precision, then sqrt(ε)$\sqrt{\epsilon }$ is probably the smallest reasonable choice for xtol. (This is because, normally, to machine accuracy, F(x + sqrt(ε),ej) = F(x)$F\left(x+\sqrt{\epsilon },{e}_{j}\right)=F\left(x\right)$ where ej${e}_{j}$ is any column of the identity matrix.)
If you set xtol to 0.0$0.0$ (or any positive value less than ε$\epsilon$), nag_opt_bounds_mod_deriv2_comp (e04lb) will use 10.0 × sqrt(ε)$10.0×\sqrt{\epsilon }$ instead of xtol.
Default: 0.0$0.0$
Constraint: xtol0.0${\mathbf{xtol}}\ge 0.0$.
6:     stepmx – double scalar
An estimate of the Euclidean distance between the solution and the starting point supplied by you. (For maximum efficiency a slight overestimate is preferable.)
nag_opt_bounds_mod_deriv2_comp (e04lb) will ensure that, for each iteration,
 sqrt( ∑ j = 1n [xj(k) − xj(k − 1)]2 ) ≤ stepmx $∑j=1n [xj (k) -xj (k-1) ] 2 ≤stepmx$
where k$k$ is the iteration number. Thus, if the problem has more than one solution, nag_opt_bounds_mod_deriv2_comp (e04lb) 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)${x}^{\left(k\right)}$ entering a region where the problem is ill-behaved and can also help to avoid possible overflow in the evaluation of F(x)$F\left(x\right)$. However, an underestimate of stepmx can lead to inefficiency.
Default: 100000.0$100000.0$
Constraint: ${\mathbf{stepmx}}\ge {\mathbf{xtol}}$.

liw lw

### Output Parameters

1:     bl(n) – double array
The lower bounds actually used by nag_opt_bounds_mod_deriv2_comp (e04lb), e.g., if ibound = 2${\mathbf{ibound}}=2$, bl(1) = bl(2) = = bl(n) = 0.0${\mathbf{bl}}\left(1\right)={\mathbf{bl}}\left(2\right)=\cdots ={\mathbf{bl}}\left({\mathbf{n}}\right)=0.0$.
2:     bu(n) – double array
The upper bounds actually used by nag_opt_bounds_mod_deriv2_comp (e04lb), e.g., if ibound = 2${\mathbf{ibound}}=2$, bu(1) = bu(2) = = bu(n) = 106${\mathbf{bu}}\left(1\right)={\mathbf{bu}}\left(2\right)=\cdots ={\mathbf{bu}}\left({\mathbf{n}}\right)={10}^{6}$.
3:     x(n) – double array
The final point x(k)${x}^{\left(k\right)}$. Thus, if ${\mathbf{ifail}}={\mathbf{0}}$ on exit, x(j)${\mathbf{x}}\left(j\right)$ is the j$j$th component of the estimated position of the minimum.
4:     hesl(lh) – double array
During the determination of a direction pz${p}_{z}$ (see Section [Description]), H + E$H+E$ is decomposed into the product LDLT$LD{L}^{\mathrm{T}}$, where L$L$ is a unit lower triangular matrix and D$D$ is a diagonal matrix. (The matrices H$H$, E$E$, L$L$ and D$D$ are all of dimension nz${n}_{z}$, where nz${n}_{z}$ is the number of variables free from their bounds. H$H$ consists of those rows and columns of the full estimated second derivative matrix which relate to free variables. E$E$ is chosen so that H + E$H+E$ is positive definite.)
hesl and hesd are used to store the factors L$L$ and D$D$. The elements of the strict lower triangle of L$L$ are stored row by row in the first nz(nz1) / 2${n}_{z}\left({n}_{z}-1\right)/2$ positions of hesl. The diagonal elements of D$D$ are stored in the first nz${n}_{z}$ positions of hesd. In the last factorization before a normal exit, the matrix E$E$ will be zero, so that hesl and hesd will contain, on exit, the factors of the final estimated second derivative matrix H$H$. The elements of hesd are useful for deciding whether to accept the results produced by nag_opt_bounds_mod_deriv2_comp (e04lb) (see Section [Accuracy]).
5:     hesd(n) – double array
During the determination of a direction pz${p}_{z}$ (see Section [Description]), H + E$H+E$ is decomposed into the product LDLT$LD{L}^{\mathrm{T}}$, where L$L$ is a unit lower triangular matrix and D$D$ is a diagonal matrix. (The matrices H$H$, E$E$, L$L$ and D$D$ are all of dimension nz${n}_{z}$, where nz${n}_{z}$ is the number of variables free from their bounds. H$H$ consists of those rows and columns of the full second derivative matrix which relate to free variables. E$E$ is chosen so that H + E$H+E$ is positive definite.)
hesl and hesd are used to store the factors L$L$ and D$D$. The elements of the strict lower triangle of L$L$ are stored row by row in the first nz(nz1) / 2${n}_{z}\left({n}_{z}-1\right)/2$ positions of hesl. The diagonal elements of D$D$ are stored in the first nz${n}_{z}$ positions of hesd.
In the last factorization before a normal exit, the matrix E$E$ will be zero, so that hesl and hesd will contain, on exit, the factors of the final second derivative matrix H$H$. The elements of hesd are useful for deciding whether to accept the result produced by nag_opt_bounds_mod_deriv2_comp (e04lb) (see Section [Accuracy]).
6:     istate(n) – int64int32nag_int array
Information about which variables are currently on their bounds and which are free. If istate(j)${\mathbf{istate}}\left(j\right)$ is:
• – equal to 1$-1$, xj${x}_{j}$ is fixed on its upper bound;
• – equal to 2$-2$, xj${x}_{j}$ is fixed on its lower bound;
• – equal to 3$-3$, xj${x}_{j}$ is effectively a constant (i.e., lj = uj${l}_{j}={u}_{j}$);
• – positive, istate(j)${\mathbf{istate}}\left(j\right)$ gives the position of xj${x}_{j}$ in the sequence of free variables.
7:     f – double scalar
The function value at the final point given in x.
8:     g(n) – double array
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.
9:     iw(liw) – int64int32nag_int array
liw2$\mathit{liw}\ge 2$.
Communication array, used to store information between calls to nag_opt_bounds_mod_deriv2_comp (e04lb).
10:   w(lw) – double array
lwmax (7 × n + n × (n1) / 2,8)$\mathit{lw}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(7×{\mathbf{n}}+{\mathbf{n}}×\left({\mathbf{n}}-1\right)/2,8\right)$.
Communication array, used to store information between calls to nag_opt_bounds_mod_deriv2_comp (e04lb).
11:   ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Note: nag_opt_bounds_mod_deriv2_comp (e04lb) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W ifail < 0${\mathbf{ifail}}<0$
A negative value of ifail indicates an exit from nag_opt_bounds_mod_deriv2_comp (e04lb) because you have set iflag negative in funct or h. The value of ifail will be the same as your setting of iflag.
ifail = 1${\mathbf{ifail}}=1$
 On entry, n < 1${\mathbf{n}}<1$, or maxcal < 1${\mathbf{maxcal}}<1$, or eta < 0.0${\mathbf{eta}}<0.0$, or eta ≥ 1.0${\mathbf{eta}}\ge 1.0$, or xtol < 0.0${\mathbf{xtol}}<0.0$, or ${\mathbf{stepmx}}<{\mathbf{xtol}}$, or ibound < 0${\mathbf{ibound}}<0$, or ibound > 4${\mathbf{ibound}}>4$, or bl(j) > bu(j)${\mathbf{bl}}\left(j\right)>{\mathbf{bu}}\left(j\right)$ for some j$j$ if ibound = 0${\mathbf{ibound}}=0$, or bl(1) > bu(1)${\mathbf{bl}}\left(1\right)>{\mathbf{bu}}\left(1\right)$ if ibound = 3${\mathbf{ibound}}=3$, or lh < max (1,n × (n − 1) / 2) ${\mathbf{lh}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}-1\right)/2\right)$, or liw < 2$\mathit{liw}<2$, or lw < max (8,7 × n + n × (n − 1) / 2) $\mathit{lw}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(8,7×{\mathbf{n}}+{\mathbf{n}}×\left({\mathbf{n}}-1\right)/2\right)$.
(Note that if you have set xtol to 0.0$0.0$, nag_opt_bounds_mod_deriv2_comp (e04lb) 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.
ifail = 2${\mathbf{ifail}}=2$
There have been maxcal function evaluations. If steady reductions in F(x)$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$x$. This exit may also indicate that F(x)$F\left(x\right)$ has no minimum.
W ifail = 3${\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(x)$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(x)$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.
ifail = 4${\mathbf{ifail}}=4$
Not used. (This is done to make the significance of ${\mathbf{ifail}}={\mathbf{5}}$ similar for nag_opt_bounds_mod_deriv_comp (e04kd) and nag_opt_bounds_mod_deriv2_comp (e04lb).)
W ifail = 5${\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}}$, 3${\mathbf{3}}$ or 5${\mathbf{5}}$ may also be caused by mistakes in user-supplied functions 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.

## Accuracy

A successful exit (${\mathbf{ifail}}={\mathbf{0}}$) is made from nag_opt_bounds_mod_deriv2_comp (e04lb) when H(k)${H}^{\left(k\right)}$ is positive definite and when (B1, B2 and B3) or B4 hold, where
 B1 ≡ α(k) × ‖p(k)‖ < (xtol + sqrt(ε)) × (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 × sqrt(ε).
$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$k$ are the values at the k$k$th iteration of the quantities mentioned in Section [Description]. ε$\epsilon$ is the machine precision and . $‖.‖$ denotes the Euclidean norm.)
If ${\mathbf{ifail}}={\mathbf{0}}$, then the vector in x on exit, xsol${x}_{\mathrm{sol}}$, is almost certainly an estimate of the position of the minimum, xtrue${x}_{\mathrm{true}}$, to the accuracy specified by xtol.
If ${\mathbf{ifail}}={\mathbf{3}}$ or 5${\mathbf{5}}$, xsol${x}_{\mathrm{sol}}$ may still be a good estimate of xtrue${x}_{\mathrm{true}}$, but the following checks should be made. Let the largest of the first nz${n}_{z}$ elements of hesd be hesd(b)${\mathbf{hesd}}\left(b\right)$, let the smallest be hesd(s)${\mathbf{hesd}}\left(s\right)$, and define k = hesd(b) / hesd(s)$k={\mathbf{hesd}}\left(b\right)/{\mathbf{hesd}}\left(s\right)$. The scalar k$k$ is usually a good estimate of the condition number of the projected Hessian matrix at xsol${x}_{\mathrm{sol}}$. If
 (i) the sequence {F(x(k))}$\left\{F\left({x}^{\left(k\right)}\right)\right\}$ converges to F(xsol)$F\left({x}_{\mathrm{sol}}\right)$ at a superlinear or fast linear rate, (ii) ‖gz(xsol)‖2 < 10.0 × ε${‖{g}_{z}\left({x}_{\mathrm{sol}}\right)‖}^{2}<10.0×\epsilon$, and (iii) k < 1.0 / ‖gz(xsol)‖$k<1.0/‖{g}_{z}\left({x}_{\mathrm{sol}}\right)‖$,
then it is almost certain that xsol${x}_{\mathrm{sol}}$ is a close approximation to the position of a minimum. When (ii) is true, then usually F(xsol)$F\left({x}_{\mathrm{sol}}\right)$ is a close approximation to F(xtrue)$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$k$
Further suggestions about confirmation of a computed solution are given in the E04 Chapter Introduction.

### Timing

The number of iterations required depends on the number of variables, the behaviour of F(x)$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 nag_opt_bounds_mod_deriv2_comp (e04lb) is (nz3)/6 + O(nz2)$\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(x)$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.

### Scaling

Ideally, the problem should be scaled so that, at the solution, F(x)$F\left(x\right)$ and the corresponding values of the xj${x}_{j}$ are each in the range (1, + 1)$\left(-1,+1\right)$, and so that at points one unit away from the solution, F(x)$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 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 nag_opt_bounds_mod_deriv2_comp (e04lb) will take less computer time.

### Unconstrained Minimization

If a problem is genuinely unconstrained and has been scaled sensibly, the following points apply:
 (a) nz${n}_{z}$ will always be n$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$g$ should all be close to zero at the final point, (d) the values of the istate(j)${\mathbf{istate}}\left(j\right)$ given by monit and on exit from nag_opt_bounds_mod_deriv2_comp (e04lb) are unlikely to be of interest (unless they are negative, which would indicate that the modulus of one of the xj${x}_{j}$ has reached 106${10}^{6}$ for some reason), (e) monit's parameter gpjnrm simply gives the norm of the first derivative vector.

## Example

```function nag_opt_bounds_mod_deriv2_comp_example
ibound = int64(0);
bl = [1;
-2;
-1000000;
1];
bu = [3;
0;
1000000;
3];
x = [3;
-1;
0;
1];
lh = int64(6);
iw = [int64(0);0];
w = zeros(34,1);
[blOut, buOut, xOut, hesl, hesd, istate, f, g, iwOut, wOut, ifail] = ...
nag_opt_bounds_mod_deriv2_comp(@funct, @hess, @monit, ibound, bl, bu, x, lh, iw, w)

function [iflag, fc, gc] = funct(iflag, n, xc)
gc = zeros(n, 1);

fc = (xc(1)+10*xc(2))^2 + 5*(xc(3)-xc(4))^2 + (xc(2)-2*xc(3))^4 + ...
10*(xc(1)-xc(4))^4;
gc(1) = 2*(xc(1)+10*xc(2)) + 40*(xc(1)-xc(4))^3;
gc(2) = 20*(xc(1)+10*xc(2)) + 4*(xc(2)-2*xc(3))^3;
gc(3) = 10*(xc(3)-xc(4)) - 8*(xc(2)-2*xc(3))^3;
gc(4) = 10*(xc(4)-xc(3)) - 40*(xc(1)-xc(4))^3;

function [iflag, fhesl, fhesd] = hess(iflag, n, xc, lh, fhesd)
fhesl = zeros(lh, 1);

fhesd(1) = 2.0d0 + 120.0d0*(xc(1)-xc(4))^2;
fhesd(2) = 200.0d0 + 12.0d0*(xc(2)-2.0d0*xc(3))^2;
fhesd(3) = 10.0d0 + 48.0d0*(xc(2)-2.0d0*xc(3))^2;
fhesd(4) = 10.0d0 + 120.0d0*(xc(1)-xc(4))^2;
fhesl(1) = 20.0d0;
fhesl(2) = 0.0d0;
fhesl(3) = -24.0d0*(xc(2)-2.0d0*xc(3))^2;
fhesl(4) = -120.0d0*(xc(1)-xc(4))^2;
fhesl(5) = 0.0d0;
fhesl(6) = -10.0d0;

function [] = monit(n, xc, fc, gc, istate, gpjnrm, cond, posdef, niter, nf)

fprintf('\n Itn     Fn evals              Fn value            Norm of proj gradient\n');
fprintf(' %3d      %5d    %20.4f      %20.4f\n', niter, nf, fc, gpjnrm);
fprintf('\n J           X(J)                G(J)         Status\n');
for j = 1:double(n)
isj = istate(j);
if (isj > 0)
fprintf('%2d %16.4f%20.4f   %s\n', j, xc(j), gc(j), '    Free');
elseif (isj == -1)
fprintf('%2d %16.4f%20.4f   %s\n', j, xc(j), gc(j), '    Upper Bound');
elseif (isj == -2)
fprintf('%2d %16.4f%20.4f   %s\n', j, xc(j), gc(j), '    Lower Bound');
elseif (isj == -3)
fprintf('%2d %16.4f%20.4f   %s\n', j, xc(j), gc(j), '    Constant');
end
end
if (cond ~= 0.0d0)
if (cond > 1.0d6)
fprintf('\nEstimated condition number of projected Hessian is more than 1.0e+6\n');
else
fprintf('\nEstimated condition number of projected Hessian = %10.2f\n', cond);
end
if ( not(posdef) )
%     The following statement is included so that this MONIT
%     can be used in conjunction with either of the routines
%     nag_opt_bounds_mod_deriv_comp or nag_opt_bounds_mod_deriv2_comp
fprintf('\nProjected Hessian matrix is not positive definite\n');
end
end
```
```

Itn     Fn evals              Fn value            Norm of proj gradient
0          1                215.0000                  144.0139

J           X(J)                G(J)         Status
1           3.0000            306.0000       Upper Bound
2          -1.0000           -144.0000       Free
3           0.0000             -2.0000       Free
4           1.0000           -310.0000       Lower Bound

Estimated condition number of projected Hessian =       3.83

Itn     Fn evals              Fn value            Norm of proj gradient
1          2                163.0642                  320.3345

J           X(J)                G(J)         Status
1           3.0000            320.3345       Free
2          -0.2833             -0.0351       Free
3           0.3311              0.0703       Free
4           1.0000           -313.3106       Lower Bound

Estimated condition number of projected Hessian =       9.46

Itn     Fn evals              Fn value            Norm of proj gradient
2          3                 34.3864                   94.9936

J           X(J)                G(J)         Status
1           2.3327             94.9936       Free
2          -0.2172             -0.0026       Free
3           0.3565              0.0052       Free
4           1.0000            -88.2372       Lower Bound

Estimated condition number of projected Hessian =       4.35

Itn     Fn evals              Fn value            Norm of proj gradient
3          4                  8.8929                   28.2250

J           X(J)                G(J)         Status
1           1.8870             28.2250       Free
2          -0.1731             -0.0009       Free
3           0.3742              0.0017       Free
4           1.0000            -21.6542       Lower Bound

Estimated condition number of projected Hessian =       4.23

Itn     Fn evals              Fn value            Norm of proj gradient
4          5                  3.8068                    8.4415

J           X(J)                G(J)         Status
1           1.5881              8.4415       Free
2          -0.1435             -0.0004       Free
3           0.3861              0.0008       Free
4           1.0000             -1.9952       Lower Bound

Estimated condition number of projected Hessian =       4.62

Itn     Fn evals              Fn value            Norm of proj gradient
5          6                  2.7680                    2.5810

J           X(J)                G(J)         Status
1           1.3847              2.5810       Free
2          -0.1233             -0.0002       Free
3           0.3941              0.0004       Free
4           1.0000              3.7808       Lower Bound

Estimated condition number of projected Hessian =       9.60

Itn     Fn evals              Fn value            Norm of proj gradient
6          7                  2.5381                    0.8503

J           X(J)                G(J)         Status
1           1.2396              0.8503       Free
2          -0.1090             -0.0001       Free
3           0.3998              0.0002       Free
4           1.0000              5.4513       Lower Bound

Estimated condition number of projected Hessian =      18.55

Itn     Fn evals              Fn value            Norm of proj gradient
7          8                  2.4702                    0.3609

J           X(J)                G(J)         Status
1           1.1165              0.3609       Free
2          -0.0968             -0.0001       Free
3           0.4047              0.0001       Free
4           1.0000              5.8896       Lower Bound

Estimated condition number of projected Hessian =      27.45

Itn     Fn evals              Fn value            Norm of proj gradient
8          9                  2.4338                    0.0002

J           X(J)                G(J)         Status
1           1.0000              0.2953       Lower Bound
2          -0.0852             -0.0001       Free
3           0.4093              0.0002       Free
4           1.0000              5.9069       Lower Bound

Estimated condition number of projected Hessian =       4.43

Itn     Fn evals              Fn value            Norm of proj gradient
9         10                  2.4338                    0.0000

J           X(J)                G(J)         Status
1           1.0000              0.2953       Lower Bound
2          -0.0852             -0.0000       Free
3           0.4093              0.0000       Free
4           1.0000              5.9070       Lower Bound

Estimated condition number of projected Hessian =       4.43

Itn     Fn evals              Fn value            Norm of proj gradient
10         11                  2.4338                    0.0000

J           X(J)                G(J)         Status
1           1.0000              0.2953       Lower Bound
2          -0.0852             -0.0000       Free
3           0.4093              0.0000       Free
4           1.0000              5.9070       Lower Bound

Estimated condition number of projected Hessian =       4.43
Warning: nag_opt_bounds_mod_deriv2_comp (e04lb) returned a warning indicator (3)

blOut =

1
-2
-1000000
1

buOut =

3
0
1000000
3

xOut =

1.0000
-0.0852
0.4093
1.0000

hesl =

-0.0935
0
-0.1978
0
0
0

hesd =

209.8031
47.3802
45.5183
0

istate =

-2
1
2
-2

f =

2.4338

g =

0.2953
-0.0000
0.0000
5.9070

iwOut =

-1
0

wOut =

1.0000
-0.0852
0.4093
1.0000
0.2953
0.0000
-0.0000
5.9070
0.2953
-0.0000
0.0000
5.9070
0
0.0000
-0.0000
0
-0.0000
0.0000
0.0001
0
-0.0000
0.0000
-0.0086
0
2.0000
209.8031
49.2125
10.0000
20.0000
0
-19.6062
0
0
-10.0000

ifail =

3

```
```function e04lb_example
ibound = int64(0);
bl = [1;
-2;
-1000000;
1];
bu = [3;
0;
1000000;
3];
x = [3;
-1;
0;
1];
lh = int64(6);
iw = [int64(0);0];
w = zeros(34,1);
[blOut, buOut, xOut, hesl, hesd, istate, f, g, iwOut, wOut, ifail] = ...
e04lb(@funct, @hess, @monit, ibound, bl, bu, x, lh, iw, w)

function [iflag, fc, gc] = funct(iflag, n, xc)
gc = zeros(n, 1);

fc = (xc(1)+10*xc(2))^2 + 5*(xc(3)-xc(4))^2 + (xc(2)-2*xc(3))^4 + ...
10*(xc(1)-xc(4))^4;
gc(1) = 2*(xc(1)+10*xc(2)) + 40*(xc(1)-xc(4))^3;
gc(2) = 20*(xc(1)+10*xc(2)) + 4*(xc(2)-2*xc(3))^3;
gc(3) = 10*(xc(3)-xc(4)) - 8*(xc(2)-2*xc(3))^3;
gc(4) = 10*(xc(4)-xc(3)) - 40*(xc(1)-xc(4))^3;

function [iflag, fhesl, fhesd] = hess(iflag, n, xc, lh, fhesd)
fhesl = zeros(lh, 1);

fhesd(1) = 2.0d0 + 120.0d0*(xc(1)-xc(4))^2;
fhesd(2) = 200.0d0 + 12.0d0*(xc(2)-2.0d0*xc(3))^2;
fhesd(3) = 10.0d0 + 48.0d0*(xc(2)-2.0d0*xc(3))^2;
fhesd(4) = 10.0d0 + 120.0d0*(xc(1)-xc(4))^2;
fhesl(1) = 20.0d0;
fhesl(2) = 0.0d0;
fhesl(3) = -24.0d0*(xc(2)-2.0d0*xc(3))^2;
fhesl(4) = -120.0d0*(xc(1)-xc(4))^2;
fhesl(5) = 0.0d0;
fhesl(6) = -10.0d0;

function [] = monit(n, xc, fc, gc, istate, gpjnrm, cond, posdef, niter, nf)

fprintf('\n Itn     Fn evals              Fn value            Norm of proj gradient\n');
fprintf(' %3d      %5d    %20.4f      %20.4f\n', niter, nf, fc, gpjnrm);
fprintf('\n J           X(J)                G(J)         Status\n');
for j = 1:double(n)
isj = istate(j);
if (isj > 0)
fprintf('%2d %16.4f%20.4f   %s\n', j, xc(j), gc(j), '    Free');
elseif (isj == -1)
fprintf('%2d %16.4f%20.4f   %s\n', j, xc(j), gc(j), '    Upper Bound');
elseif (isj == -2)
fprintf('%2d %16.4f%20.4f   %s\n', j, xc(j), gc(j), '    Lower Bound');
elseif (isj == -3)
fprintf('%2d %16.4f%20.4f   %s\n', j, xc(j), gc(j), '    Constant');
end
end
if (cond ~= 0.0d0)
if (cond > 1.0d6)
fprintf('\nEstimated condition number of projected Hessian is more than 1.0e+6\n');
else
fprintf('\nEstimated condition number of projected Hessian = %10.2f\n', cond);
end
if ( not(posdef) )
%     The following statement is included so that this MONIT
%     can be used in conjunction with either of the routines
%     E04KDF or  E04LBF
fprintf('\nProjected Hessian matrix is not positive definite\n');
end
end
```
```

Itn     Fn evals              Fn value            Norm of proj gradient
0          1                215.0000                  144.0139

J           X(J)                G(J)         Status
1           3.0000            306.0000       Upper Bound
2          -1.0000           -144.0000       Free
3           0.0000             -2.0000       Free
4           1.0000           -310.0000       Lower Bound

Estimated condition number of projected Hessian =       3.83

Itn     Fn evals              Fn value            Norm of proj gradient
1          2                163.0642                  320.3345

J           X(J)                G(J)         Status
1           3.0000            320.3345       Free
2          -0.2833             -0.0351       Free
3           0.3311              0.0703       Free
4           1.0000           -313.3106       Lower Bound

Estimated condition number of projected Hessian =       9.46

Itn     Fn evals              Fn value            Norm of proj gradient
2          3                 34.3864                   94.9936

J           X(J)                G(J)         Status
1           2.3327             94.9936       Free
2          -0.2172             -0.0026       Free
3           0.3565              0.0052       Free
4           1.0000            -88.2372       Lower Bound

Estimated condition number of projected Hessian =       4.35

Itn     Fn evals              Fn value            Norm of proj gradient
3          4                  8.8929                   28.2250

J           X(J)                G(J)         Status
1           1.8870             28.2250       Free
2          -0.1731             -0.0009       Free
3           0.3742              0.0017       Free
4           1.0000            -21.6542       Lower Bound

Estimated condition number of projected Hessian =       4.23

Itn     Fn evals              Fn value            Norm of proj gradient
4          5                  3.8068                    8.4415

J           X(J)                G(J)         Status
1           1.5881              8.4415       Free
2          -0.1435             -0.0004       Free
3           0.3861              0.0008       Free
4           1.0000             -1.9952       Lower Bound

Estimated condition number of projected Hessian =       4.62

Itn     Fn evals              Fn value            Norm of proj gradient
5          6                  2.7680                    2.5810

J           X(J)                G(J)         Status
1           1.3847              2.5810       Free
2          -0.1233             -0.0002       Free
3           0.3941              0.0004       Free
4           1.0000              3.7808       Lower Bound

Estimated condition number of projected Hessian =       9.60

Itn     Fn evals              Fn value            Norm of proj gradient
6          7                  2.5381                    0.8503

J           X(J)                G(J)         Status
1           1.2396              0.8503       Free
2          -0.1090             -0.0001       Free
3           0.3998              0.0002       Free
4           1.0000              5.4513       Lower Bound

Estimated condition number of projected Hessian =      18.55

Itn     Fn evals              Fn value            Norm of proj gradient
7          8                  2.4702                    0.3609

J           X(J)                G(J)         Status
1           1.1165              0.3609       Free
2          -0.0968             -0.0001       Free
3           0.4047              0.0001       Free
4           1.0000              5.8896       Lower Bound

Estimated condition number of projected Hessian =      27.45

Itn     Fn evals              Fn value            Norm of proj gradient
8          9                  2.4338                    0.0002

J           X(J)                G(J)         Status
1           1.0000              0.2953       Lower Bound
2          -0.0852             -0.0001       Free
3           0.4093              0.0002       Free
4           1.0000              5.9069       Lower Bound

Estimated condition number of projected Hessian =       4.43

Itn     Fn evals              Fn value            Norm of proj gradient
9         10                  2.4338                    0.0000

J           X(J)                G(J)         Status
1           1.0000              0.2953       Lower Bound
2          -0.0852             -0.0000       Free
3           0.4093              0.0000       Free
4           1.0000              5.9070       Lower Bound

Estimated condition number of projected Hessian =       4.43

Itn     Fn evals              Fn value            Norm of proj gradient
10         11                  2.4338                    0.0000

J           X(J)                G(J)         Status
1           1.0000              0.2953       Lower Bound
2          -0.0852             -0.0000       Free
3           0.4093              0.0000       Free
4           1.0000              5.9070       Lower Bound

Estimated condition number of projected Hessian =       4.43
Warning: nag_opt_bounds_mod_deriv2_comp (e04lb) returned a warning indicator (3)

blOut =

1
-2
-1000000
1

buOut =

3
0
1000000
3

xOut =

1.0000
-0.0852
0.4093
1.0000

hesl =

-0.0935
0
-0.1978
0
0
0

hesd =

209.8031
47.3802
45.5183
0

istate =

-2
1
2
-2

f =

2.4338

g =

0.2953
-0.0000
0.0000
5.9070

iwOut =

-1
0

wOut =

1.0000
-0.0852
0.4093
1.0000
0.2953
0.0000
-0.0000
5.9070
0.2953
-0.0000
0.0000
5.9070
0
0.0000
-0.0000
0
-0.0000
0.0000
0.0001
0
-0.0000
0.0000
-0.0086
0
2.0000
209.8031
49.2125
10.0000
20.0000
0
-19.6062
0
0
-10.0000

ifail =

3

```