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

nag_opt_bounds_mod_deriv_comp (e04kd) 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 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).

Mark 22: liw, lw have been removed from the interface

.nag_opt_bounds_mod_deriv_comp (e04kd) 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}${x}_{j}$), problems which have only non-negativity bounds, and problems in which l_{1} = l_{2} = ⋯ = l_{n}${l}_{1}={l}_{2}=\cdots ={l}_{n}$ and u_{1} = u_{2} = ⋯ = u_{n}${u}_{1}={u}_{2}=\cdots ={u}_{n}$. It is possible to specify that a particular x_{j}${x}_{j}$ should be held constant. You must supply a starting point, and a funct to calculate the value of F(x)$F\left(x\right)$ and its first derivatives
( ∂ F)/( ∂ x_{j})
$\frac{\partial F}{\partial {x}_{j}}$ at any point x$x$.

MinimizeF(x _{1},x_{2}, … ,x_{n}) subject to l_{j} ≤ x_{j} ≤ u_{j}, j = 1,2, … ,n.
$$\mathrm{Minimize}F({x}_{1},{x}_{2},\dots ,{x}_{n})\text{\hspace{1em} subject to \hspace{1em}}{l}_{j}\le {x}_{j}\le {u}_{j}\text{, \hspace{1em}}j=1,2,\dots ,n\text{.}$$ |

A typical iteration starts at the current point x$x$ where n_{z}${n}_{z}$ (say) variables are free from their bounds. The vector g_{z}${g}_{z}$, whose elements are the derivatives of F(x)$F\left(x\right)$ with respect to the free variables, is known. The matrix of second derivatives with respect to the free variables, H$H$, is estimated by finite differences. (Note that g_{z}${g}_{z}$ and H$H$ are both of dimension n_{z}${n}_{z}$.) The equations

are solved to give a search direction p_{z}${p}_{z}$. (The matrix E$E$ is chosen so that H + E$H+E$ is positive definite.)

(H + E)p _{z} = − g_{z}
$$(H+E){p}_{z}=-{g}_{z}$$ |

p_{z}${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(x+\alpha p)$ 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 n_{z}${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 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., n_{z}${n}_{z}$ 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, nag_opt_bounds_mod_deriv_comp (e04kd) sets the l_{j}${l}_{j}$ to − 10^{6}$-{10}^{6}$ and the u_{j}${u}_{j}$ to 10^{6}${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_deriv_comp (e04kd) will act as an unconstrained minimization algorithm.

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

- 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)/( ∂ x
_{j}) $\frac{\partial F}{\partial {x}_{j}}$ at a specified point. (However, if you do not wish to calculate F$F$ or its first derivatives at a particular x$x$, there is the option of setting a parameter to cause nag_opt_bounds_mod_deriv_comp (e04kd) 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 1$1$ or 2$2$. The value 1$1$ indicates that only the first derivatives of F$F$ need be supplied, and the value 2$2$ indicates that both F$F$ itself and its first derivatives must be calculated.
- 2: n – int64int32nag_int scalar
- The number n$n$ of variables.
- 3: xc(n) – double array
- The point x$x$ at which the ( ∂ F)/( ∂ x
_{j}) $\frac{\partial F}{\partial {x}_{j}}$, or F$F$ and the ( ∂ F)/( ∂ x_{j}) $\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, lw as for nag_opt_bounds_mod_deriv_comp (e04kd). 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 × (n − 1) / 2) + 1$\mathrm{max}\phantom{\rule{0.125em}{0ex}}(8,7\times {\mathbf{n}}+{\mathbf{n}}\times ({\mathbf{n}}-1)/2)+1$ onwards of w for passing quantities to funct from the function which calls nag_opt_bounds_mod_deriv_comp (e04kd). 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 you must not change the first 2$2$ elements of iw or the first max (8,7 × n + n × (n − 1) / 2)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}(8,7\times {\mathbf{n}}+{\mathbf{n}}\times ({\mathbf{n}}-1)/2)$ elements of w.

**Output Parameters**- 1: iflag – int64int32nag_int scalar
- If it is not possible to evaluate F$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 nag_opt_bounds_mod_deriv_comp (e04kd). nag_opt_bounds_mod_deriv_comp (e04kd) will then terminate immediately, with ifail set to your setting of iflag.
- 2: fc – double scalar
- 3: gc(n) – double array
- 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_deriv_comp (e04kd). - 2: monit – function handle or string containing name of m-file
- If iprint ≥ 0${\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 must 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)/( ∂ x
_{j}) $\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, x
_{j}${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., l _{j}= u_{j}${l}_{j}={u}_{j}$) if istate(j) = − 3${\mathbf{istate}}\left(j\right)=-3$If istate(j)${\mathbf{istate}}\left(j\right)$ is positive, its value gives the position of x_{j}${x}_{j}$ in the sequence of free variables. - 6: gpjnrm – double scalar
- The Euclidean norm of the current projected gradient vector g
_{z}${g}_{z}$. - 7: cond – double scalar
- The ratio of the largest to the smallest elements of the diagonal factor D$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 – logical scalar
- Specifies
**true**or**false**according to whether or not the approximation to the second derivative matrix for the current subspace, H$H$, is positive definite. - 9: niter – int64int32nag_int scalar
- The number of iterations (as outlined in Section [Description]) which have been performed by nag_opt_bounds_mod_deriv_comp (e04kd) so far.
- 10: nf – int64int32nag_int scalar
- The number of evaluations of F(x)$F\left(x\right)$ so far, i.e., the number of calls of funct with iflag set to 2$2$. Each such call of funct also calculates the first derivatives of F$F$. (In addition to these calls monitored by nf, funct is called with iflag set to 1$1$ not more than n times per iteration.)
- 11: iw(liw) – int64int32nag_int array
- 12: w(lw) – double array

**Output Parameters** - 3: eta – double scalar
- Every iteration of nag_opt_bounds_mod_deriv_comp (e04kd) involves a linear minimization (i.e., minimization of F(x + αp)$F(x+\alpha p)$ 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 large values (say, 0.9$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$n$ is small and a high accuracy minimization when n$n$ is large.
*Suggested value*: - 4: ibound – int64int32nag_int scalar
- 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${\mathbf{ibound}}=0$
- If the variables are bounded and you are supplying all the l
_{j}${l}_{j}$ and u_{j}${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 0 ≤ x
_{j}$0\le {x}_{j}$. - ibound = 3${\mathbf{ibound}}=3$
- If all the variables are bounded, and l
_{1}= l_{2}= ⋯ = l_{n}${l}_{1}={l}_{2}=\cdots ={l}_{n}$ and u_{1}= u_{2}= ⋯ = u_{n}${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 for consistency with other functions. In nag_opt_bounds_mod_deriv_comp (e04kd) it produces the same effect as ibound = 1.${\mathbf{ibound}}=1\text{.}$)

- 5: bl(n) – double array
- The fixed lower bounds l
_{j}${l}_{j}$.If ibound is set to 0$0$, you must set bl(j)${\mathbf{bl}}\left(\mathit{j}\right)$ to l_{j}${l}_{\mathit{j}}$, for j = 1,2, … ,n$\mathit{j}=1,2,\dots ,n$. (If a lower bound is not specified for any x_{j}${x}_{j}$, the corresponding bl(j)${\mathbf{bl}}\left(j\right)$ should be set to a large negative number, e.g., − 10^{6}$-{10}^{6}$.) - 6: bu(n) – double array
- The fixed upper bounds u
_{j}${u}_{j}$.If ibound is set to 0$0$, you must set bu(j)${\mathbf{bu}}\left(\mathit{j}\right)$ to u_{j}${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., 10^{6}${10}^{6}$.) - 7: x(n) – double array
- 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_deriv_comp (e04kd) is called.
- 9: iw(liw) – int64int32nag_int array
- liw, the dimension of the array, must satisfy the constraint liw ≥ 2$\mathit{liw}\ge 2$.
*Constraint*: liw ≥ 2$\mathit{liw}\ge 2$. - 10: w(lw) – double array

- 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.- 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_deriv_comp (e04kd).
- 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 with iflag set to 2$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$1$) to evaluate only first derivatives.
- 4: xtol – double scalar
- The accuracy in x$x$ to which the solution is required.If x
_{true}${x}_{\mathrm{true}}$ is the true value of x$x$ at the minimum, then x_{sol}${x}_{\mathrm{sol}}$, the estimated position before a normal exit, is such that ‖x_{sol}− x_{true}‖ < xtol × (1.0 + ‖x_{true}‖)$\Vert {x}_{\mathrm{sol}}-{x}_{\mathrm{true}}\Vert <{\mathbf{xtol}}\times (1.0+\Vert {x}_{\mathrm{true}}\Vert )$ where ‖y‖ = sqrt( ∑_{j = 1}^{n}y_{j}^{2})$\Vert y\Vert =\sqrt{{\displaystyle \sum _{j=1}^{n}}{y}_{j}^{2}}$. For example, if the elements of x_{sol}${x}_{\mathrm{sol}}$ are not much larger than 1.0$1.0$ in modulus, and if xtol is set to 10^{ − 5}${10}^{-5}$, then x_{sol}${x}_{\mathrm{sol}}$ is usually accurate to about five decimal places. (For further details see Section [Accuracy].)If the problem is scaled as described in Section [Scaling] 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(ε)e_{j}) = F(x)$F(x+\sqrt{\epsilon}{e}_{j})=F\left(x\right)$, for any j$j$ where e_{j}${e}_{j}$ is the j$j$th 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_deriv_comp (e04kd) will use 10.0 × sqrt(ε)$10.0\times \sqrt{\epsilon}$ instead of xtol.*Default*: 0.0$0.0$ - 5: delta – double scalar
- The differencing interval to be used for approximating the second derivatives of F(x)$F\left(x\right)$. Thus, for the finite difference approximations, the first derivatives of F(x)$F\left(x\right)$ are evaluated at points which are delta apart. If ε$\epsilon $ is the machine precision, then sqrt(ε)$\sqrt{\epsilon}$ will usually be a suitable setting for delta. If you set delta to 0.0$0.0$ (or to any positive value less than ε$\epsilon $), nag_opt_bounds_mod_deriv_comp (e04kd) will automatically use sqrt(ε)$\sqrt{\epsilon}$ as the differencing interval.
*Default*: 0.0$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_deriv_comp (e04kd) will ensure that, for each iteration,where k$k$ is the iteration number. Thus, if the problem has more than one solution, nag_opt_bounds_mod_deriv_comp (e04kd) is most likely to find the one nearest to the starting point. On difficult problems, a realistic choice can prevent the sequence of x$$\sqrt{\sum _{j=1}^{n}{[{x}_{j}^{\left(k\right)}-{x}_{j}^{(k-1)}]}^{2}}\le {\mathbf{stepmx}}\text{,}$$
^{(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$

- liw lw

- 1: bl(n) – double array
- 2: bu(n) – double array
- 3: x(n) – double array
- 4: hesl(lh) – double array
- During the determination of a direction p
_{z}${p}_{z}$ (see Section [Description]), H + E$H+E$ is decomposed into the product LDL^{T}$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 n_{z}${n}_{z}$, where n_{z}${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 n_{z}(n_{z}− 1) / 2${n}_{z}({n}_{z}-1)/2$ positions of hesl. The diagonal elements of D$D$ are stored in the first n_{z}${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_deriv_comp (e04kd) (see Section [Accuracy]). - 5: hesd(n) – double array
- During the determination of a direction p
_{z}${p}_{z}$ (see Section [Description]), H + E$H+E$ is decomposed into the product LDL^{T}$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 n_{z}${n}_{z}$, where n_{z}${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 n_{z}(n_{z}− 1) / 2${n}_{z}({n}_{z}-1)/2$ positions of hesl. The diagonal elements of D$D$ are stored in the first n_{z}${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_deriv_comp (e04kd) (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$, x
_{j}${x}_{j}$ is fixed on its upper bound; - – equal to − 2$-2$, x
_{j}${x}_{j}$ is fixed on its lower bound; - – equal to − 3$-3$, x
_{j}${x}_{j}$ is effectively a constant (i.e., l_{j}= u_{j}${l}_{j}={u}_{j}$); - – positive, istate(j)${\mathbf{istate}}\left(j\right)$ gives the position of x
_{j}${x}_{j}$ in the sequence of free variables.

- – equal to − 1$-1$, x
- 7: f – double scalar
- The function value at the final point given in x.
- 8: g(n) – double array
- 9: iw(liw) – int64int32nag_int array
- liw ≥ 2$\mathit{liw}\ge 2$.Communication array, used to store information between calls to nag_opt_bounds_mod_deriv_comp (e04kd).
- 10: w(lw) – double array
- lw ≥ max (7 × n + n × (n − 1) / 2,8)$\mathit{lw}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}(7\times {\mathbf{n}}+{\mathbf{n}}\times ({\mathbf{n}}-1)/2,8)$.Communication array, used to store information between calls to nag_opt_bounds_mod_deriv_comp (e04kd).
- 11: ifail – int64int32nag_int scalar
- ifail = 0${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and 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$

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 delta < 0.0${\mathbf{delta}}<0.0$, or stepmx < xtol${\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}}(1,{\mathbf{n}}\times ({\mathbf{n}}-1)/2)$, 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}}(8,7\times {\mathbf{n}}+{\mathbf{n}}\times ({\mathbf{n}}-1)/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. 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.

- Not used. (This is done to make the significance of ifail = 5${\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 ifail = 3${\mathbf{ifail}}={\mathbf{3}}$.

The values ifail = 2${\mathbf{ifail}}={\mathbf{2}}$, 3${\mathbf{3}}$ or 5${\mathbf{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.

A successful exit (ifail = 0${\mathbf{ifail}}={\mathbf{0}}$) is made from nag_opt_bounds_mod_deriv_comp (e04kd) when H^{(k)}${H}^{\left(k\right)}$ is positive definite and when (B1, B2 and B3) or B4 hold, where

(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 ‖ . ‖$\Vert .\Vert $ denotes the Euclidean norm.)

$$\begin{array}{lll}\mathrm{B1}& \equiv & {\alpha}^{\left(k\right)}\times \Vert {p}^{\left(k\right)}\Vert <({\mathbf{xtol}}+\sqrt{\epsilon})\times (1.0+\Vert {x}^{\left(k\right)}\Vert )\\ \mathrm{B2}& \equiv & |{F}^{\left(k\right)}-{F}^{(k-1)}|<({{\mathbf{xtol}}}^{2}+\epsilon )\times (1.0+\left|{F}^{\left(k\right)}\right|)\\ \mathrm{B3}& \equiv & \Vert {g}_{z}^{\left(k\right)}\Vert <({\epsilon}^{1/3}+{\mathbf{xtol}})\times (1.0+\left|{F}^{\left(k\right)}\right|)\\ \mathrm{B4}& \equiv & \Vert {g}_{z}^{\left(k\right)}\Vert <0.01\times \sqrt{\epsilon}\text{.}\end{array}$$ |

If ifail = 0${\mathbf{ifail}}={\mathbf{0}}$, then the vector in x on exit, x_{sol}${x}_{\mathrm{sol}}$, is almost certainly an estimate of the position of the minimum, x_{true}${x}_{\mathrm{true}}$, to the accuracy specified by xtol.

If ifail = 3${\mathbf{ifail}}={\mathbf{3}}$ or 5${\mathbf{5}}$, x_{sol}${x}_{\mathrm{sol}}$ may still be a good estimate of x_{true}${x}_{\mathrm{true}}$, but the following checks should be made. Let the largest of the first n_{z}${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 x_{sol}${x}_{\mathrm{sol}}$. If

then it is almost certain that x_{sol}${x}_{\mathrm{sol}}$ is a close approximation to the position of a minimum. When (ii) is true, then usually F(x_{sol})$F\left({x}_{\mathrm{sol}}\right)$ is a close approximation to F(x_{true})$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$

(i) | the sequence {F(x^{(k)})}$\left\{F\left({x}^{\left(k\right)}\right)\right\}$ converges to F(x_{sol})$F\left({x}_{\mathrm{sol}}\right)$ at a superlinear or fast linear rate, |

(ii) | ‖g_{z}(x_{sol})‖^{2} < 10.0 × ε${\Vert {g}_{z}\left({x}_{\mathrm{sol}}\right)\Vert}^{2}<10.0\times \epsilon $, and |

(iii) | k < 1.0 / ‖g_{z}(x_{sol})‖$k<1.0/\Vert {g}_{z}\left({x}_{\mathrm{sol}}\right)\Vert $, |

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(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_deriv_comp (e04kd) is
(n_{z}^{3})/6 + O(n_{z}^{2})$\frac{{n}_{z}^{3}}{6}+\mathit{O}\left({n}_{z}^{2}\right)$. In addition, each iteration makes n_{z}${n}_{z}$ calls of funct (with iflag set to 1$1$) in approximating the projected Hessian matrix, and at least one other call of funct (with iflag set to 2$2$). So, unless F(x)$F\left(x\right)$ and its first derivatives can be evaluated very quickly, the run time will be dominated by the time spent in funct.

Ideally, the problem should be scaled so that, at the solution, F(x)$F\left(x\right)$ and the corresponding values of x_{j}${x}_{j}$ are each in the range ( − 1, + 1)$(-1,+1)$, 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_deriv_comp (e04kd) will take less computer time.

If a problem is genuinely unconstrained and has been scaled sensibly, the following points apply:

(a) | n_{z}${n}_{z}$ will always be n$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$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_deriv_comp (e04kd) are unlikely to be of interest (unless they are negative, which would indicate that the modulus of one of the x_{j}${x}_{j}$ has reached 10^{6}${10}^{6}$ for some reason), |

(e) | monit's parameter gpjnrm simply gives the norm of the first derivative vector. |

Open in the MATLAB editor: nag_opt_bounds_mod_deriv_comp_example

function nag_opt_bounds_mod_deriv_comp_exampleeta = 0.5; 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_deriv_comp(@funct, @monit, eta, ibound, bl, bu, x, lh, iw, w)function [iflag, fc, gc] = funct(iflag, n, xc)gc = zeros(n, 1); fc = 0; if (iflag ~= 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; end 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 [] = 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 functions % 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_deriv_comp (e04kd) 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.3803
45.5183
0
istate =
-2
1
2
-2
f =
2.4338
g =
0.2953
-0.0000
0.0000
5.9070
iwOut =
-1
3
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
0
209.8031
49.2125
0
20.0000
0
-19.6062
0
0
-10.0000
ifail =
3
```

Open in the MATLAB editor: e04kd_example

function e04kd_exampleeta = 0.5; 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] = ... e04kd(@funct, @monit, eta, ibound, bl, bu, x, lh, iw, w)function [iflag, fc, gc] = funct(iflag, n, xc)gc = zeros(n, 1); fc = 0; if (iflag ~= 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; end 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 [] = 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 functions % e04kd or e04lb 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_deriv_comp (e04kd) 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.3803
45.5183
0
istate =
-2
1
2
-2
f =
2.4338
g =
0.2953
-0.0000
0.0000
5.9070
iwOut =
-1
3
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
0
209.8031
49.2125
0
20.0000
0
-19.6062
0
0
-10.0000
ifail =
3
```

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013