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_lsq_gencon_deriv (e04us)

## Purpose

nag_opt_lsq_gencon_deriv (e04us) is designed to minimize an arbitrary smooth sum of squares function subject to constraints (which may include simple bounds on the variables, linear constraints and smooth nonlinear constraints) using a sequential quadratic programming (SQP) method. As many first derivatives as possible should be supplied by you; any unspecified derivatives are approximated by finite differences. See the description of the optional parameter Derivative Level, in Section [Description of the optional parameters]. It is not intended for large sparse problems.
nag_opt_lsq_gencon_deriv (e04us) may also be used for unconstrained, bound-constrained and linearly constrained optimization.

## Syntax

[iter, istate, c, cjac, f, fjac, clamda, objf, r, x, user, lwsav, iwsav, rwsav, ifail] = e04us(a, bl, bu, y, confun, objfun, istate, cjac, fjac, clamda, r, x, lwsav, iwsav, rwsav, 'm', m, 'n', n, 'nclin', nclin, 'ncnln', ncnln, 'user', user)
[iter, istate, c, cjac, f, fjac, clamda, objf, r, x, user, lwsav, iwsav, rwsav, ifail] = nag_opt_lsq_gencon_deriv(a, bl, bu, y, confun, objfun, istate, cjac, fjac, clamda, r, x, lwsav, iwsav, rwsav, 'm', m, 'n', n, 'nclin', nclin, 'ncnln', ncnln, 'user', user)
Before calling nag_opt_lsq_gencon_deriv (e04us), or the option setting function (e04ur), nag_opt_init (e04wb) must be called.

## Description

nag_opt_lsq_gencon_deriv (e04us) is designed to solve the nonlinear least squares programming problem – the minimization of a smooth nonlinear sum of squares function subject to a set of constraints on the variables. The problem is assumed to be stated in the following form:
m
minimize F(x) = (1/2) (yifi(x)) 2  subject to  l{
 x ALx c(x)
}
u,
xRn i = 1
$minimize x∈Rn F(x) = 12 ∑ i=1 m ( yi- fi (x) ) 2 subject to l≤ { x ALx c(x) } ≤u,$
(1)
where F(x)$F\left(x\right)$ (the objective function) is a nonlinear function which can be represented as the sum of squares of m$m$ subfunctions (y1f1(x)),(y2f2(x)),,(ymfm(x))$\left({y}_{1}-{f}_{1}\left(x\right)\right),\left({y}_{2}-{f}_{2}\left(x\right)\right),\dots ,\left({y}_{m}-{f}_{m}\left(x\right)\right)$, the yi${y}_{i}$ are constant, AL${A}_{L}$ is an nL${n}_{L}$ by n$n$ constant matrix, and c(x)$c\left(x\right)$ is an nN${n}_{N}$ element vector of nonlinear constraint functions. (The matrix AL${A}_{L}$ and the vector c(x)$c\left(x\right)$ may be empty.) The objective function and the constraint functions are assumed to be smooth, i.e., at least twice-continuously differentiable. (The method of nag_opt_lsq_gencon_deriv (e04us) will usually solve (1) if any isolated discontinuities are away from the solution.)
Note that although the bounds on the variables could be included in the definition of the linear constraints, we prefer to distinguish between them for reasons of computational efficiency. For the same reason, the linear constraints should not be included in the definition of the nonlinear constraints. Upper and lower bounds are specified for all the variables and for all the constraints. An equality constraint can be specified by setting li = ui${l}_{i}={u}_{i}$. If certain bounds are not present, the associated elements of l$l$ or u$u$ can be set to special values that will be treated as $-\infty$ or + $+\infty$. (See the description of the optional parameter Infinite Bound Size.)
You must supply an initial estimate of the solution to (1), together with functions that define f(x) = (f1(x),f2(x),,fm(x))T $f\left(x\right)={\left({f}_{1}\left(x\right),{f}_{2}\left(x\right),\dots ,{f}_{m}\left(x\right)\right)}^{\mathrm{T}}$, c(x)$c\left(x\right)$ and as many first partial derivatives as possible; unspecified derivatives are approximated by finite differences.
The subfunctions are defined by the array y and objfun, and the nonlinear constraints are defined by confun. On every call, these functions must return appropriate values of f(x)$f\left(x\right)$ and c(x)$c\left(x\right)$. You should also provide the available partial derivatives. Any unspecified derivatives are approximated by finite differences for a discussion of the optional parameter Derivative Level. Note that if there are any nonlinear constraints, then the first call to confun will precede the first call to objfun.
For maximum reliability, it is preferable for you to provide all partial derivatives (see Chapter 8 of Gill et al. (1981) for a detailed discussion). If all gradients cannot be provided, it is similarly advisable to provide as many as possible. While developing objfun and confun, the optional parameter Verify should be used to check the calculation of any known gradients.

## References

Gill P E, Murray W and Wright M H (1981) Practical Optimization Academic Press
Hock W and Schittkowski K (1981) Test Examples for Nonlinear Programming Codes. Lecture Notes in Economics and Mathematical Systems 187 Springer–Verlag

## Parameters

### Compulsory Input Parameters

1:     a(lda, : $:$) – double array
The first dimension of the array a must be at least max (1,nclin)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nclin}}\right)$
The second dimension of the array must be at least n${\mathbf{n}}$ if nclin > 0${\mathbf{nclin}}>0$, and at least 1$1$ otherwise
The i$\mathit{i}$th row of a contains the i$\mathit{i}$th row of the matrix AL${A}_{L}$ of general linear constraints in (1). That is, the i$\mathit{i}$th row contains the coefficients of the i$\mathit{i}$th general linear constraint, for i = 1,2,,nclin$\mathit{i}=1,2,\dots ,{\mathbf{nclin}}$.
If nclin = 0${\mathbf{nclin}}=0$, the array a is not referenced.
2:     bl(${\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}$) – double array
3:     bu(${\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}$) – double array
Must contain the lower bounds and bu the upper bounds, for all the constraints in the following order. The first n$n$ elements of each array must contain the bounds on the variables, the next nL${n}_{L}$ elements the bounds for the general linear constraints (if any) and the next nN${n}_{N}$ elements the bounds for the general nonlinear constraints (if any). To specify a nonexistent lower bound (i.e., lj = ${l}_{j}=-\infty$), set bl(j)bigbnd${\mathbf{bl}}\left(j\right)\le -\mathit{bigbnd}$, and to specify a nonexistent upper bound (i.e., uj = + ${u}_{j}=+\infty$), set bu(j)bigbnd${\mathbf{bu}}\left(j\right)\ge \mathit{bigbnd}$; the default value of bigbnd$\mathit{bigbnd}$ is 1020${10}^{20}$, but this may be changed by the optional parameter Infinite Bound Size. To specify the j$j$th constraint as an equality, set bl(j) = bu(j) = β${\mathbf{bl}}\left(j\right)={\mathbf{bu}}\left(j\right)=\beta$, say, where |β| < bigbnd$|\beta |<\mathit{bigbnd}$.
Constraints:
• bl(j)bu(j)${\mathbf{bl}}\left(\mathit{j}\right)\le {\mathbf{bu}}\left(\mathit{j}\right)$, for j = 1,2,,n + nclin + ncnln$\mathit{j}=1,2,\dots ,{\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}$;
• if bl(j) = bu(j) = β${\mathbf{bl}}\left(j\right)={\mathbf{bu}}\left(j\right)=\beta$, |β| < bigbnd$|\beta |<\mathit{bigbnd}$.
4:     y(m) – double array
m, the dimension of the array, must satisfy the constraint m > 0${\mathbf{m}}>0$.
The coefficients of the constant vector y$y$ of the objective function.
5:     confun – function handle or string containing name of m-file
confun must calculate the vector c(x)$c\left(x\right)$ of nonlinear constraint functions and (optionally) its Jacobian ( = (c)/(x) $\text{}=\frac{\partial c}{\partial x}$) for a specified n$n$-element vector x$x$. If there are no nonlinear constraints (i.e., ncnln = 0${\mathbf{ncnln}}=0$), confun will never be called by nag_opt_lsq_gencon_deriv (e04us) and confun may be the string 'e04udm'. (nag_opt_nlp1_dummy_confun (e04udm) is included in the NAG Toolbox.) If there are nonlinear constraints, the first call to confun will occur before the first call to objfun.
[mode, c, cjac, user] = confun(mode, ncnln, n, ldcj, needc, x, cjac, nstate, user)

Input Parameters

1:     mode – int64int32nag_int scalar
Indicates which values must be assigned during each call of confun. Only the following values need be assigned, for each value of i$i$ such that needc(i) > 0${\mathbf{needc}}\left(i\right)>0$:
mode = 0${\mathbf{mode}}=0$
c(i)${\mathbf{c}}\left(i\right)$.
mode = 1${\mathbf{mode}}=1$
All available elements in the i$i$th row of cjac.
mode = 2${\mathbf{mode}}=2$
c(i)${\mathbf{c}}\left(i\right)$ and all available elements in the i$i$th row of cjac.
2:     ncnln – int64int32nag_int scalar
nN${n}_{N}$, the number of nonlinear constraints.
3:     n – int64int32nag_int scalar
n$n$, the number of variables.
4:     ldcj – int64int32nag_int scalar
The first dimension of the array cjac as declared in the (sub)program from which nag_opt_lsq_gencon_deriv (e04us) is called.
5:     needc(ncnln) – int64int32nag_int array
The indices of the elements of c and/or cjac that must be evaluated by confun. If needc(i) > 0${\mathbf{needc}}\left(i\right)>0$, then the i$i$th element of c and/or the available elements of the i$i$th row of cjac (see parameter mode) must be evaluated at x$x$.
6:     x(n) – double array
x$x$, the vector of variables at which the constraint functions and/or all available elements of the constraint Jacobian are to be evaluated.
7:     cjac(ldcj,n) – double array
Is set to a special value.
8:     nstate – int64int32nag_int scalar
If nstate = 1${\mathbf{nstate}}=1$ then nag_opt_lsq_gencon_deriv (e04us) is calling confun for the first time. This parameter setting allows you to save computation time if certain data must be read or calculated only once.
9:     user – Any MATLAB object
confun is called from nag_opt_lsq_gencon_deriv (e04us) with the object supplied to nag_opt_lsq_gencon_deriv (e04us).

Output Parameters

1:     mode – int64int32nag_int scalar
May be set to a negative value if you wish to terminate the solution to the current problem, and in this case nag_opt_lsq_gencon_deriv (e04us) will terminate with ifail set to mode.
2:     c(ncnln) – double array
If needc(i) > 0${\mathbf{needc}}\left(i\right)>0$ and mode = 0${\mathbf{mode}}=0$ or 2$2$, c(i)${\mathbf{c}}\left(i\right)$ must contain the value of the i$i$th constraint at x$x$. The remaining elements of c, corresponding to the non-positive elements of needc, are ignored.
3:     cjac(ldcj,n) – double array
ldcjmax (1,ncnln)$\mathit{ldcj}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncnln}}\right)$.
If needc(i) > 0${\mathbf{needc}}\left(i\right)>0$ and mode = 1${\mathbf{mode}}=1$ or 2$2$, the i$i$th row of cjac must contain the available elements of the vector ci$\nabla {c}_{i}$ given by
 ∇ci = (( ∂ ci)/( ∂ x1),( ∂ ci)/( ∂ x2), … ,( ∂ ci)/( ∂ xn))T, $∇ci=( ∂ci ∂x1 , ∂ci ∂x2 ,…, ∂ci ∂xn )T,$
where (ci)/(xj) $\frac{\partial {c}_{i}}{\partial {x}_{j}}$ is the partial derivative of the i$i$th constraint with respect to the j$j$th variable, evaluated at the point x$x$. See also the parameter nstate. The remaining rows of cjac, corresponding to non-positive elements of needc, are ignored.
If all elements of the constraint Jacobian are known (i.e., ${\mathbf{Derivative Level}}=2$ or 3$3$), any constant elements may be assigned to cjac one time only at the start of the optimization. An element of cjac that is not subsequently assigned in confun will retain its initial value throughout. Constant elements may be loaded into cjac either before the call to nag_opt_lsq_gencon_deriv (e04us) or during the first call to confun (signalled by the value nstate = 1${\mathbf{nstate}}=1$). The ability to preload constants is useful when many Jacobian elements are identically zero, in which case cjac may be initialized to zero and nonzero elements may be reset by confun.
Note that constant nonzero elements do affect the values of the constraints. Thus, if cjac(i,j)${\mathbf{cjac}}\left(i,j\right)$ is set to a constant value, it need not be reset in subsequent calls to confun, but the value cjac(i,j) × x(j)${\mathbf{cjac}}\left(i,j\right)×{\mathbf{x}}\left(j\right)$ must nonetheless be added to c(i)${\mathbf{c}}\left(i\right)$. For example, if cjac(1,1) = 2${\mathbf{cjac}}\left(1,1\right)=2$ and cjac(1,2) = 5${\mathbf{cjac}}\left(1,2\right)=-5$, then the term 2 × x(1)5 × x(2)$2×{\mathbf{x}}\left(1\right)-5×{\mathbf{x}}\left(2\right)$ must be included in the definition of c(1)${\mathbf{c}}\left(1\right)$.
It must be emphasized that, if ${\mathbf{Derivative Level}}=0$ or 1$1$, unassigned elements of cjac are not treated as constant; they are estimated by finite differences, at nontrivial expense. If you do not supply a value for the optional parameter Difference Interval, an interval for each element of x$x$ is computed automatically at the start of the optimization. The automatic procedure can usually identify constant elements of cjac, which are then computed once only by finite differences.
4:     user – Any MATLAB object
Note:  confun should be tested separately before being used in conjunction with nag_opt_lsq_gencon_deriv (e04us). See also the description of the optional parameter Verify.
6:     objfun – function handle or string containing name of m-file
objfun must calculate either the i$i$th element of the vector f(x) = (f1(x),f2(x),,fm(x))T $f\left(x\right)={\left({f}_{1}\left(x\right),{f}_{2}\left(x\right),\dots ,{f}_{m}\left(x\right)\right)}^{\mathrm{T}}$ or all m$m$ elements of f(x)$f\left(x\right)$ and (optionally) its Jacobian ( = (f)/(x) $\text{}=\frac{\partial f}{\partial x}$) for a specified n$n$-element vector x$x$.
[mode, f, fjac, user] = objfun(mode, m, n, ldfj, needfi, x, fjac, nstate, user)

Input Parameters

1:     mode – int64int32nag_int scalar
Indicates which values must be assigned during each call of objfun. Only the following values need be assigned:
mode = 0${\mathbf{mode}}=0$ and needfi = i${\mathbf{needfi}}=i$, where i > 0$i>0$
f(i)${\mathbf{f}}\left(i\right)$.
mode = 0${\mathbf{mode}}=0$ and needfi < 0${\mathbf{needfi}}<0$
f.
mode = 1${\mathbf{mode}}=1$ and needfi < 0${\mathbf{needfi}}<0$
All available elements of fjac.
mode = 2${\mathbf{mode}}=2$ and needfi < 0${\mathbf{needfi}}<0$
f and all available elements of fjac.
2:     m – int64int32nag_int scalar
m$m$, the number of subfunctions.
3:     n – int64int32nag_int scalar
n$n$, the number of variables.
4:     ldfj – int64int32nag_int scalar
The first dimension of the array fjac as declared in the (sub)program from which nag_opt_lsq_gencon_deriv (e04us) is called.
5:     needfi – int64int32nag_int scalar
If needfi = i > 0${\mathbf{needfi}}=i>0$, only the i$i$th element of f(x)$f\left(x\right)$ needs to be evaluated at x$x$; the remaining elements need not be set. This can result in significant computational savings when mn$m\gg n$.
6:     x(n) – double array
x$x$, the vector of variables at which f(x)$f\left(x\right)$ and/or all available elements of its Jacobian are to be evaluated.
7:     fjac(ldfj,n) – double array
Is set to a special value.
8:     nstate – int64int32nag_int scalar
If nstate = 1${\mathbf{nstate}}=1$ then nag_opt_lsq_gencon_deriv (e04us) is calling objfun for the first time. This parameter setting allows you to save computation time if certain data must be read or calculated only once.
9:     user – Any MATLAB object
objfun is called from nag_opt_lsq_gencon_deriv (e04us) with the object supplied to nag_opt_lsq_gencon_deriv (e04us).

Output Parameters

1:     mode – int64int32nag_int scalar
May be set to a negative value if you wish to terminate the solution to the current problem, and in this case nag_opt_lsq_gencon_deriv (e04us) will terminate with ifail set to mode.
2:     f(m) – double array
If mode = 0${\mathbf{mode}}=0$ and needfi = i > 0${\mathbf{needfi}}=i>0$, f(i)${\mathbf{f}}\left(i\right)$ must contain the value of fi${f}_{i}$ at x$x$.
If mode = 0${\mathbf{mode}}=0$ or 2$2$ and needfi < 0${\mathbf{needfi}}<0$, f(i)${\mathbf{f}}\left(\mathit{i}\right)$ must contain the value of fi${f}_{\mathit{i}}$ at x$x$, for i = 1,2,,m$\mathit{i}=1,2,\dots ,m$.
3:     fjac(ldfj,n) – double array
ldfjm$\mathit{ldfj}\ge {\mathbf{m}}$.
If mode = 1${\mathbf{mode}}=1$ or 2$2$ and needfi < 0${\mathbf{needfi}}<0$, the i$i$th row of fjac must contain the available elements of the vector fi$\nabla {f}_{i}$ given by
 ∇fi = (( ∂ fi)/( ∂ x1),( ∂ fi)/( ∂ x2), … ,( ∂ fi)/( ∂ xn))T, $∇fi=( ∂fi ∂x1 , ∂fi ∂x2 ,…, ∂fi ∂xn )T,$
evaluated at the point x$x$. See also the parameter nstate.
4:     user – Any MATLAB object
Note:  objfun should be tested separately before being used in conjunction with nag_opt_lsq_gencon_deriv (e04us). See also the description of the optional parameter Verify.
7:     istate(${\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}$) – int64int32nag_int array
Need not be set if the (default) optional parameter Cold Start is used.
If the optional parameter Warm Start has been chosen, the elements of istate corresponding to the bounds and linear constraints define the initial working set for the procedure that finds a feasible point for the linear constraints and bounds. The active set at the conclusion of this procedure and the elements of istate corresponding to nonlinear constraints then define the initial working set for the first QP subproblem. More precisely, the first n$n$ elements of istate refer to the upper and lower bounds on the variables, the next nL${n}_{L}$ elements refer to the upper and lower bounds on ALx${A}_{L}x$, and the next nN${n}_{N}$ elements refer to the upper and lower bounds on c(x)$c\left(x\right)$. Possible values for istate(j)${\mathbf{istate}}\left(j\right)$ are as follows:
 istate(j)${\mathbf{istate}}\left(j\right)$ Meaning 0 The corresponding constraint is not in the initial QP working set. 1 This inequality constraint should be in the working set at its lower bound. 2 This inequality constraint should be in the working set at its upper bound. 3 This equality constraint should be in the initial working set. This value must not be specified unless bl(j) = bu(j)${\mathbf{bl}}\left(j\right)={\mathbf{bu}}\left(j\right)$.
The values 2$-2$, 1$-1$ and 4$4$ are also acceptable but will be modified by the function. If nag_opt_lsq_gencon_deriv (e04us) has been called previously with the same values of n, nclin and ncnln, istate already contains satisfactory information. (See also the description of the optional parameter Warm Start.) The function also adjusts (if necessary) the values supplied in x to be consistent with istate.
Constraint: 2istate(j)4$-2\le {\mathbf{istate}}\left(\mathit{j}\right)\le 4$, for j = 1,2,,n + nclin + ncnln$\mathit{j}=1,2,\dots ,{\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}$.
8:     cjac(ldcj, : $:$) – double array
The first dimension of the array cjac must be at least max (1,ncnln)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncnln}}\right)$
The second dimension of the array must be at least n${\mathbf{n}}$ if ncnln > 0${\mathbf{ncnln}}>0$, and at least 1$1$ otherwise
In general, cjac need not be initialized before the call to nag_opt_lsq_gencon_deriv (e04us). However, if ${\mathbf{Derivative Level}}=3$, you may optionally set the constant elements of cjac (see parameter nstate in the description of confun). Such constant elements need not be re-assigned on subsequent calls to confun.
9:     fjac(ldfj,n) – double array
ldfj, the first dimension of the array, must satisfy the constraint ldfjm$\mathit{ldfj}\ge {\mathbf{m}}$.
In general, fjac need not be initialized before the call to nag_opt_lsq_gencon_deriv (e04us). However, if ${\mathbf{Derivative Level}}=3$, you may optionally set the constant elements of fjac (see parameter nstate in the description of objfun). Such constant elements need not be re-assigned on subsequent calls to objfun.
10:   clamda(${\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}$) – double array
Need not be set if the (default) optional parameter Cold Start is used.
If the optional parameter Warm Start has been chosen, clamda(j)${\mathbf{clamda}}\left(\mathit{j}\right)$ must contain a multiplier estimate for each nonlinear constraint with a sign that matches the status of the constraint specified by the istate array, for j = n + nclin + 1,,n + nclin + ncnln$\mathit{j}={\mathbf{n}}+{\mathbf{nclin}}+1,\dots ,{\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}$. The remaining elements need not be set. Note that if the j$j$th constraint is defined as ‘inactive’ by the initial value of the istate array (i.e., istate(j) = 0${\mathbf{istate}}\left(j\right)=0$), clamda(j)${\mathbf{clamda}}\left(j\right)$ should be zero; if the j$j$th constraint is an inequality active at its lower bound (i.e., istate(j) = 1${\mathbf{istate}}\left(j\right)=1$), clamda(j)${\mathbf{clamda}}\left(j\right)$ should be non-negative; if the j$j$th constraint is an inequality active at its upper bound (i.e., istate(j) = 2${\mathbf{istate}}\left(j\right)=2$, clamda(j)${\mathbf{clamda}}\left(j\right)$ should be non-positive. If necessary, the function will modify clamda to match these rules.
11:   r(ldr,n) – double array
ldr, the first dimension of the array, must satisfy the constraint ldrn$\mathit{ldr}\ge {\mathbf{n}}$.
Need not be initialized if the (default) optional parameter Cold Start is used.
If the optional parameter Warm Start has been chosen, r must contain the upper triangular Cholesky factor R $R$ of the initial approximation of the Hessian of the Lagrangian function, with the variables in the natural order. Elements not in the upper triangular part of r are assumed to be zero and need not be assigned.
12:   x(n) – double array
n, the dimension of the array, must satisfy the constraint n > 0${\mathbf{n}}>0$.
An initial estimate of the solution.
13:   lwsav(120$120$) – logical array
14:   iwsav(610$610$) – int64int32nag_int array
15:   rwsav(475$475$) – double array
The arrays lwsav, iwsav and rwsav must not be altered between calls to any of the functions nag_opt_lsq_gencon_deriv (e04us), (e04uq) or (e04ur).

### Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The dimension of the array y and the first dimension of the array fjac. (An error is raised if these dimensions are not equal.)
m$m$, the number of subfunctions associated with F(x)$F\left(x\right)$.
Constraint: m > 0${\mathbf{m}}>0$.
2:     n – int64int32nag_int scalar
Default: The dimension of the array x and the first dimension of the array r and the second dimension of the arrays a, cjac, fjac, r. (An error is raised if these dimensions are not equal.)
n$n$, the number of variables.
Constraint: n > 0${\mathbf{n}}>0$.
3:     nclin – int64int32nag_int scalar
Default: The first dimension of the array a.
nL${n}_{L}$, the number of general linear constraints.
Constraint: nclin0${\mathbf{nclin}}\ge 0$.
4:     ncnln – int64int32nag_int scalar
Default: The first dimension of the array cjac.
nN${n}_{N}$, the number of nonlinear constraints.
Constraint: ncnln0${\mathbf{ncnln}}\ge 0$.
5:     user – Any MATLAB object
user is not used by nag_opt_lsq_gencon_deriv (e04us), but is passed to confun and objfun. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files than to use user.

### Input Parameters Omitted from the MATLAB Interface

lda ldcj ldfj ldr iwork liwork work lwork iuser ruser

### Output Parameters

1:     iter – int64int32nag_int scalar
The number of major iterations performed.
2:     istate(${\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}$) – int64int32nag_int array
The status of the constraints in the QP working set at the point returned in x. The significance of each possible value of istate(j)${\mathbf{istate}}\left(j\right)$ is as follows:
 istate(j)${\mathbf{istate}}\left(j\right)$ Meaning − 2$-2$ This constraint violates its lower bound by more than the appropriate feasibility tolerance (see the optional parameters Linear Feasibility Tolerance and Nonlinear Feasibility Tolerance). This value can occur only when no feasible point can be found for a QP subproblem. − 1$-1$ This constraint violates its upper bound by more than the appropriate feasibility tolerance (see the optional parameters Linear Feasibility Tolerance and Nonlinear Feasibility Tolerance). This value can occur only when no feasible point can be found for a QP subproblem. − 0$\phantom{-}0$ The constraint is satisfied to within the feasibility tolerance, but is not in the QP working set. − 1$\phantom{-}1$ This inequality constraint is included in the QP working set at its lower bound. − 2$\phantom{-}2$ This inequality constraint is included in the QP working set at its upper bound. − 3$\phantom{-}3$ This constraint is included in the QP working set as an equality. This value of istate can occur only when bl(j) = bu(j)${\mathbf{bl}}\left(j\right)={\mathbf{bu}}\left(j\right)$.
3:     c(max (1,ncnln)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncnln}}\right)$) – double array
If ncnln > 0${\mathbf{ncnln}}>0$, c(i)${\mathbf{c}}\left(\mathit{i}\right)$ contains the value of the i$\mathit{i}$th nonlinear constraint function ci${c}_{\mathit{i}}$ at the final iterate, for i = 1,2,,ncnln$\mathit{i}=1,2,\dots ,{\mathbf{ncnln}}$.
If ncnln = 0${\mathbf{ncnln}}=0$, the array c is not referenced.
4:     cjac(ldcj, : $:$) – double array
The first dimension of the array cjac will be max (1,ncnln)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncnln}}\right)$
The second dimension of the array will be n${\mathbf{n}}$ if ncnln > 0${\mathbf{ncnln}}>0$, and at least 1$1$ otherwise
ldcjmax (1,ncnln)$\mathit{ldcj}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncnln}}\right)$.
If ncnln > 0${\mathbf{ncnln}}>0$, cjac contains the Jacobian matrix of the nonlinear constraint functions at the final iterate, i.e., cjac(i,j)${\mathbf{cjac}}\left(\mathit{i},\mathit{j}\right)$ contains the partial derivative of the i$\mathit{i}$th constraint function with respect to the j$\mathit{j}$th variable, for i = 1,2,,ncnln$\mathit{i}=1,2,\dots ,{\mathbf{ncnln}}$ and j = 1,2,,n$\mathit{j}=1,2,\dots ,{\mathbf{n}}$. (See the discussion of parameter cjac under confun.)
If ncnln = 0${\mathbf{ncnln}}=0$, the array cjac is not referenced.
5:     f(m) – double array
f(i)${\mathbf{f}}\left(\mathit{i}\right)$ contains the value of the i$\mathit{i}$th function fi${f}_{\mathit{i}}$ at the final iterate, for i = 1,2,,m$\mathit{i}=1,2,\dots ,{\mathbf{m}}$.
6:     fjac(ldfj,n) – double array
ldfjm$\mathit{ldfj}\ge {\mathbf{m}}$.
The Jacobian matrix of the functions f1,f2,,fm${f}_{1},{f}_{2},\dots ,{f}_{m}$ at the final iterate, i.e., fjac(i,j)${\mathbf{fjac}}\left(\mathit{i},\mathit{j}\right)$ contains the partial derivative of the i$\mathit{i}$th function with respect to the j$\mathit{j}$th variable, for i = 1,2,,m$\mathit{i}=1,2,\dots ,{\mathbf{m}}$ and j = 1,2,,n$\mathit{j}=1,2,\dots ,{\mathbf{n}}$. (See also the discussion of parameter fjac under objfun.)
7:     clamda(${\mathbf{n}}+{\mathbf{nclin}}+{\mathbf{ncnln}}$) – double array
The values of the QP multipliers from the last QP subproblem. clamda(j)${\mathbf{clamda}}\left(j\right)$ should be non-negative if istate(j) = 1${\mathbf{istate}}\left(j\right)=1$ and non-positive if istate(j) = 2${\mathbf{istate}}\left(j\right)=2$.
8:     objf – double scalar
The value of the objective function at the final iterate.
9:     r(ldr,n) – double array
ldrn$\mathit{ldr}\ge {\mathbf{n}}$.
If Hessian = NO${\mathbf{Hessian}}=\mathrm{NO}$, r contains the upper triangular Cholesky factor R $R$ of QTQ${Q}^{\mathrm{T}}\stackrel{~}{H}Q$, an estimate of the transformed and reordered Hessian of the Lagrangian at x$x$ (see (6) in (e04uf)). If Hessian = YES${\mathbf{Hessian}}=\mathrm{YES}$, r contains the upper triangular Cholesky factor R $R$ of H$H$, the approximate (untransformed) Hessian of the Lagrangian, with the variables in the natural order.
10:   x(n) – double array
The final estimate of the solution.
11:   user – Any MATLAB object
12:   lwsav(120$120$) – logical array
13:   iwsav(610$610$) – int64int32nag_int array
14:   rwsav(475$475$) – double array
15:   ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).
nag_opt_lsq_gencon_deriv (e04us) returns with ${\mathbf{ifail}}={\mathbf{0}}$ if the iterates have converged to a point x$x$ that satisfies the first-order Kuhn–Tucker conditions (see Section [Overview] in (e04uf)) to the accuracy requested by the optional parameter Optimality Tolerance (default value = εr0.8$\text{default value}={\epsilon }_{r}^{0.8}$, where εr${\epsilon }_{r}$ is the value of the optional parameter Function Precision (default value = ε0.9$\text{default value}={\epsilon }^{0.9}$, where ε$\epsilon$ is the machine precision)), i.e., the projected gradient and active constraint residuals are negligible at x$x$.
You should check whether the following four conditions are satisfied:
 (i) the final value of Norm Gz (see Section [Description of Printed output]) is significantly less than that at the starting point; (ii) during the final major iterations, the values of Step and Mnr (see Section [Description of Printed output]) are both one; (iii) the last few values of both Norm Gz and Violtn (see Section [Description of Printed output]) become small at a fast linear rate; and (iv) Cond Hz (see Section [Description of Printed output]) is small.
If all these conditions hold, x$x$ is almost certainly a local minimum of (1).

## Error Indicators and Warnings

Note: nag_opt_lsq_gencon_deriv (e04us) 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_lsq_gencon_deriv (e04us) because you set mode < 0${\mathbf{mode}}<0$ in objfun or confun. The value of ifail will be the same as your setting of mode.
W ifail = 1${\mathbf{ifail}}=1$
The final iterate x$x$ satisfies the first-order Kuhn–Tucker conditions (see Section [Overview] in (e04uf)) to the accuracy requested, but the sequence of iterates has not yet converged. nag_opt_lsq_gencon_deriv (e04us) was terminated because no further improvement could be made in the merit function (see Section [Description of Printed output]).
This value of ifail may occur in several circumstances. The most common situation is that you ask for a solution with accuracy that is not attainable with the given precision of the problem (as specified by the optional parameter Function Precision (default value = ε0.9$\text{default value}={\epsilon }^{0.9}$, where ε$\epsilon$ is the machine precision)). This condition will also occur if, by chance, an iterate is an ‘exact’ Kuhn–Tucker point, but the change in the variables was significant at the previous iteration. (This situation often happens when minimizing very simple functions, such as quadratics.)
If the four conditions listed in Section [Parameters] for ${\mathbf{ifail}}={\mathbf{0}}$ are satisfied, x$x$ is likely to be a solution of (1) even if ${\mathbf{ifail}}={\mathbf{1}}$.
W ifail = 2${\mathbf{ifail}}=2$
nag_opt_lsq_gencon_deriv (e04us) has terminated without finding a feasible point for the linear constraints and bounds, which means that either no feasible point exists for the given value of the optional parameter Linear Feasibility Tolerance (default value = sqrt(ε)$\text{default value}=\sqrt{\epsilon }$, where ε$\epsilon$ is the machine precision), or no feasible point could be found in the number of iterations specified by the optional parameter Minor Iteration Limit (default value = max (50,3(n + nL + nN))$\text{default value}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,3\left(n+{n}_{L}+{n}_{N}\right)\right)$). You should check that there are no constraint redundancies. If the data for the constraints are accurate only to an absolute precision σ$\sigma$, you should ensure that the value of the optional parameter Linear Feasibility Tolerance is greater than σ$\sigma$. For example, if all elements of AL${A}_{L}$ are of order unity and are accurate to only three decimal places, Linear Feasibility Tolerance should be at least 103${10}^{-3}$.
W ifail = 3${\mathbf{ifail}}=3$
No feasible point could be found for the nonlinear constraints. The problem may have no feasible solution. This means that there has been a sequence of QP subproblems for which no feasible point could be found (indicated by I at the end of each line of intermediate printout produced by the major iterations; see Section [Description of Printed output]). This behaviour will occur if there is no feasible point for the nonlinear constraints. (However, there is no general test that can determine whether a feasible point exists for a set of nonlinear constraints.) If the infeasible subproblems occur from the very first major iteration, it is highly likely that no feasible point exists. If infeasibilities occur when earlier subproblems have been feasible, small constraint inconsistencies may be present. You should check the validity of constraints with negative values of istate. If you are convinced that a feasible point does exist, nag_opt_lsq_gencon_deriv (e04us) should be restarted at a different starting point.
W ifail = 4${\mathbf{ifail}}=4$
The limiting number of iterations (as determined by the optional parameter Major Iteration Limit (default value = max (50,3(n + nL) + 10nN)$\text{default value}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,3\left(n+{n}_{L}\right)+10{n}_{N}\right)$) has been reached.
If the algorithm appears to be making satisfactory progress, then Major Iteration Limit may be too small. If so, either increase its value and rerun nag_opt_lsq_gencon_deriv (e04us) or, alternatively, rerun nag_opt_lsq_gencon_deriv (e04us) using the optional parameter Warm Start. If the algorithm seems to be making little or no progress however, then you should check for incorrect gradients or ill-conditioning as described under ${\mathbf{ifail}}={\mathbf{6}}$.
Note that ill-conditioning in the working set is sometimes resolved automatically by the algorithm, in which case performing additional iterations may be helpful. However, ill-conditioning in the Hessian approximation tends to persist once it has begun, so that allowing additional iterations without altering ${\mathbf{r}}$ is usually inadvisable. If the quasi-Newton update of the Hessian approximation was reset during the latter major iterations (i.e., an occurs at the end of each line of intermediate printout; see Section [Description of Printed output]), it may be worthwhile to try a Warm Start at the final point as suggested above.
ifail = 5${\mathbf{ifail}}=5$
Not used by this function.
W ifail = 6${\mathbf{ifail}}=6$
x$x$ does not satisfy the first-order Kuhn–Tucker conditions (see Section [Overview] in (e04uf)), and no improved point for the merit function (see Section [Description of Printed output]) could be found during the final linesearch.
This sometimes occurs because an overly stringent accuracy has been requested, i.e., the value of the optional parameter Optimality Tolerance (default value = εr0.8$\text{default value}={\epsilon }_{r}^{0.8}$, where εr${\epsilon }_{r}$ is the value of the optional parameter Function Precision (default value = ε0.9$\text{default value}={\epsilon }^{0.9}$, where ε$\epsilon$ is the machine precision)) is too small. In this case you should apply the four tests described under ${\mathbf{ifail}}={\mathbf{0}}$ to determine whether or not the final solution is acceptable (see Gill et al. (1981), for a discussion of the attainable accuracy).
If many iterations have occurred in which essentially no progress has been made and nag_opt_lsq_gencon_deriv (e04us) has failed completely to move from the initial point then user-supplied functions objfun and/or confun may be incorrect. You should refer to comments under ${\mathbf{ifail}}={\mathbf{7}}$ and check the gradients using the optional parameter Verify (default value = 0$\text{default value}=0$). Unfortunately, there may be small errors in the objective and constraint gradients that cannot be detected by the verification process. Finite difference approximations to first derivatives are catastrophically affected by even small inaccuracies. An indication of this situation is a dramatic alteration in the iterates if the finite difference interval is altered. One might also suspect this type of error if a switch is made to central differences even when Norm Gz and Violtn (see Section [Description of Printed output]) are large.
Another possibility is that the search direction has become inaccurate because of ill-conditioning in the Hessian approximation or the matrix of constraints in the working set; either form of ill-conditioning tends to be reflected in large values of Mnr (the number of iterations required to solve each QP subproblem; see Section [Description of Printed output]).
If the condition estimate of the projected Hessian (Cond Hz; see Section [Description of Monitoring Information]) is extremely large, it may be worthwhile rerunning nag_opt_lsq_gencon_deriv (e04us) from the final point with the optional parameter Warm Start. In this situation, istate and clamda should be left unaltered and ${\mathbf{r}}$ should be reset to the identity matrix.
If the matrix of constraints in the working set is ill-conditioned (i.e., Cond T is extremely large; see Section [Description of Monitoring Information]), it may be helpful to run nag_opt_lsq_gencon_deriv (e04us) with a relaxed value of the optional parameter Feasibility Tolerance (default value = sqrt(ε)$\text{default value}=\sqrt{\epsilon }$, where ε$\epsilon$ is the machine precision). (Constraint dependencies are often indicated by wide variations in size in the diagonal elements of the matrix T$T$, whose diagonals will be printed if ${\mathbf{Major Print Level}}\ge 30$).
W ifail = 7${\mathbf{ifail}}=7$
The user-supplied derivatives of the subfunctions and/or nonlinear constraints appear to be incorrect.
Large errors were found in the derivatives of the subfunctions and/or nonlinear constraints. This value of ifail will occur if the verification process indicated that at least one Jacobian element had no correct figures. You should refer to the printed output to determine which elements are suspected to be in error.
As a first-step, you should check that the code for the subfunction and constraint values is correct – for example, by computing the subfunctions at a point where the correct value of F(x)$F\left(x\right)$ is known. However, care should be taken that the chosen point fully tests the evaluation of the subfunctions. It is remarkable how often the values x = 0$x=0$ or x = 1$x=1$ are used to test function evaluation procedures, and how often the special properties of these numbers make the test meaningless.
Special care should be used in this test if computation of the subfunctions involves subsidiary data communicated in global storage. Although the first evaluation of the subfunctions may be correct, subsequent calculations may be in error because some of the subsidiary data has accidentally been overwritten.
Gradient checking will be ineffective if the objective function uses information computed by the constraints, since they are not necessarily computed before each function evaluation.
Errors in programming the subfunctions may be quite subtle in that the subfunction values are ‘almost’ correct. For example, a subfunction may not be accurate to full precision because of the inaccurate calculation of a subsidiary quantity, or the limited accuracy of data upon which the subfunction depends. A common error on machines where numerical calculations are usually performed in double precision is to include even one single precision constant in the calculation of the subfunction; since some compilers do not convert such constants to double precision, half the correct figures may be lost by such a seemingly trivial error.
ifail = 8${\mathbf{ifail}}=8$
Not used by this function.
ifail = 9${\mathbf{ifail}}=9$
An input parameter is invalid.
overflow$\mathbf{\text{overflow}}$
If overflow occurs then either an element of C$C$ is very large, or the singular values or singular vectors have been incorrectly supplied.

## Accuracy

If ${\mathbf{ifail}}={\mathbf{0}}$ on exit, then the vector returned in the array x is an estimate of the solution to an accuracy of approximately Optimality Tolerance (default value = ε0.8$\text{default value}={\epsilon }^{0.8}$, where ε$\epsilon$ is the machine precision).

### Description of the Printed Output

This section describes the intermediate printout and final printout produced by nag_opt_lsq_gencon_deriv (e04us). The intermediate printout is a subset of the monitoring information produced by the function at every iteration (see Section [Description of Monitoring Information]). You can control the level of printed output (see the description of the optional parameter Major Print Level). Note that the intermediate printout and final printout are produced only if ${\mathbf{Major Print Level}}\ge 10$ (the default for nag_opt_lsq_gencon_deriv (e04us), by default no output is produced by nag_opt_lsq_gencon_deriv (e04us)). (by default no output is produced by nag_opt_lsq_gencon_deriv (e04us)).
The following line of summary output ( < 80$\text{}<80$ characters) is produced at every major iteration. In all cases, the values of the quantities printed are those in effect on completion of the given iteration.
 Maj is the major iteration count. Mnr is the number of minor iterations required by the feasibility and optimality phases of the QP subproblem. Generally, Mnr will be 1$1$ in the later iterations, since theoretical analysis predicts that the correct active set will be identified near the solution (see Section [Algorithmic Details] in (e04uf)). Note that Mnr may be greater than the optional parameter Minor Iteration Limit if some iterations are required for the feasibility phase. Step is the step αk${\alpha }_{k}$ taken along the computed search direction. On reasonably well-behaved problems, the unit step (i.e., αk = 1${\alpha }_{k}=1$) will be taken as the solution is approached. Merit Function is the value of the augmented Lagrangian merit function (see (12) in (e04uf)) at the current iterate. This function will decrease at each iteration unless it was necessary to increase the penalty parameters (see Section [The Merit Function] in (e04uf)). As the solution is approached, Merit Function will converge to the value of the objective function at the solution. If the QP subproblem does not have a feasible point (signified by I at the end of the current output line) then the merit function is a large multiple of the constraint violations, weighted by the penalty parameters. During a sequence of major iterations with infeasible subproblems, the sequence of Merit Function values will decrease monotonically until either a feasible subproblem is obtained or nag_opt_lsq_gencon_deriv (e04us) terminates with ${\mathbf{ifail}}={\mathbf{3}}$ (no feasible point could be found for the nonlinear constraints). If there are no nonlinear constraints present (i.e., ncnln = 0${\mathbf{ncnln}}=0$) then this entry contains Objective, the value of the objective function F(x)$F\left(x\right)$. The objective function will decrease monotonically to its optimal value when there are no nonlinear constraints. Norm Gz is ‖ZTgFR‖$‖{Z}^{\mathrm{T}}{g}_{\mathrm{FR}}‖$, the Euclidean norm of the projected gradient (see Section [Solution of the Quadratic Programming Subproblem] in (e04uf)). Norm Gz will be approximately zero in the neighbourhood of a solution. Violtn is the Euclidean norm of the residuals of constraints that are violated or in the predicted active set (not printed if ncnln is zero). Violtn will be approximately zero in the neighbourhood of a solution. Cond Hz is a lower bound on the condition number of the projected Hessian approximation HZ${H}_{Z}$ ( HZ = ZT HFR Z = RZT RZ ${H}_{Z}={Z}^{\mathrm{T}}{H}_{\mathrm{FR}}Z={R}_{Z}^{\mathrm{T}}{R}_{Z}$; see (6) and (11) in (e04uf)). The larger this number, the more difficult the problem. M is printed if the quasi-Newton update has been modified to ensure that the Hessian approximation is positive definite (see Section [The Quasi-Newton Update] in (e04uf)). I is printed if the QP subproblem has no feasible point. C is printed if central differences have been used to compute the unspecified objective and constraint gradients. If the value of Step is zero then the switch to central differences was made because no lower point could be found in the linesearch. (In this case, the QP subproblem is resolved with the central difference gradient and Jacobian.) If the value of Step is nonzero then central differences were computed because Norm Gz and Violtn imply that x$x$ is close to a Kuhn–Tucker point (see Section [Overview] in (e04uf)). L is printed if the linesearch has produced a relative change in x$x$ greater than the value defined by the optional parameter Step Limit. If this output occurs frequently during later iterations of the run, optional parameter Step Limit should be set to a larger value. R is printed if the approximate Hessian has been refactorized. If the diagonal condition estimator of R$R$ indicates that the approximate Hessian is badly conditioned then the approximate Hessian is refactorized using column interchanges. If necessary, R$R$ is modified so that its diagonal condition estimator is bounded.
The final printout includes a listing of the status of every variable and constraint.
The following describes the printout for each variable. A full stop (.) is printed for any numerical value that is zero.
Varbl gives the name (V) and index j$\mathit{j}$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$, of the variable.
State gives the state of the variable (FR if neither bound is in the working set, EQ if a fixed variable, LL if on its lower bound, UL if on its upper bound, TF if temporarily fixed at its current value). If Value lies outside the upper or lower bounds by more than the Feasibility Tolerance, State will be ++ or -- respectively.
A key is sometimes printed before State.
 A Alternative optimum possible. The variable is active at one of its bounds, but its Lagrange multiplier is essentially zero. This means that if the variable were allowed to start moving away from its bound then there would be no change to the objective function. The values of the other free variables might change, giving a genuine alternative solution. However, if there are any degenerate variables (labelled D), the actual change might prove to be zero, since one of them could encounter a bound immediately. In either case the values of the Lagrange multipliers might also change. D Degenerate. The variable is free, but it is equal to (or very close to) one of its bounds. I Infeasible. The variable is currently violating one of its bounds by more than the Feasibility Tolerance.
Value is the value of the variable at the final iteration.
Lower Bound is the lower bound specified for the variable. None indicates that bl(j)bigbnd${\mathbf{bl}}\left(j\right)\le -\mathit{bigbnd}$.
Upper Bound is the upper bound specified for the variable. None indicates that bu(j)bigbnd${\mathbf{bu}}\left(j\right)\ge \mathit{bigbnd}$.
Lagr Mult is the Lagrange multiplier for the associated bound. This will be zero if State is FR unless bl(j)bigbnd${\mathbf{bl}}\left(j\right)\le -\mathit{bigbnd}$ and bu(j)bigbnd${\mathbf{bu}}\left(j\right)\ge \mathit{bigbnd}$, in which case the entry will be blank. If x$x$ is optimal, the multiplier should be non-negative if State is LL and non-positive if State is UL.
Slack is the difference between the variable Value and the nearer of its (finite) bounds bl(j)${\mathbf{bl}}\left(j\right)$ and bu(j)${\mathbf{bu}}\left(j\right)$. A blank entry indicates that the associated variable is not bounded (i.e., bl(j)bigbnd${\mathbf{bl}}\left(j\right)\le -\mathit{bigbnd}$ and bu(j)bigbnd${\mathbf{bu}}\left(j\right)\ge \mathit{bigbnd}$).
The meaning of the printout for linear and nonlinear constraints is the same as that given above for variables, with ‘variable’ replaced by ‘constraint’, bl(j)${\mathbf{bl}}\left(j\right)$ and bu(j)${\mathbf{bu}}\left(j\right)$ are replaced by bl(n + j)${\mathbf{bl}}\left(n+j\right)$ and bu(n + j)${\mathbf{bu}}\left(n+j\right)$ respectively, and with the following changes in the heading:
 L Con gives the name (L) and index j$\mathit{j}$, for j = 1,2, … ,nL$\mathit{j}=1,2,\dots ,{n}_{L}$, of the linear constraint. N Con gives the name (N) and index (j − nL$\mathit{j}-{n}_{L}$), for j = nL + 1, … ,nL + nN$\mathit{j}={n}_{L}+1,\dots ,{n}_{L}+{n}_{N}$, of the nonlinear constraint.
Note that movement off a constraint (as opposed to a variable moving away from its bound) can be interpreted as allowing the entry in the Slack column to become positive.
Numerical values are output with a fixed number of digits; they are not guaranteed to be accurate to this precision.

## Example

```function nag_opt_lsq_gencon_deriv_example
a = [1, 1];
bl = [0.4;
-4;
1;
0];
bu = [1e25;
1e25;
1e25;
1e25];
y = [0.49;
0.49;
0.48;
0.47;
0.48;
0.47;
0.46;
0.46;
0.45;
0.43;
0.45;
0.43;
0.43;
0.44;
0.43;
0.43;
0.46;
0.45;
0.42;
0.42;
0.43;
0.41;
0.41;
0.4;
0.42;
0.4;
0.4;
0.41;
0.4;
0.41;
0.41;
0.4;
0.4;
0.4;
0.38;
0.41;
0.4;
0.4;
0.41;
0.38;
0.4;
0.4;
0.39;
0.39];
istate = zeros(4, 1, 'int64');
cjac = [0, 0];
fjac = [0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0];
clamda = zeros(4, 1);
r = [0, 0;
0, 0];
x = [0.4;
0];
[cwsav,lwsav,iwsav,rwsav,ifail] = nag_opt_init('nag_opt_lsq_gencon_deriv');
[iter, istateOut, c, cjacOut, f, fjacOut, clamdaOut, objf, rOut, xOut, user, ...
lwsavOut, iwsavOut, rwsavOut, ifail] = ...
nag_opt_lsq_gencon_deriv(a, bl, bu, y, @confun, @objfun, istate, cjac, fjac, clamda, r, x, lwsav, iwsav, rwsav);
iter, istateOut, c, cjacOut, f, fjacOut, clamdaOut, objf, rOut, xOut, ifail

function [mode, c, cjac, user] = ...
confun(mode, ncnln, n, ldcj, needc, x, cjac, nstate, user)
c = zeros(ncnln, 1);

if (nstate == 1)
%   first call to confun. set all jacobian elements to zero.
%   note that this will only work when 'derivative level = 3'
%   (the default; see section 11.2).
cjac = zeros(ncnln, n);
end
if (needc(1) > 0)
if (mode == 0 || mode == 2)
c(1) = -0.09 - x(1)*x(2) + 0.49*x(2);
end
if (mode == 1 || mode == 2)
cjac(1,1) = -x(2);
cjac(1,2) = -x(1) + 0.49;
end
end

function [mode, f, fjac, user] = objfun(mode, m, n, ldfj, needfi, x, fjac, nstate, user)
f = zeros(m, 1);

a = [8, 8, 10, 10, 10, 10, 12, 12, 12, 12, 14, 14, 14, 16, 16, 16, 18, 18, ...
20, 20, 20, 22, 22, 22, 24, 24, 24, 26, 26, 26, 28, 28, 30, 30, 30, ...
32, 32, 34, 36, 36, 38, 38, 40, 42];

for i = 1:double(m)
temp = exp(-x(2)*(a(i)-8));
if (mode  ==  0 || mode  ==  2)
f(i) = x(1) + (0.49-x(1))*temp;
end
if (mode  ==  1 || mode  ==  2)
fjac(i,1) = 1 - temp;
fjac(i,2) = -(0.49-x(1))*(a(i)-8)*temp;
end
end
```
```

iter =

6

istateOut =

0
0
0
1

c =

-9.7677e-13

cjacOut =

-1.2848    0.0700

f =

0.4900
0.4900
0.4253
0.4253
0.4253
0.4253
0.4204
0.4204
0.4204
0.4204
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200

fjacOut =

0         0
0         0
0.9234   -0.0107
0.9234   -0.0107
0.9234   -0.0107
0.9234   -0.0107
0.9941   -0.0016
0.9941   -0.0016
0.9941   -0.0016
0.9941   -0.0016
0.9996   -0.0002
0.9996   -0.0002
0.9996   -0.0002
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000

clamdaOut =

0
0
0
0.0334

objf =

0.0142

rOut =

0.3365    6.4556
-0.7623    1.3572

xOut =

0.4200
1.2848

ifail =

0

```
```function e04us_example
a = [1, 1];
bl = [0.4;
-4;
1;
0];
bu = [1e25;
1e25;
1e25;
1e25];
y = [0.49;
0.49;
0.48;
0.47;
0.48;
0.47;
0.46;
0.46;
0.45;
0.43;
0.45;
0.43;
0.43;
0.44;
0.43;
0.43;
0.46;
0.45;
0.42;
0.42;
0.43;
0.41;
0.41;
0.4;
0.42;
0.4;
0.4;
0.41;
0.4;
0.41;
0.41;
0.4;
0.4;
0.4;
0.38;
0.41;
0.4;
0.4;
0.41;
0.38;
0.4;
0.4;
0.39;
0.39];
istate = zeros(4, 1, 'int64');
cjac = [0, 0];
fjac = [0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0;
0, 0];
clamda = zeros(4, 1);
r = [0, 0;
0, 0];
x = [0.4;
0];
[cwsav,lwsav,iwsav,rwsav,ifail] = e04wb('e04us');
[iter, istateOut, c, cjacOut, f, fjacOut, clamdaOut, objf, rOut, xOut, user, ...
lwsavOut, iwsavOut, rwsavOut, ifail] = ...
e04us(a, bl, bu, y, @confun, @objfun, istate, cjac, fjac, clamda, r, x, lwsav, iwsav, rwsav);
iter, istateOut, c, cjacOut, f, fjacOut, clamdaOut, objf, rOut, xOut, ifail

function [mode, c, cjac, user] = ...
confun(mode, ncnln, n, ldcj, needc, x, cjac, nstate, user)
c = zeros(ncnln, 1);

if (nstate == 1)
%   first call to confun. set all jacobian elements to zero.
%   note that this will only work when 'derivative level = 3'
%   (the default; see section 11.2).
cjac = zeros(ncnln, n);
end
if (needc(1) > 0)
if (mode == 0 || mode == 2)
c(1) = -0.09 - x(1)*x(2) + 0.49*x(2);
end
if (mode == 1 || mode == 2)
cjac(1,1) = -x(2);
cjac(1,2) = -x(1) + 0.49;
end
end

function [mode, f, fjac, user] = objfun(mode, m, n, ldfj, needfi, x, fjac, nstate, user)
f = zeros(m, 1);

a = [8, 8, 10, 10, 10, 10, 12, 12, 12, 12, 14, 14, 14, 16, 16, 16, 18, 18, ...
20, 20, 20, 22, 22, 22, 24, 24, 24, 26, 26, 26, 28, 28, 30, 30, 30, ...
32, 32, 34, 36, 36, 38, 38, 40, 42];

for i = 1:double(m)
temp = exp(-x(2)*(a(i)-8));
if (mode  ==  0 || mode  ==  2)
f(i) = x(1) + (0.49-x(1))*temp;
end
if (mode  ==  1 || mode  ==  2)
fjac(i,1) = 1 - temp;
fjac(i,2) = -(0.49-x(1))*(a(i)-8)*temp;
end
end
```
```

iter =

6

istateOut =

0
0
0
1

c =

-9.7677e-13

cjacOut =

-1.2848    0.0700

f =

0.4900
0.4900
0.4253
0.4253
0.4253
0.4253
0.4204
0.4204
0.4204
0.4204
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200
0.4200

fjacOut =

0         0
0         0
0.9234   -0.0107
0.9234   -0.0107
0.9234   -0.0107
0.9234   -0.0107
0.9941   -0.0016
0.9941   -0.0016
0.9941   -0.0016
0.9941   -0.0016
0.9996   -0.0002
0.9996   -0.0002
0.9996   -0.0002
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000
1.0000   -0.0000

clamdaOut =

0
0
0
0.0334

objf =

0.0142

rOut =

0.3365    6.4556
-0.7623    1.3572

xOut =

0.4200
1.2848

ifail =

0

```
Note: the remainder of this document is intended for more advanced users. Section [Optional Parameters] describes the optional parameters which may be set by calls to nag_opt_lsq_gencon_deriv_option_string (e04ur). Section [Description of Monitoring Information] describes the quantities which can be requested to monitor the course of the computation.

## Algorithmic Details

nag_opt_lsq_gencon_deriv (e04us) implements a sequential quadratic programming (SQP) method incorporating an augmented Lagrangian merit function and a BFGS (Broyden–Fletcher–Goldfarb–Shanno) quasi-Newton approximation to the Hessian of the Lagrangian, and is based on nag_opt_nlp2_solve (e04wd). The documents for nag_opt_lsq_lincon_solve (e04nc), nag_opt_nlp1_rcomm (e04uf) and nag_opt_nlp2_solve (e04wd) should be consulted for details of the method.

## Optional Parameters

Several optional parameters in nag_opt_lsq_gencon_deriv (e04us) define choices in the problem specification or the algorithm logic. In order to reduce the number of formal parameters of nag_opt_lsq_gencon_deriv (e04us) these optional parameters have associated default values that are appropriate for most problems. Therefore you need only specify those optional parameters whose values are to be different from their default values.
The remainder of this section can be skipped if you wish to use the default values for all optional parameters.
The following is a list of the optional parameters available. A full description of each optional parameter is provided in Section [Description of the optional parameters].
Optional parameters may be specified by calling nag_opt_lsq_gencon_deriv_option_string (e04ur) before a call to nag_opt_lsq_gencon_deriv (e04us).
nag_opt_lsq_gencon_deriv_option_string (e04ur) can be called to supply options directly, one call being necessary for each optional parameter. For example,
```[lwsav, iwsav, rwsav, inform] = e04ur('Print Level = 1', lwsav, iwsav, rwsav);
```
nag_opt_lsq_gencon_deriv_option_string (e04ur) should be consulted for a full description of this method of supplying optional parameters.
All optional parameters not specified by you are set to their default values. Optional parameters specified by you are unaltered by nag_opt_lsq_gencon_deriv (e04us) (unless they define invalid values) and so remain in effect for subsequent calls to nag_opt_lsq_gencon_deriv (e04us), unless altered by you.

### Description of the Optional Parameters

For each option, we give a summary line, a description of the optional parameter and details of constraints.
The summary line contains:
• the keywords, where the minimum abbreviation of each keyword is underlined (if no characters of an optional qualifier are underlined, the qualifier may be omitted);
• a parameter value, where the letters a$a$, i​ and ​r$i\text{​ and ​}r$ denote options that take character, integer and real values respectively;
• the default value, where the symbol ε$\epsilon$ is a generic notation for machine precision (see nag_machine_precision (x02aj)), and εr${\epsilon }_{r}$ denotes the relative precision of the objective function Function Precision.
Keywords and character values are case and white space insensitive.
Further details of other quantities not explicitly defined in this section may be found by consulting the document for nag_opt_nlp1_rcomm (e04uf).
Central Difference Interval  r$r$
Default values are computed
If the algorithm switches to central differences because the forward-difference approximation is not sufficiently accurate, the value of r$r$ is used as the difference interval for every element of x$x$. The switch to central differences is indicated by at the end of each line of intermediate printout produced by the major iterations (see Section [Description of Printed output]). The use of finite differences is discussed further under the optional parameter Difference Interval.
If you supply a value for this optional parameter, a small value between 0.0$0.0$ and 1.0$1.0$ is appropriate.
Cold Start
Default
Warm Start
This option controls the specification of the initial working set in both the procedure for finding a feasible point for the linear constraints and bounds, and in the first QP subproblem thereafter. With a Cold Start, the first working set is chosen by nag_opt_lsq_gencon_deriv (e04us) based on the values of the variables and constraints at the initial point. Broadly speaking, the initial working set will include equality constraints and bounds or inequality constraints that violate or ‘nearly’ satisfy their bounds (to within Crash Tolerance).
With a Warm Start, you must set the istate array and define clamda and r as discussed in Section [Parameters]. istate values associated with bounds and linear constraints determine the initial working set of the procedure to find a feasible point with respect to the bounds and linear constraints. istate values associated with nonlinear constraints determine the initial working set of the first QP subproblem after such a feasible point has been found. nag_opt_lsq_gencon_deriv (e04us) will override your specification of istate if necessary, so that a poor choice of the working set will not cause a fatal error. For instance, any elements of istate which are set to 2$-2$, 1​ or ​4$-1\text{​ or ​}4$ will be reset to zero, as will any elements which are set to 3$3$ when the corresponding elements of bl and bu are not equal. A Warm Start will be advantageous if a good estimate of the initial working set is available – for example, when nag_opt_lsq_gencon_deriv (e04us) is called repeatedly to solve related problems.
Crash Tolerance  r$r$
Default = 0.01$\text{}=0.01$
This value is used in conjunction with the optional parameter Cold Start (the default value) when nag_opt_lsq_gencon_deriv (e04us) selects an initial working set. If 0r1$0\le r\le 1$, the initial working set will include (if possible) bounds or general inequality constraints that lie within r$r$ of their bounds. In particular, a constraint of the form ajT xl ${a}_{j}^{\mathrm{T}}x\ge l$ will be included in the initial working set if |ajTxl| r (1 + |l|) $|{a}_{j}^{\mathrm{T}}x-l|\le r\left(1+|l|\right)$. If r < 0$r<0$ or r > 1$r>1$, the default value is used.
Defaults
This special keyword may be used to reset all optional parameters to their default values.
Derivative Level  i$i$
Default = 3$\text{}=3$
This parameter indicates which derivatives are provided in user-supplied functions objfun and confun. The possible choices for i$i$ are the following.
 i$i$ Meaning 3 All elements of the objective Jacobian and the constraint Jacobian are provided by you. 2 All elements of the constraint Jacobian are provided, but some elements of the objective Jacobian are not specified by you. 1 All elements of the objective Jacobian are provided, but some elements of the constraint Jacobian are not specified by you. 0 Some elements of both the objective Jacobian and the constraint Jacobian are not specified by you.
The value i = 3$i=3$ should be used whenever possible, since nag_opt_lsq_gencon_deriv (e04us) is more reliable (and will usually be more efficient) when all derivatives are exact.
If i = 0​ or ​2$i=0\text{​ or ​}2$, nag_opt_lsq_gencon_deriv (e04us) will approximate unspecified elements of the objective Jacobian, using finite differences. The computation of finite difference approximations usually increases the total run-time, since a call to objfun is required for each unspecified element. Furthermore, less accuracy can be attained in the solution (see Chapter 8 of Gill et al. (1981), for a discussion of limiting accuracy).
If i = 0​ or ​1$i=0\text{​ or ​}1$, nag_opt_lsq_gencon_deriv (e04us) will approximate unspecified elements of the constraint Jacobian. One call to confun is needed for each variable for which partial derivatives are not available. For example, if the constraint Jacobian has the form
 * * * * * ? ? * * * ? * * * * *
$* * * * * ? ? * * * ? * * * * *$
where ‘*$*$’ indicates an element provided by you and ‘?’ indicates an unspecified element, nag_opt_lsq_gencon_deriv (e04us) will call confun twice: once to estimate the missing element in column 2$2$, and again to estimate the two missing elements in column 3$3$. (Since columns 1$1$ and 4$4$ are known, they require no calls to confun.)
At times, central differences are used rather than forward differences, in which case twice as many calls to objfun and confun are needed. (The switch to central differences is not under your control.)
If i < 0$i<0$ or i > 3$i>3$, the default value is used.
Difference Interval  r$r$
Default values are computed
This option defines an interval used to estimate derivatives by finite differences in the following circumstances:
 (a) For verifying the objective and/or constraint gradients (see the description of the optional parameter Verify). (b) For estimating unspecified elements of the objective and/or constraint Jacobian matrix.
In general, a derivative with respect to the j$j$th variable is approximated using the interval δj${\delta }_{j}$, where δj = r(1 + |j|)${\delta }_{j}=r\left(1+|{\stackrel{^}{x}}_{j}|\right)$, with $\stackrel{^}{x}$ the first point feasible with respect to the bounds and linear constraints. If the functions are well scaled, the resulting derivative approximation should be accurate to O(r)$\mathit{O}\left(r\right)$. See Gill et al. (1981) for a discussion of the accuracy in finite difference approximations.
If a difference interval is not specified, a finite difference interval will be computed automatically for each variable by a procedure that requires up to six calls of confun and objfun for each element. This option is recommended if the function is badly scaled or you wish to have nag_opt_lsq_gencon_deriv (e04us) determine constant elements in the objective and constraint gradients (see the descriptions of confun and objfun in Section [Parameters]).
If you supply a value for this optional parameter, a small value between 0.0$0.0$ and 1.0$1.0$ is appropriate.
Feasibility Tolerance  r$r$
Default = sqrt(ε)$\text{}=\sqrt{\epsilon }$
The scalar r$r$ defines the maximum acceptable absolute violations in linear and nonlinear constraints at a ‘feasible’ point; i.e., a constraint is considered satisfied if its violation does not exceed r$r$. If r < ε$r<\epsilon$ or r1$r\ge 1$, the default value is used. Using this keyword sets both optional parameters Linear Feasibility Tolerance and Nonlinear Feasibility Tolerance to r$r$, if εr < 1$\epsilon \le r<1$. (Additional details are given under the descriptions of these optional parameters.)
Function Precision  r$r$
Default = ε0.9$\text{}={\epsilon }^{0.9}$
This parameter defines εr${\epsilon }_{r}$, which is intended to be a measure of the accuracy with which the problem functions F(x)$F\left(x\right)$ and c(x)$c\left(x\right)$ can be computed. If r < ε$r<\epsilon$ or r1$r\ge 1$, the default value is used.
The value of εr${\epsilon }_{r}$ should reflect the relative precision of 1 + |F(x)|$1+|F\left(x\right)|$; i.e., εr${\epsilon }_{r}$ acts as a relative precision when |F|$|F|$ is large and as an absolute precision when |F|$|F|$ is small. For example, if F(x)$F\left(x\right)$ is typically of order 1000$1000$ and the first six significant digits are known to be correct, an appropriate value for εr${\epsilon }_{r}$ would be 106${10}^{-6}$. In contrast, if F(x)$F\left(x\right)$ is typically of order 104${10}^{-4}$ and the first six significant digits are known to be correct, an appropriate value for εr${\epsilon }_{r}$ would be 1010${10}^{-10}$. The choice of εr${\epsilon }_{r}$ can be quite complicated for badly scaled problems; see Chapter 8 of Gill et al. (1981) for a discussion of scaling techniques. The default value is appropriate for most simple functions that are computed with full accuracy. However, when the accuracy of the computed function values is known to be significantly worse than full precision, the value of εr${\epsilon }_{r}$ should be large enough so that nag_opt_lsq_gencon_deriv (e04us) will not attempt to distinguish between function values that differ by less than the error inherent in the calculation.
Hessian  No$\overline{)\mathbf{N}}\mathbf{o}$
Default = NO$=\mathrm{NO}$
This option controls the contents of the upper triangular matrix R$R$ (see Section [Parameters]). nag_opt_lsq_gencon_deriv (e04us) works exclusively with the transformed and reordered Hessian HQ${H}_{Q}$, and hence extra computation is required to form the Hessian itself. If Hessian = NO${\mathbf{Hessian}}=\mathrm{NO}$, r contains the Cholesky factor of the transformed and reordered Hessian. If Hessian = YES${\mathbf{Hessian}}=\mathrm{YES}$, the Cholesky factor of the approximate Hessian itself is formed and stored in r. You should select Hessian = YES${\mathbf{Hessian}}=\mathrm{YES}$ if a Warm Start will be used for the next call to nag_opt_lsq_gencon_deriv (e04us).
Infinite Bound Size  r$r$
Default = 1020$\text{}={10}^{20}$
If r > 0$r>0$, r$r$ defines the ‘infinite’ bound bigbnd$\mathit{bigbnd}$ in the definition of the problem constraints. Any upper bound greater than or equal to bigbnd$\mathit{bigbnd}$ will be regarded as + $+\infty$ (and similarly any lower bound less than or equal to bigbnd$-\mathit{bigbnd}$ will be regarded as $-\infty$). If r < 0$r<0$, the default value is used.
Infinite Step Size  r$r$
Default = max (bigbnd,1020)$\text{}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\mathit{bigbnd},{10}^{20}\right)$
If r > 0$r>0$, r$r$ specifies the magnitude of the change in variables that is treated as a step to an unbounded solution. If the change in x$x$ during an iteration would exceed the value of r$r$, the objective function is considered to be unbounded below in the feasible region. If r0$r\le 0$, the default value is used.
JTJ Initial Hessian
Default
Unit Initial Hessian
This option controls the initial value of the upper triangular matrix R$R$. If J$J$ denotes the objective Jacobian matrix f(x)$\nabla f\left(x\right)$, then JTJ${J}^{\mathrm{T}}J$ is often a good approximation to the objective Hessian matrix 2F(x)${\nabla }^{2}F\left(x\right)$ (see also optional parameter Reset Frequency).
Line Search Tolerance  r$r$
Default = 0.9$\text{}=0.9$
The value r$r$ (0r < 1$0\le r<1$) controls the accuracy with which the step α$\alpha$ taken during each iteration approximates a minimum of the merit function along the search direction (the smaller the value of r$r$, the more accurate the linesearch). The default value r = 0.9$r=0.9$ requests an inaccurate search and is appropriate for most problems, particularly those with any nonlinear constraints.
If there are no nonlinear constraints, a more accurate search may be appropriate when it is desirable to reduce the number of major iterations – for example, if the objective function is cheap to evaluate, or if a substantial number of derivatives are unspecified. If r < 0$r<0$ or r1$r\ge 1$, the default value is used.
Linear Feasibility Tolerance  r1${r}_{1}$
Default = sqrt(ε)$\text{}=\sqrt{\epsilon }$
Nonlinear Feasibility Tolerance  r2${r}_{2}$
Default = ε0.33$\text{}={\epsilon }^{0.33}$ or sqrt(ε)$\sqrt{\epsilon }$
The default value of r2${r}_{2}$ is ε0.33${\epsilon }^{0.33}$ if ${\mathbf{Derivative Level}}=0$ or 1$1$, and sqrt(ε)$\sqrt{\epsilon }$ otherwise.
The scalars r1${r}_{1}$ and r2${r}_{2}$ define the maximum acceptable absolute violations in linear and nonlinear constraints at a ‘feasible’ point; i.e., a linear constraint is considered satisfied if its violation does not exceed r1${r}_{1}$, and similarly for a nonlinear constraint and r2${r}_{2}$. If rm < ε${r}_{m}<\epsilon$ or rm1${r}_{\mathit{m}}\ge 1$, the default value is used, for m = 1,2$\mathit{m}=1,2$.
On entry to nag_opt_lsq_gencon_deriv (e04us), an iterative procedure is executed in order to find a point that satisfies the linear constraints and bounds on the variables to within the tolerance r1${r}_{1}$. All subsequent iterates will satisfy the linear constraints to within the same tolerance (unless r1${r}_{1}$ is comparable to the finite difference interval).
For nonlinear constraints, the feasibility tolerance r2${r}_{2}$ defines the largest constraint violation that is acceptable at an optimal point. Since nonlinear constraints are generally not satisfied until the final iterate, the value of optional parameter Nonlinear Feasibility Tolerance acts as a partial termination criterion for the iterative sequence generated by nag_opt_lsq_gencon_deriv (e04us) (see also optional parameter Optimality Tolerance).
These tolerances should reflect the precision of the corresponding constraints. For example, if the variables and the coefficients in the linear constraints are of order unity, and the latter are correct to about 6$6$ decimal digits, it would be appropriate to specify r1${r}_{1}$ as 106${10}^{-6}$.
List
Default for e04us = List$\text{e04us}={\mathbf{List}}$
Nolist
Default for e04us = Nolist$\text{e04us}={\mathbf{Nolist}}$
Normally each optional parameter specification is printed as it is supplied. Optional parameter Nolist may be used to suppress the printing and optional parameter List may be used to restore printing.
Major Iteration Limit  i$i$
Default = max (50,3(n + nL) + 10nN)$\text{}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,3\left(n+{n}_{L}\right)+10{n}_{N}\right)$
Iteration Limit
Iters
Itns
The value of i$i$ specifies the maximum number of major iterations allowed before termination. Setting i = 0$i=0$ and ${\mathbf{Major Print Level}}>0$ means that the workspace needed will be computed and printed, but no iterations will be performed. If i < 0$i<0$, the default value is used.
Major Print Level  i$i$
Print Level
Default for nag_opt_lsq_gencon_deriv (e04us) = 0$\text{}=0$
The value of i$i$ controls the amount of printout produced by the major iterations of nag_opt_lsq_gencon_deriv (e04us), as indicated below. A detailed description of the printed output is given in Section [Description of Printed output] (summary output at each major iteration and the final solution) and Section [Description of Monitoring Information] (monitoring information at each major iteration). (See also the description of the optional parameter Minor Print Level.)
The following printout is sent to the current advisory message unit (as defined by nag_file_set_unit_advisory (x04ab)):
 i$i$ Output ≥ 00$\phantom{\ge 0}0$ No output. ≥ 01$\phantom{\ge 0}1$ The final solution only. ≥ 05$\phantom{\ge 0}5$ One line of summary output ( < 80$\text{}<80$ characters; see Section [Description of Printed output]) for each major iteration (no printout of the final solution). ≥ 10$\text{}\ge 10$ The final solution and one line of summary output for each major iteration.
The following printout is sent to the logical unit number defined by the optional parameter Monitoring File:
 i$i$ Output < 5$\text{}<5$ No output. ≥ 5$\text{}\ge 5$ One long line of output ( > 80$\text{}>80$ characters; see Section [Description of Monitoring Information]) for each major iteration (no printout of the final solution). ≥ 20$\text{}\ge 20$ At each major iteration, the objective function, the Euclidean norm of the nonlinear constraint violations, the values of the nonlinear constraints (the vector c$c$), the values of the linear constraints (the vector ALx${A}_{L}x$), and the current values of the variables (the vector x$x$). ≥ 30$\text{}\ge 30$ At each major iteration, the diagonal elements of the matrix T$T$ associated with the TQ$TQ$ factorization (see (5) in (e04uf)) of the QP working set, and the diagonal elements of R$R$, the triangular factor of the transformed and reordered Hessian (see (6) in (e04uf)).
If ${\mathbf{Major Print Level}}\ge 5$ and the unit number defined by the optional parameter Monitoring File is the same as that defined by nag_file_set_unit_advisory (x04ab), then the summary output for each major iteration is suppressed.
Minor Iteration Limit  i$i$
Default = max (50,3(n + nL + nN))$\text{}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,3\left(n+{n}_{L}+{n}_{N}\right)\right)$
The value of i$i$ specifies the maximum number of iterations for finding a feasible point with respect to the bounds and linear constraints (if any). The value of i$i$ also specifies the maximum number of minor iterations for the optimality phase of each QP subproblem. If i0$i\le 0$, the default value is used.
Minor Print Level  i$i$
Default = 0$\text{}=0$
The value of i$i$ controls the amount of printout produced by the minor iterations of nag_opt_lsq_gencon_deriv (e04us) (i.e., the iterations of the quadratic programming algorithm), as indicated below. A detailed description of the printed output is given in Section [Description of Printed output] (summary output at each minor iteration and the final QP solution) and Section [Description of Monitoring Information] (monitoring information at each minor iteration). (See also the description of the optional parameter Major Print Level.)
The following printout is sent to the current advisory message unit (as defined by nag_file_set_unit_advisory (x04ab)):
 i$i$ Output ≥ 00$\phantom{\ge 0}0$ No output. ≥ 01$\phantom{\ge 0}1$ The final QP solution only. ≥ 05$\phantom{\ge 0}5$ One line of summary output ( < 80$\text{}<80$ characters; see Section [Description of Printed output]) for each minor iteration (no printout of the final QP solution). ≥ 10$\text{}\ge 10$ The final QP solution and one line of summary output for each minor iteration.
The following printout is sent to the logical unit number defined by the optional parameter Monitoring File:
 i$i$ Output < 5$\text{}<5$ No output. ≥ 5$\text{}\ge 5$ One long line of output ( > 80$\text{}>80$ characters; see Section [Description of Monitoring Information]) for each minor iteration (no printout of the final QP solution). ≥ 20$\text{}\ge 20$ At each minor iteration, the current estimates of the QP multipliers, the current estimate of the QP search direction, the QP constraint values, and the status of each QP constraint. ≥ 30$\text{}\ge 30$ At each minor iteration, the diagonal elements of the matrix T$T$ associated with the TQ$TQ$ factorization (see (5) in (e04uf)) of the QP working set, and the diagonal elements of the Cholesky factor R $R$ of the transformed Hessian (see (6) in (e04uf)).
If ${\mathbf{Minor Print Level}}\ge 5$ and the unit number defined by the optional parameter Monitoring File is the same as that defined by nag_file_set_unit_advisory (x04ab), then the summary output for each minor iteration is suppressed.
Monitoring File  i$i$
Default = 1$\text{}=-1$
If i0$i\ge 0$ and ${\mathbf{Major Print Level}}\ge 5$ or i0$i\ge 0$ and ${\mathbf{Minor Print Level}}\ge 5$, monitoring information produced by nag_opt_lsq_gencon_deriv (e04us) at every iteration is sent to a file with logical unit number i$i$. If i < 0$i<0$ and/or ${\mathbf{Major Print Level}}<5$ and ${\mathbf{Minor Print Level}}<5$, no monitoring information is produced.
Optimality Tolerance  r$r$
Default = εR0.8 $\text{}={\epsilon }_{R}^{0.8}$
The parameter r$r$ (εRr < 1${\epsilon }_{R}\le r<1$) specifies the accuracy to which you wish the final iterate to approximate a solution of the problem. Broadly speaking, r$r$ indicates the number of correct figures desired in the objective function at the solution. For example, if r$r$ is 106${10}^{-6}$ and nag_opt_lsq_gencon_deriv (e04us) terminates successfully, the final value of F$F$ should have approximately six correct figures. If r < εR$r<{\epsilon }_{R}$ or r1$r\ge 1$, the default value is used.
nag_opt_lsq_gencon_deriv (e04us) will terminate successfully if the iterative sequence of x$x$ values is judged to have converged and the final point satisfies the first-order Kuhn–Tucker conditions (see Section [Overview] in (e04uf)). The sequence of iterates is considered to have converged at x$x$ if
 α‖p‖ ≤ sqrt(r)(1 + ‖x‖), $α‖p‖≤r(1+‖x‖),$ (2)
where p$p$ is the search direction and α$\alpha$ the step length. An iterate is considered to satisfy the first-order conditions for a minimum if
 ‖ZTgFR‖ ≤ sqrt( r ) (1 + max ( 1 + |F(x)| ,‖gFR‖)) $‖ ZT g FR ‖ ≤ r ( 1 + max( 1 + | F ( x ) | ,‖ g FR ‖) )$ (3)
and
 |resj| ≤ ftol  for all  j, $|resj|≤ftol for all j,$ (4)
where ZTgFR${Z}^{\mathrm{T}}{g}_{\mathrm{FR}}$ is the projected gradient, gFR${g}_{\mathrm{FR}}$ is the gradient of F(x)$F\left(x\right)$ with respect to the free variables, resj${\mathit{res}}_{j}$ is the violation of the j$j$th active nonlinear constraint, and ftol$\mathit{ftol}$ is the Nonlinear Feasibility Tolerance.
Reset Frequency  i$i$
Default = 2$\text{}=2$
If i > 0$i>0$, this parameter allows you to reset the approximate Hessian matrix to JTJ${J}^{\mathrm{T}}J$ every i$i$ iterations, where J$J$ is the objective Jacobian matrix f(x)$\nabla f\left(x\right)$ (see also the description of the optional parameter JTJ Initial Hessian).
At any point where there are no nonlinear constraints active and the values of f$f$ are small in magnitude compared to the norm of J$J$, JTJ${J}^{\mathrm{T}}J$ will be a good approximation to the objective Hessian 2F(x)${\nabla }^{2}F\left(x\right)$. Under these circumstances, frequent resetting can significantly improve the convergence rate of nag_opt_lsq_gencon_deriv (e04us).
Resetting is suppressed at any iteration during which there are nonlinear constraints active.
If i0$i\le 0$, the default value is used.
Start Objective Check At Variable  i1${i}_{1}$
Default = 1$\text{}=1$
Stop Objective Check At Variable  i2${i}_{2}$
Default = n$\text{}=n$
Start Constraint Check At Variable  i3${i}_{3}$
Default = 1$\text{}=1$
Stop Constraint Check At Variable  i4${i}_{4}$
Default = n$\text{}=n$
These keywords take effect only if ${\mathbf{Verify Level}}>0$. They may be used to control the verification of Jacobian elements computed by user-supplied functions objfun and confun. For example, if the first 30$30$ columns of the objective Jacobian appeared to be correct in an earlier run, so that only column 31$31$ remains questionable, it is reasonable to specify ${\mathbf{Start Objective Check At Variable}}=31$. If the first 30$30$ variables appear linearly in the subfunctions, so that the corresponding Jacobian elements are constant, the above choice would also be appropriate.
If i2m10${i}_{2\mathit{m}-1}\le 0$ or i2m1 > min (n,i2m)${i}_{2\mathit{m}-1}>\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(n,{i}_{2\mathit{m}}\right)$, the default value is used, for m = 1,2$\mathit{m}=1,2$. If i2m0${i}_{2\mathit{m}}\le 0$ or i2m > n${i}_{2\mathit{m}}>n$, the default value is used, for m = 1,2$\mathit{m}=1,2$.
Step Limit  r$r$
Default = 2.0$\text{}=2.0$
If r > 0,r$r>0,r$ specifies the maximum change in variables at the first step of the linesearch. In some cases, such as F(x) = aebx$F\left(x\right)=a{e}^{bx}$ or F(x) = axb$F\left(x\right)=a{x}^{b}$, even a moderate change in the elements of x$x$ can lead to floating point overflow. The parameter r$r$ is therefore used to encourage evaluation of the problem functions at meaningful points. Given any major iterate x$x$, the first point $\stackrel{~}{x}$ at which F$F$ and c$c$ are evaluated during the linesearch is restricted so that
 ‖x̃ − x‖2 ≤ r(1 + ‖x‖2). $‖x~-x‖2≤r(1+‖x‖2).$
The linesearch may go on and evaluate F$F$ and c$c$ at points further from x$x$ if this will result in a lower value of the merit function (indicated by L at the end of each line of output produced by the major iterations; see Section [Description of Printed output]). If L is printed for most of the iterations, r$r$ should be set to a larger value.
Wherever possible, upper and lower bounds on x$x$ should be used to prevent evaluation of nonlinear functions at wild values. The default value Step Limit = 2.0${\mathbf{Step Limit}}=2.0$ should not affect progress on well-behaved functions, but values such as 0.1 ​ or ​ 0.01$0.1\text{​ or ​}0.01$ may be helpful when rapidly varying functions are present. If a small value of Step Limit is selected, a good starting point may be required. An important application is to the class of nonlinear least squares problems. If r0$r\le 0$, the default value is used.
Verify Level  i$i$
Default = 0$\text{}=0$
Verify
These keywords refer to finite difference checks on the gradient elements computed by objfun and confun. (Unspecified gradient elements are not checked.) The possible choices for i$i$ are the following:
 i$i$ Meaning − 1$-1$ No checks are performed. − 0$\phantom{-}0$ Only a ‘cheap’ test will be performed, requiring one call to objfun. − 1$\phantom{-}1$ Individual gradient elements will also be checked using a reliable (but more expensive) test.
For example, the nonlinear objective gradient (if any) will be verified if either Verify Objective Gradients or ${\mathbf{Verify Level}}=1$ is specified. Similarly, the objective and the constraint gradients will be verified if Verify = YES${\mathbf{Verify}}=\mathrm{YES}$ or ${\mathbf{Verify Level}}=3$ or Verify is specified.
If i = 1$i=-1$, no checking will be performed.
If 0i3$0\le i\le 3$, gradients will be verified at the first point that satisfies the linear constraints and bounds. If i = 0$i=0$, only a ‘cheap’ test will be performed, requiring one call to objfun and (if appropriate) one call to confun. If 1i3$1\le i\le 3$, a more reliable (but more expensive) check will be made on individual gradient elements, within the ranges specified by the Start Objective Check At Variable and Stop Objective Check At Variable keywords. A result of the form OK or BAD? is printed by nag_opt_lsq_gencon_deriv (e04us) to indicate whether or not each element appears to be correct.
If 10i13$10\le i\le 13$, the action is the same as for i10$i-10$, except that it will take place at the user-specified initial value of x$x$.
If i < 1$i<-1$ or 4i9$4\le i\le 9$ or i > 13$i>13$, the default value is used.
We suggest that ${\mathbf{Verify Level}}=3$ be used whenever a new function function is being developed.

## Description of Monitoring Information

This section describes the long line of output ( > 80$\text{}>80$ characters) which forms part of the monitoring information produced by nag_opt_lsq_gencon_deriv (e04us). (See also the description of the optional parameters Major Print Level, Minor Print Level and Monitoring File.) You can control the level of printed output.
When ${\mathbf{Major Print Level}}\ge 5$ and ${\mathbf{Monitoring File}}\ge 0$, the following line of output is produced at every major iteration of nag_opt_lsq_gencon_deriv (e04us) on the unit number specified by optional parameter Monitoring File. In all cases, the values of the quantities printed are those in effect on completion of the given iteration.
Maj is the major iteration count.
Mnr is the number of minor iterations required by the feasibility and optimality phases of the QP subproblem. Generally, Mnr will be 1$1$ in the later iterations, since theoretical analysis predicts that the correct active set will be identified near the solution (see Section [Algorithmic Details] in (e04uf)).
Note that Mnr may be greater than the optional parameter Minor Iteration Limit if some iterations are required for the feasibility phase.
Step is the step αk${\alpha }_{k}$ taken along the computed search direction. On reasonably well-behaved problems, the unit step (i.e., αk = 1${\alpha }_{k}=1$) will be taken as the solution is approached.
Nfun is the cumulative number of evaluations of the objective function needed for the linesearch. Evaluations needed for the estimation of the gradients by finite differences are not included. Nfun is printed as a guide to the amount of work required for the linesearch.
Merit Function is the value of the augmented Lagrangian merit function (see (12) in (e04uf)) at the current iterate. This function will decrease at each iteration unless it was necessary to increase the penalty parameters (see Section [The Merit Function] in (e04uf)). As the solution is approached, Merit Function will converge to the value of the objective function at the solution.
If the QP subproblem does not have a feasible point (signified by I at the end of the current output line) then the merit function is a large multiple of the constraint violations, weighted by the penalty parameters. During a sequence of major iterations with infeasible subproblems, the sequence of Merit Function values will decrease monotonically until either a feasible subproblem is obtained or nag_opt_lsq_gencon_deriv (e04us) terminates with ${\mathbf{ifail}}={\mathbf{3}}$ (no feasible point could be found for the nonlinear constraints).
If there are no nonlinear constraints present (i.e., ncnln = 0${\mathbf{ncnln}}=0$) then this entry contains Objective, the value of the objective function F(x)$F\left(x\right)$. The objective function will decrease monotonically to its optimal value when there are no nonlinear constraints.
Norm Gz is ZTgFR$‖{Z}^{\mathrm{T}}{g}_{\mathrm{FR}}‖$, the Euclidean norm of the projected gradient (see Section [Solution of the Quadratic Programming Subproblem] in (e04uf)). Norm Gz will be approximately zero in the neighbourhood of a solution.
Violtn is the Euclidean norm of the residuals of constraints that are violated or in the predicted active set (not printed if ncnln is zero). Violtn will be approximately zero in the neighbourhood of a solution.
Nz is the number of columns of Z$Z$ (see Section [Solution of the Quadratic Programming Subproblem] in (e04uf)). The value of Nz is the number of variables minus the number of constraints in the predicted active set; i.e., Nz = n(Bnd + Lin + Nln)$\mathtt{Nz}=n-\left(\mathtt{Bnd}+\mathtt{Lin}+\mathtt{Nln}\right)$.
Bnd is the number of simple bound constraints in the current working set.
Lin is the number of general linear constraints in the current working set.
Nln is the number of nonlinear constraints in the predicted active set (not printed if ncnln is zero).
Penalty is the Euclidean norm of the vector of penalty parameters used in the augmented Lagrangian merit function (not printed if ncnln is zero).
Cond H is a lower bound on the condition number of the Hessian approximation H$H$.
Cond Hz is a lower bound on the condition number of the projected Hessian approximation HZ${H}_{Z}$ ( HZ = ZT HFR Z = RZT RZ ${H}_{Z}={Z}^{\mathrm{T}}{H}_{\mathrm{FR}}Z={R}_{Z}^{\mathrm{T}}{R}_{Z}$; see (6) and (11) in (e04uf)). The larger this number, the more difficult the problem.
Cond T is a lower bound on the condition number of the matrix of predicted active constraints.
Conv is a three-letter indication of the status of the three convergence tests (2)(4) defined in the description of the optional parameter Optimality Tolerance. Each letter is T if the test is satisfied and F otherwise. The three tests indicate whether:
 (i) the sequence of iterates has converged; (ii) the projected gradient (Norm Gz) is sufficiently small; and (iii) the norm of the residuals of constraints in the predicted active set (Violtn) is small enough.
If any of these indicators is F when nag_opt_lsq_gencon_deriv (e04us) terminates with ${\mathbf{ifail}}={\mathbf{0}}$, you should check the solution carefully.
M is printed if the quasi-Newton update has been modified to ensure that the Hessian approximation is positive definite (see Section [The Quasi-Newton Update] in (e04uf)).
I is printed if the QP subproblem has no feasible point.
C is printed if central differences have been used to compute the unspecified objective and constraint gradients. If the value of Step is zero then the switch to central differences was made because no lower point could be found in the linesearch. (In this case, the QP subproblem is resolved with the central difference gradient and Jacobian.) If the value of Step is nonzero then central differences were computed because Norm Gz and Violtn imply that x$x$ is close to a Kuhn–Tucker point (see Section [Overview] in (e04uf)).
L is printed if the linesearch has produced a relative change in x$x$ greater than the value defined by the optional parameter Step Limit. If this output occurs frequently during later iterations of the run, optional parameter Step Limit should be set to a larger value.
R is printed if the approximate Hessian has been refactorized. If the diagonal condition estimator of R$R$ indicates that the approximate Hessian is badly conditioned then the approximate Hessian is refactorized using column interchanges. If necessary, R$R$ is modified so that its diagonal condition estimator is bounded.