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

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_opt_lsq_lincon_solve (e04nc)

## Purpose

nag_opt_lsq_lincon_solve (e04nc) solves linearly constrained linear least squares problems and convex quadratic programming problems. It is not intended for large sparse problems.

## Syntax

[istate, kx, x, a, b, iter, obj, clamda, lwsav, iwsav, rwsav, ifail] = e04nc(c, bl, bu, cvec, istate, kx, x, a, b, lwsav, iwsav, rwsav, 'm', m, 'n', n, 'nclin', nclin)
[istate, kx, x, a, b, iter, obj, clamda, lwsav, iwsav, rwsav, ifail] = nag_opt_lsq_lincon_solve(c, bl, bu, cvec, istate, kx, x, a, b, lwsav, iwsav, rwsav, 'm', m, 'n', n, 'nclin', nclin)
Before calling nag_opt_lsq_lincon_solve (e04nc), or the option setting function nag_opt_lsq_lincon_option_string (e04ne), nag_opt_init (e04wb) must be called.

## Description

nag_opt_lsq_lincon_solve (e04nc) is designed to solve a class of quadratic programming problems of the following general form:
 $minimize x∈Rn Fx subject to l≤ x Cx ≤u$ (1)
where ${\mathbf{c}}$ is an ${n}_{L}$ by $n$ matrix and the objective function $F\left(x\right)$ may be specified in a variety of ways depending upon the particular problem to be solved. The available forms for $F\left(x\right)$ are listed in Table 1, in which the prefixes FP, LP, QP and LS stand for ‘feasible point’, ‘linear programming’, ‘quadratic programming’ and ‘least squares’ respectively, $c$ is an $n$-element vector, $b$ is an $m$ element vector and $‖z‖$ denotes the Euclidean length of $z$.
 Problem type $F\left(x\right)$ Matrix $A$ FP None Not applicable LP ${c}^{\mathrm{T}}x$ Not applicable QP1 $\phantom{{c}^{\mathrm{T}}x+}\frac{1}{2}{x}^{\mathrm{T}}Ax$ $n$ by $n$ symmetric positive semidefinite QP2 ${c}^{\mathrm{T}}x+\frac{1}{2}{x}^{\mathrm{T}}Ax$ $n$ by $n$ symmetric positive semidefinite QP3 $\phantom{{c}^{\mathrm{T}}x+}\frac{1}{2}{x}^{\mathrm{T}}{A}^{\mathrm{T}}Ax$ $m$ by $n$ upper trapezoidal QP4 ${c}^{\mathrm{T}}x+\frac{1}{2}{x}^{\mathrm{T}}{A}^{\mathrm{T}}Ax$ $m$ by $n$ upper trapezoidal LS1 $\phantom{{c}^{\mathrm{T}}x+}\frac{1}{2}{‖b-Ax‖}^{2}$ $m$ by $n$ LS2 ${c}^{\mathrm{T}}x+\frac{1}{2}{‖b-Ax‖}^{2}$ $m$ by $n$ LS3 $\phantom{{c}^{\mathrm{T}}x+}\frac{1}{2}{‖b-Ax‖}^{2}$ $m$ by $n$ upper trapezoidal LS4 ${c}^{\mathrm{T}}x+\frac{1}{2}{‖b-Ax‖}^{2}$ $m$ by $n$ upper trapezoidal
Table 1
In the standard LS problem $F\left(x\right)$ will usually have the form LS1, and in the standard convex QP problem $F\left(x\right)$ will usually have the form QP2. The default problem type is LS1 and other objective functions are selected by using the optional parameter Problem Type.
When $A$ is upper trapezoidal it will usually be the case that $m=n$, so that $A$ is upper triangular, but full generality has been allowed for in the specification of the problem. The upper trapezoidal form is intended for cases where a previous factorization, such as a $QR$ factorization, has been performed.
The constraints involving ${\mathbf{c}}$ are called the general constraints. Note that upper and lower bounds are specified for all the variables and for all the general constraints. An equality constraint can be specified by setting ${l}_{i}={u}_{i}$. If certain bounds are not present, the associated elements of $l$ or $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.)
The defining feature of a quadratic function $F\left(x\right)$ is that the second-derivative matrix $H$ (the Hessian matrix) is constant. For the LP case $H=0$; for QP1 and QP2, $H=A$; for QP3 and QP4, $H={A}^{\mathrm{T}}A$ and for LS1 (the default), LS2, LS3 and LS4, $H={A}^{\mathrm{T}}A$.
Problems of type QP3 and QP4 for which $A$ is not in upper trapezoidal form should be solved as types LS1 and LS2 respectively, with $b=0$.
For problems of type LS, we refer to $A$ as the least squares matrix, or the matrix of observations and to $b$ as the vector of observations.
You must supply an initial estimate of the solution.
If $H$ is nonsingular then nag_opt_lsq_lincon_solve (e04nc) will obtain the unique (global) minimum. If $H$ is singular then the solution may still be a global minimum if all active constraints have nonzero Lagrange multipliers. Otherwise the solution obtained will be either a weak minimum (i.e., with a unique optimal objective value, but an infinite set of optimal $x$), or else the objective function is unbounded below in the feasible region. The last case can only occur when $F\left(x\right)$ contains an explicit linear term (as in problems LP, QP2, QP4, LS2 and LS4).
The method used by nag_opt_lsq_lincon_solve (e04nc) is described in detail in Algorithmic Details.

## References

Gill P E, Hammarling S, Murray W, Saunders M A and Wright M H (1986) Users' guide for LSSOL (Version 1.0) Report SOL 86-1 Department of Operations Research, Stanford University
Gill P E, Murray W, Saunders M A and Wright M H (1984) Procedures for optimization problems with a mixture of bounds and general linear constraints ACM Trans. Math. Software 10 282–298
Gill P E, Murray W and Wright M H (1981) Practical Optimization Academic Press
Stoer J (1971) On the numerical solution of constrained least squares problems SIAM J. Numer. Anal. 8 382–411

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{c}\left(\mathit{ldc},:\right)$ – double array
The first dimension of the array c must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nclin}}\right)$.
The second dimension of the array c must be at least ${\mathbf{n}}$ if ${\mathbf{nclin}}>0$, and at least $1$ otherwise.
The $\mathit{i}$th row of c must contain the coefficients of the $\mathit{i}$th general constraint, for $\mathit{i}=1,2,\dots ,{\mathbf{nclin}}$.
If ${\mathbf{nclin}}=0$, c is not referenced.
2:     $\mathrm{bl}\left({\mathbf{n}}+{\mathbf{nclin}}\right)$ – double array
3:     $\mathrm{bu}\left({\mathbf{n}}+{\mathbf{nclin}}\right)$ – double array
bl must contain the lower bounds and bu the upper bounds, for all the constraints, in the following order. The first $n$ elements of each array must contain the bounds on the variables, and the next ${n}_{L}$ elements must contain the bounds for the general linear constraints (if any). To specify a nonexistent lower bound (i.e., ${l}_{j}=-\infty$), set ${\mathbf{bl}}\left(j\right)\le -\mathit{bigbnd}$, and to specify a nonexistent upper bound (i.e., ${u}_{j}=+\infty$), set ${\mathbf{bu}}\left(j\right)\ge \mathit{bigbnd}$; the default value of $\mathit{bigbnd}$ is ${10}^{20}$, but this may be changed by the optional parameter Infinite Bound Size. To specify the $j$th constraint as an equality, set ${\mathbf{bu}}\left(j\right)={\mathbf{bl}}\left(j\right)=\beta$, say, where $\left|\beta \right|<\mathit{bigbnd}$.
Constraints:
• ${\mathbf{bl}}\left(\mathit{j}\right)\le {\mathbf{bu}}\left(\mathit{j}\right)$, for $\mathit{j}=1,2,\dots ,{\mathbf{n}}+{\mathbf{nclin}}$;
• if ${\mathbf{bl}}\left(j\right)={\mathbf{bu}}\left(j\right)=\beta$, $\left|\beta \right|<\mathit{bigbnd}$.
4:     $\mathrm{cvec}\left(:\right)$ – double array
The dimension of the array cvec must be at least ${\mathbf{n}}$ if the problem is of type LP, QP2, QP4, LS2 or LS4, and at least $1$ otherwise
The coefficients of the explicit linear term of the objective function.
If the problem is of type FP, QP1, QP3, LS1 (the default) or LS3, cvec is not referenced.
5:     $\mathrm{istate}\left({\mathbf{n}}+{\mathbf{nclin}}\right)$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, istate specifies the desired status of the constraints at the start of the feasibility phase. More precisely, the first $n$ elements of istate refer to the upper and lower bounds on the variables, and the next ${n}_{L}$ elements refer to the general linear constraints (if any). Possible values for ${\mathbf{istate}}\left(j\right)$ are as follows:
 ${\mathbf{istate}}\left(j\right)$ Meaning 0 The constraint should not be in the initial working set. 1 The constraint should be in the initial working set at its lower bound. 2 The constraint should be in the initial working set at its upper bound. 3 The constraint should be in the initial working set as an equality. This value must not be specified unless ${\mathbf{bl}}\left(j\right)={\mathbf{bu}}\left(j\right)$.
The values $-2$, $-1$ and $4$ are also acceptable but will be reset to zero by the function. If nag_opt_lsq_lincon_solve (e04nc) has been called previously with the same values of n and nclin, 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: $-2\le {\mathbf{istate}}\left(\mathit{j}\right)\le 4$, for $\mathit{j}=1,2,\dots ,{\mathbf{n}}+{\mathbf{nclin}}$.
6:     $\mathrm{kx}\left({\mathbf{n}}\right)$int64int32nag_int array
Need not be initialized for problems of type FP, LP, QP1, QP2, LS1 (the default) or LS2.
For problems QP3, QP4, LS3 or LS4, kx must specify the order of the columns of the matrix $A$ with respect to the ordering of x. Thus if column $j$ of $A$ is the column associated with the variable ${x}_{i}$ then ${\mathbf{kx}}\left(j\right)=i$.
Constraints:
• $1\le {\mathbf{kx}}\left(\mathit{i}\right)\le {\mathbf{n}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$;
• if $i\ne j$, ${\mathbf{kx}}\left(i\right)\ne {\mathbf{kx}}\left(j\right)$.
7:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
An initial estimate of the solution.
Note: that it may be best to avoid the choice ${\mathbf{x}}=0.0$.
8:     $\mathrm{a}\left(\mathit{lda},:\right)$ – double array
The first dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
The second dimension of the array a must be at least ${\mathbf{n}}$ if the problem is of type QP1, QP2, QP3, QP4, LS1 (the default), LS2, LS3 or LS4, and at least $1$ otherwise.
The array a must contain the matrix $A$ as specified in Table 1 (see Description).
If the problem is of type QP1 or QP2, the first $m$ rows and columns of a must contain the leading $m$ by $m$ rows and columns of the symmetric Hessian matrix. Only the diagonal and upper triangular elements of the leading $m$ rows and columns of a are referenced. The remaining elements are assumed to be zero and need not be assigned.
For problems QP3, QP4, LS3 or LS4, the first $m$ rows of a must contain an $m$ by $n$ upper trapezoidal factor of either the Hessian matrix or the least squares matrix, ordered according to the kx array. The factor need not be of full rank, i.e., some of the diagonals may be zero. However, as a general rule, the larger the dimension of the leading nonsingular sub-matrix of $A$, the fewer iterations will be required. Elements outside the upper triangular part of the first $m$ rows of a are assumed to be zero and need not be assigned.
If a constrained least squares problem contains a very large number of observations, storage limitations may prevent storage of the entire least squares matrix. In such cases, you should transform the original $A$ into a triangular matrix before the call to nag_opt_lsq_lincon_solve (e04nc) and solve the problem as type LS3 or LS4.
9:     $\mathrm{b}\left(:\right)$ – double array
The dimension of the array b must be at least ${\mathbf{m}}$ if the problem is of type LS1 (the default), LS2, LS3 or LS4, and at least $1$ otherwise
The $m$ elements of the vector of observations.
10:   $\mathrm{lwsav}\left(120\right)$ – logical array
11:   $\mathrm{iwsav}\left(610\right)$int64int32nag_int array
12:   $\mathrm{rwsav}\left(475\right)$ – double array
The arrays lwsav, iwsav and rwsav must not be altered between calls to any of the functions nag_opt_lsq_lincon_solve (e04nc), nag_opt_lsq_lincon_option_string (e04ne).

### Optional Input Parameters

1:     $\mathrm{m}$int64int32nag_int scalar
Default: the dimension of the array a.
$m$, the number of rows in the matrix $A$. If the problem is specified as type FP or LP, m is not referenced and is assumed to be zero.
If the problem is of type QP, m will usually be $n$, the number of variables. However, a value of m less than $n$ is appropriate for QP3 or QP4 if $A$ is an upper trapezoidal matrix with $m$ rows. Similarly, m may be used to define the dimension of a leading block of nonzeros in the Hessian matrices of QP1 or QP2, in which case the last $\left(n-m\right)$ rows and columns of a are assumed to be zero. In the QP case, $m$ should not be greater than $n$; if it is, the last $\left(m-n\right)$ rows of $A$ are ignored.
If the problem is of type LS1 (the default) or specified as type LS2, LS3 or LS4, m is also the dimension of the array b. Note that all possibilities ($m, $m=n$ and $m>n$) are allowed in this case.
Constraint: ${\mathbf{m}}>0$ if the problem is not of type FP or LP.
2:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the arrays kx, x. (An error is raised if these dimensions are not equal.)
$n$, the number of variables.
Constraint: ${\mathbf{n}}>0$.
3:     $\mathrm{nclin}$int64int32nag_int scalar
Default: the dimension of the array c.
${n}_{L}$, the number of general linear constraints.
Constraint: ${\mathbf{nclin}}\ge 0$.

### Output Parameters

1:     $\mathrm{istate}\left({\mathbf{n}}+{\mathbf{nclin}}\right)$int64int32nag_int array
The status of the constraints in the working set at the point returned in x. The significance of each possible value of ${\mathbf{istate}}\left(j\right)$ is as follows:
 ${\mathbf{istate}}\left(j\right)$ Meaning $-2$ The constraint violates its lower bound by more than the feasibility tolerance. $-1$ The constraint violates its upper bound by more than the feasibility tolerance. $\phantom{-}0$ The constraint is satisfied to within the feasibility tolerance, but is not in the working set. $\phantom{-}1$ This inequality constraint is included in the working set at its lower bound. $\phantom{-}2$ This inequality constraint is included in the working set at its upper bound. $\phantom{-}3$ The constraint is included in the working set as an equality. This value of istate can occur only when ${\mathbf{bl}}\left(j\right)={\mathbf{bu}}\left(j\right)$. $\phantom{-}4$ This corresponds to optimality being declared with ${\mathbf{x}}\left(j\right)$ being temporarily fixed at its current value.
2:     $\mathrm{kx}\left({\mathbf{n}}\right)$int64int32nag_int array
Defines the order of the columns of a with respect to the ordering of x, as described above.
3:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
The point at which nag_opt_lsq_lincon_solve (e04nc) terminated. If ${\mathbf{ifail}}={\mathbf{0}}$, ${\mathbf{1}}$ or ${\mathbf{4}}$, x contains an estimate of the solution.
4:     $\mathrm{a}\left(\mathit{lda},:\right)$ – double array
The first dimension of the array a will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
The second dimension of the array a will be ${\mathbf{n}}$ if the problem is of type QP1, QP2, QP3, QP4, LS1 (the default), LS2, LS3 or LS4 and $1$ otherwise.
If ${\mathbf{Hessian}}=\mathrm{NO}$ and the problem is of type LS or QP, a contains the upper triangular Cholesky factor $R$ of (8) (see Main Iteration), with columns ordered as indicated by kx. If ${\mathbf{Hessian}}=\mathrm{YES}$ and the problem is of type LS or QP, a contains the upper triangular Cholesky factor $R$ of the Hessian matrix $H$, with columns ordered as indicated by kx. In either case $R$ may be used to obtain the variance-covariance matrix or to recover the upper triangular factor of the original least squares matrix.
If the problem is of type FP or LP, a is not referenced.
5:     $\mathrm{b}\left(:\right)$ – double array
The dimension of the array b will be ${\mathbf{m}}$ if the problem is of type LS1 (the default), LS2, LS3 or LS4 and $1$ otherwise
The transformed residual vector of equation (10) (see Main Iteration).
If the problem is of type FP, LP, QP1, QP2, QP3 or QP4, b is not referenced.
6:     $\mathrm{iter}$int64int32nag_int scalar
The total number of iterations performed.
7:     $\mathrm{obj}$ – double scalar
The value of the objective function at $x$ if $x$ is feasible, or the sum of infeasibiliites at $x$ otherwise. If the problem is of type FP and $x$ is feasible, obj is set to zero.
8:     $\mathrm{clamda}\left({\mathbf{n}}+{\mathbf{nclin}}\right)$ – double array
The values of the Lagrange multipliers for each constraint with respect to the current working set. The first $n$ elements contain the multipliers for the bound constraints on the variables, and the next ${n}_{L}$ elements contain the multipliers for the general linear constraints (if any). If ${\mathbf{istate}}\left(j\right)=0$ (i.e., constraint $j$ is not in the working set), ${\mathbf{clamda}}\left(j\right)$ is zero. If $x$ is optimal, ${\mathbf{clamda}}\left(j\right)$ should be non-negative if ${\mathbf{istate}}\left(j\right)=1$, non-positive if ${\mathbf{istate}}\left(j\right)=2$ and zero if ${\mathbf{istate}}\left(j\right)=4$.
9:     $\mathrm{lwsav}\left(120\right)$ – logical array
10:   $\mathrm{iwsav}\left(610\right)$int64int32nag_int array
11:   $\mathrm{rwsav}\left(475\right)$ – double array
12:   $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).
nag_opt_lsq_lincon_solve (e04nc) returns with ${\mathbf{ifail}}={\mathbf{0}}$ if $x$ is a strong local minimizer, i.e., the projected gradient (Norm Gz; see Printed output) is negligible, the Lagrange multipliers (Lagr Mult; see Definition of Search Direction) are optimal and ${R}_{Z}$ (see Main Iteration) is nonsingular.

## Error Indicators and Warnings

Note: nag_opt_lsq_lincon_solve (e04nc) 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  ${\mathbf{ifail}}=1$
x is a weak local minimum, (i.e., the projected gradient is negligible, the Lagrange multipliers are optimal, but either ${R}_{Z}$ (see Main Iteration) is singular, or there is a small multiplier). This means that $x$ is not unique.
W  ${\mathbf{ifail}}=2$
The solution appears to be unbounded. This value of ifail implies that a step as large as Infinite Bound Size ($\text{default value}={10}^{20}$) would have to be taken in order to continue the algorithm. This situation can occur only when $A$ is singular, there is an explicit linear term, and at least one variable has no upper or lower bound.
W  ${\mathbf{ifail}}=3$
No feasible point was found, i.e., it was not possible to satisfy all the constraints to within the feasibility tolerance. In this case, the constraint violations at the final $x$ will reveal a value of the tolerance for which a feasible point will exist – for example, when the feasibility tolerance for each violated constraint exceeds its Slack (see Printed output) at the final point. The modified problem (with an altered feasibility tolerance) may then be solved using a Warm Start. You should check that there are no constraint redundancies. If the data for the constraints are accurate only to the absolute precision $\sigma$, you should ensure that the value of the optional parameter Feasibility Tolerance ($\text{default value}=\sqrt{\epsilon }$, where $\epsilon$ is the machine precision) is greater than $\sigma$. For example, if all elements of ${\mathbf{c}}$ are of order unity and are accurate only to three decimal places, the Feasibility Tolerance should be at least ${10}^{-3}$.
${\mathbf{ifail}}=4$
The limiting number of iterations (determined by the optional parameters Feasibility Phase Iteration Limit ($\text{default value}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,5\left(n+{n}_{L}\right)\right)$) and Optimality Phase Iteration Limit ($\text{default value}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,5\left(n+{n}_{L}\right)\right)$)) was reached before normal termination occurred. If the method appears to be making progress (e.g., the objective function is being satisfactorily reduced), either increase the iterations limit and rerun nag_opt_lsq_lincon_solve (e04nc) or, alternatively, rerun nag_opt_lsq_lincon_solve (e04nc) using the Warm Start facility to specify the initial working set. If the iteration limit is already large, but some of the constraints could be nearly linearly dependent, check the monitoring information (see Description of Monitoring Information) for a repeated pattern of constraints entering and leaving the working set. (Near-dependencies are often indicated by wide variations in size in the diagonal elements of the matrix $T$ (see Definition of Search Direction), which will be printed if ${\mathbf{Print Level}}\ge 30$ ($\text{default value}=10$). In this case, the algorithm could be cycling (see the comments for ${\mathbf{ifail}}={\mathbf{5}}$).
${\mathbf{ifail}}=5$
The algorithm could be cycling, since a total of $50$ changes were made to the working set without altering $x$. You should check the monitoring information (see Description of Monitoring Information) for a repeated pattern of constraint deletions and additions.
If a sequence of constraint changes is being repeated, the iterates are probably cycling. (nag_opt_lsq_lincon_solve (e04nc) does not contain a method that is guaranteed to avoid cycling; such a method would be combinatorial in nature.) Cycling may occur in two circumstances: at a constrained stationary point where there are some small or zero Lagrange multipliers; or at a point (usually a vertex) where the constraints that are satisfied exactly are nearly linearly dependent. In the latter case, you have the option of identifying the offending dependent constraints and removing them from the problem, or restarting the run with a larger value of the optional parameter Feasibility Tolerance ($\text{default value}=\sqrt{\epsilon }$, where $\epsilon$ is the machine precision). If nag_opt_lsq_lincon_solve (e04nc) terminates with ${\mathbf{ifail}}={\mathbf{5}}$, but no suspicious pattern of constraint changes can be observed, it may be worthwhile to restart with the final $x$ (with or without the Warm Start option).
Note:  that this error exit may also occur if a poor starting point x is supplied (for example, ${\mathbf{x}}=0.0$). You are advised to try a non-zero starting point.
${\mathbf{ifail}}=6$
An input argument is invalid.
${\mathbf{ifail}}=7$
The problem to be solved is of type QP1 or QP2, but the Hessian matrix supplied in a is not positive semidefinite.
$\mathbf{\text{Overflow}}$
If the printed output before the overflow error contains a warning about serious ill-conditioning in the working set when adding the $j$th constraint, it may be possible to avoid the difficulty by increasing the magnitude of the Feasibility Tolerance ($\text{default value}=\sqrt{\epsilon }$, where $\epsilon$ is the machine precision) and rerunning the program. If the message recurs even after this change, the offending linearly dependent constraint (with index ‘$j$’) must be removed from the problem.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

nag_opt_lsq_lincon_solve (e04nc) implements a numerically stable active set strategy and returns solutions that are as accurate as the condition of the problem warrants on the machine.

This section contains some comments on scaling and a description of the printed output.

### Scaling

Sensible scaling of the problem is likely to reduce the number of iterations required and make the problem less sensitive to perturbations in the data, thus improving the condition of the problem. In the absence of better information it is usually sensible to make the Euclidean lengths of each constraint of comparable magnitude. See the E04 Chapter Introduction and Gill et al. (1981) for further information and advice.

### Description of the Printed Output

This section describes the intermediate printout and final printout produced by nag_opt_lsq_lincon_solve (e04nc). The intermediate printout is a subset of the monitoring information produced by the function at every iteration (see Description of Monitoring Information). You can control the level of printed output (see the description of the optional parameter Print Level). Note that the intermediate printout and final printout are produced only if ${\mathbf{Print Level}}\ge 10$ (the default for nag_opt_lsq_lincon_solve (e04nc), by default no output is produced by nag_opt_lsq_lincon_solve (e04nc)).
The following line of summary output ($\text{}<80$ characters) is produced at every iteration. In all cases, the values of the quantities printed are those in effect on completion of the given iteration.
 Itn is the iteration count. Step is the step taken along the computed search direction. If a constraint is added during the current iteration (i.e., Jadd is positive), Step will be the step to the nearest constraint. During the optimality phase, the step can be greater than one only if the factor ${R}_{Z}$ is singular. (See Main Iteration.) Ninf is the number of violated constraints (infeasibilities). This will be zero during the optimality phase. Sinf/Objective is the value of the current objective function. If $x$ is not feasible, Sinf gives a weighted sum of the magnitudes of constraint violations. If $x$ is feasible, Objective is the value of the objective function of (1). The output line for the final iteration of the feasibility phase (i.e., the first iteration for which Ninf is zero) will give the value of the true objective at the first feasible point.During the optimality phase the value of the objective function will be nonincreasing. During the feasibility phase the number of constraint infeasibilities will not increase until either a feasible point is found or the optimality of the multipliers implies that no feasible point exists. Once optimal multipliers are obtained the number of infeasibilities can increase, but the sum of infeasibilities will either remain constant or be reduced until the minimum sum of infeasibilities is found. Norm Gz is $‖{Z}_{1}^{\mathrm{T}}{g}_{\mathrm{FR}}‖$, the Euclidean norm of the reduced gradient with respect to ${Z}_{1}$. During the optimality phase, this norm will be approximately zero after a unit step. (See Definition of Search Direction and Main Iteration.)
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 $\mathit{j}$, for $\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 ${\mathbf{bl}}\left(j\right)\le -\mathit{bigbnd}$.
Upper Bound is the upper bound specified for the variable. None indicates that ${\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 ${\mathbf{bl}}\left(j\right)\le -\mathit{bigbnd}$ and ${\mathbf{bu}}\left(j\right)\ge \mathit{bigbnd}$, in which case the entry will be blank. If $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 ${\mathbf{bl}}\left(j\right)$ and ${\mathbf{bu}}\left(j\right)$. A blank entry indicates that the associated variable is not bounded (i.e., ${\mathbf{bl}}\left(j\right)\le -\mathit{bigbnd}$ and ${\mathbf{bu}}\left(j\right)\ge \mathit{bigbnd}$).
The meaning of the printout for general constraints is the same as that given above for variables, with ‘variable’ replaced by ‘constraint’, ${\mathbf{bl}}\left(j\right)$ and ${\mathbf{bu}}\left(j\right)$ are replaced by ${\mathbf{bl}}\left(n+j\right)$ and ${\mathbf{bu}}\left(n+j\right)$ respectively, and with the following change in the heading:
 L Con gives the name (L) and index $\mathit{j}$, for $\mathit{j}=1,2,\dots ,{n}_{L}$, of the linear 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

This example minimizes the function $\frac{1}{2}{‖b-Ax‖}^{2}$, where
 $A= 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 0 0 1 1 3 1 1 1 -1 -1 -3 1 1 1 4 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 2 1 1 0 0 0 -1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 2 2 3 1 0 1 1 1 1 0 2 2 and b= 1 1 1 1 1 1 1 1 1 1$
subject to the bounds
 $0≤x1≤2 0≤x2≤2 -∞≤x3≤2 0≤x4≤2 0≤x5≤2 0≤x6≤2 0≤x7≤2 0≤x8≤2 0≤x9≤2$
and to the general constraints
 $2.0 ≤ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + 4x9 ≤ ∞ -∞ ≤ x1 + 2x2 + 3x3 + 4x4 - 2x5 + x6 + x7 + x8 + x9 ≤ 2.0 1.0 ≤ x1 - x2 + x3 - x4 + x5 + x6 + x7 + x8 + x9 ≤ 4.0$
The initial point, which is infeasible, is
 $x0=1.0,0.5,0.3333,0.25,0.2,0.1667,0.1428,0.125,0.1111T,$
and $F\left({x}_{0}\right)=9.4746$ (to five figures).
The optimal solution (to five figures) is
 $x*=0.0,0.041526,0.58718,0.0,0.099643,0.0,0.04906,0.0,0.30565T,$
and $F\left({x}^{*}\right)=0.081341$. Four bound constraints and all three general constraints are active at the solution.
```function e04nc_example

fprintf('e04nc example results\n\n');

% Problem specification
n     = 9;
m     = 10;
nclin = 3;
c  = [1,    1,    1,       1,     1,    1,       1,       1,      4;
1,    2,    3,       4,    -2,    1,       1,       1,      1;
1,   -1,    1,      -1,     1,    1,       1,       1,      1];
x  = [1;    0.5;  0.3333;  0.25;  0.2;  0.1667;  0.1428;  0.125;  0.1111];
a  = [1,    1,    1,       1,     1,    1,       1,       1,      1;
1,    2,    1,       1,     1,    1,       2,       0,      0;
1,    1,    3,       1,     1,    1,      -1,      -1,     -3;
1,    1,    1,       4,     1,    1,       1,       1,      1;
1,    1,    1,       3,     1,    1,       1,       1,      1;
1,    1,    2,       1,     1,    0,       0,       0,     -1;
1,    1,    1,       1,     0,    1,       1,       1,      1;
1,    1,    1,       0,     1,    1,       1,       1,      1;
1,    1,    0,       1,     1,    1,       2,       2,      3;
1,    0,    1,       1,     1,    1,       0,       2,      2 ];

b(1:m)  =  1;
bl(1:n) =  0;
bl(3)   = -1e25;
bu(1:n) =  2;
bl(n+1:n+nclin) = [        2; -1e25;    1];
bu(n+1:n+nclin) = [     1e25;     2;    4];

cvec   = [0];
istate = zeros(12, 1, 'int64');
kx     = zeros(9, 1, 'int64');

% Initialize and set no printing options
[cwsav,lwsav,iwsav,rwsav,ifail] = e04wb('e04nc');
[lwsav,iwsav,rwsav,inform] = e04ne(...
'NoList', lwsav, iwsav, rwsav);
[lwsav,iwsav,rwsav,inform] = e04ne(...
'Print Level = 0', lwsav, iwsav, rwsav);

% Solve
[istate, kx, x, a, b, iter, obj, clamda, lwsav, iwsav, rwsav, ifail] = ...
e04nc(...
c, bl, bu, cvec, istate, kx, x, a, b, lwsav, iwsav, rwsav);

fprintf('Minimum value     :  %9.4f\n\n',obj);
fprintf('Found after %3d iterations at x:\n',iter);
fprintf('    %9.4f %9.4f %9.4f\n',x);

```
```e04nc example results

Minimum value     :     0.0813

Found after  15 iterations at x:
0.0000    0.0415    0.5872
0.0000    0.0996    0.0000
0.0491    0.0000    0.3056
```
Note: the remainder of this document is intended for more advanced users. Algorithmic Details contains a detailed description of the algorithm which may be needed in order to understand Optional Parameters and Description of Monitoring Information. Optional Parameters describes the optional parameters which may be set by calls to nag_opt_lsq_lincon_option_string (e04ne). Description of Monitoring Information describes the quantities which can be requested to monitor the course of the computation.

## Algorithmic Details

This section contains a detailed description of the method used by nag_opt_lsq_lincon_solve (e04nc).

### Overview

nag_opt_lsq_lincon_solve (e04nc) is essentially identical to the function LSSOL described in Gill et al. (1986). It is based on a two-phase (primal) quadratic programming method with features to exploit the convexity of the objective function due to Gill et al. (1984). (In the full-rank case, the method is related to that of Stoer (1971).) nag_opt_lsq_lincon_solve (e04nc) has two phases: finding an initial feasible point by minimizing the sum of infeasibilities (the feasibility phase), and minimizing the quadratic objective function within the feasible region (the optimality phase). The two-phase nature of the algorithm is reflected by changing the function being minimized from the sum of infeasibilities to the quadratic objective function. The feasibility phase does not perform the standard simplex method (i.e., it does not necessarily find a vertex), except in the LP case when ${n}_{L}\le n$. Once any iterate is feasible, all subsequent iterates remain feasible.
nag_opt_lsq_lincon_solve (e04nc) has been designed to be efficient when used to solve a sequence of related problems – for example, within a sequential quadratic programming method for nonlinearly constrained optimization (e.g., nag_opt_nlp1_rcomm (e04uf) or nag_opt_nlp2_solve (e04wd)). In particular, you may specify an initial working set (the indices of the constraints believed to be satisfied exactly at the solution); see the discussion of the optional parameter Warm Start.
In general, an iterative process is required to solve a quadratic program. (For simplicity, we shall always consider a typical iteration and avoid reference to the index of the iteration.) Each new iterate $\stackrel{-}{x}$ is defined by
 $x-=x+αp,$ (2)
where the step length $\alpha$ is a non-negative scalar, and $p$ is called the search direction.
At each point $x$, a working set of constraints is defined to be a linearly independent subset of the constraints that are satisfied ‘exactly’ (to within the tolerance defined by the optional parameter Feasibility Tolerance). The working set is the current prediction of the constraints that hold with equality at a solution of (1). The search direction is constructed so that the constraints in the working set remain unaltered for any value of the step length. For a bound constraint in the working set, this property is achieved by setting the corresponding element of the search direction to zero. Thus, the associated variable is fixed, and specification of the working set induces a partition of $x$ into fixed and free variables. During a given iteration, the fixed variables are effectively removed from the problem; since the relevant elements of the search direction are zero, the columns of ${\mathbf{c}}$ corresponding to fixed variables may be ignored.
Let ${n}_{\mathrm{W}}$ denote the number of general constraints in the working set and let ${n}_{\mathrm{FX}}$ denote the number of variables fixed at one of their bounds (${n}_{\mathrm{W}}$ and ${n}_{\mathrm{FX}}$ are the quantities Lin and Bnd in the monitoring file output from nag_opt_lsq_lincon_solve (e04nc); see Description of Monitoring Information). Similarly, let ${n}_{\mathrm{FR}}\left({n}_{\mathrm{FR}}=n-{n}_{\mathrm{FX}}\right)$ denote the number of free variables. At every iteration, the variables are reordered so that the last ${n}_{\mathrm{FX}}$ variables are fixed, with all other relevant vectors and matrices ordered accordingly. The order of the variables is indicated by the contents of the array kx on exit (see Arguments).

### Definition of Search Direction

Let ${C}_{\mathrm{FR}}$ denote the ${n}_{\mathrm{W}}$ by ${n}_{\mathrm{FR}}$ sub-matrix of general constraints in the working set corresponding to the free variables, and let ${p}_{\mathrm{FR}}$ denote the search direction with respect to the free variables only. The general constraints in the working set will be unaltered by any move along $p$ if
 $CFRpFR=0.$ (3)
In order to compute ${p}_{\mathrm{FR}}$, the $TQ$ factorization of ${C}_{\mathrm{FR}}$ is used:
 $CFRQFR=0 T$ (4)
where $T$ is a nonsingular ${n}_{\mathrm{W}}$ by ${n}_{\mathrm{W}}$ reverse-triangular matrix (i.e., ${t}_{ij}=0$ if $i+j<{n}_{\mathrm{W}}$), and the nonsingular ${n}_{\mathrm{FR}}$ by ${n}_{\mathrm{FR}}$ matrix ${Q}_{\mathrm{FR}}$ is the product of orthogonal transformations (see Gill et al. (1984)). If the columns of ${Q}_{\mathrm{FR}}$ are partitioned so that
 $QFR=Z Y,$ (5)
where $Y$ is ${n}_{\mathrm{FR}}$ by ${n}_{\mathrm{W}}$, then the ${n}_{Z}\left({n}_{Z}={n}_{\mathrm{FR}}-{n}_{\mathrm{W}}\right)$ columns of $Z$ form a basis for the null space of ${C}_{\mathrm{FR}}$. Let ${n}_{R}$ be an integer such that $0\le {n}_{R}\le {n}_{Z}$, and let ${Z}_{1}$ denote a matrix whose ${n}_{R}$ columns are a subset of the columns of $Z$. (The integer ${n}_{R}$ is the quantity Zr in the monitoring file output from nag_opt_lsq_lincon_solve (e04nc). In many cases, ${Z}_{1}$ will include all the columns of $Z$.) The direction ${p}_{\mathrm{FR}}$ will satisfy (3) if
 $pFR=Z1pZ$ (6)
where ${p}_{Z}$ is any ${n}_{R}$-vector.

### Main Iteration

Let $Q$ denote the $n$ by $n$ matrix
 $Q= QFR IFX ,$ (7)
where ${I}_{\mathrm{FX}}$ is the identity matrix of order ${n}_{\mathrm{FX}}$. Let $R$ denote an $n$ by $n$ upper triangular matrix (the Cholesky factor) such that
 $RTR=HQ≡QTH~Q,$ (8)
where $\stackrel{~}{H}$ is the Hessian $H$ with rows and columns permuted so that the free variables are first.
Let the matrix of the first ${n}_{Z}$ rows and columns of $R$ be denoted by ${R}_{Z}$. The definition of ${p}_{Z}$ in (6) depends on whether or not the matrix ${R}_{Z}$ is singular at $x$. In the nonsingular case, ${p}_{Z}$ satisfies the equations
 $RZT RZ pZ = - gZ$ (9)
where ${g}_{Z}$ denotes the vector ${Z}^{\mathrm{T}}{g}_{\mathrm{FR}}$ and $g$ denotes the objective gradient. (The norm of ${g}_{\mathrm{FR}}$ is the printed quantity Norm Gf; see Description of Monitoring Information.) When ${p}_{Z}$ is defined by (9), $x+p$ is the minimizer of the objective function subject to the constraints (bounds and general) in the working set treated as equalities. In general, a vector ${f}_{Z}$ is available such that ${R}_{Z}^{\mathrm{T}}{f}_{Z}=-{g}_{Z}$, which allows ${p}_{Z}$ to be computed from a single back-substitution ${R}_{Z}{p}_{Z}={f}_{Z}$. For example, when solving problem LS1, ${f}_{Z}$ comprises the first ${n}_{Z}$ elements of the transformed residual vector
 $f=Pb-Ax,$ (10)
which is recurred from one iteration to the next, where $P$ is an orthogonal matrix.
In the singular case, ${p}_{Z}$ is defined such that
 $RZ pZ = 0 and gZT pZ < 0 .$ (11)
This vector has the property that the objective function is linear along $p$ and may be reduced by any step of the form $x+\alpha p$, where $\alpha >0$.
The vector ${Z}^{\mathrm{T}}{g}_{\mathrm{FR}}$ is known as the projected gradient at $x$. If the projected gradient is zero, $x$ is a constrained stationary point in the subspace defined by $Z$. During the feasibility phase, the projected gradient will usually be zero only at a vertex (although it may be zero at non-vertices in the presence of constraint dependencies). During the optimality phase, a zero projected gradient implies that $x$ minimizes the quadratic objective when the constraints in the working set are treated as equalities. At a constrained stationary point, Lagrange multipliers ${\lambda }_{{\mathbf{c}}}$ and ${\lambda }_{{\mathbf{b}}}$ for the general and bound constraints are defined from the equations
 $CFRTλC=gFRand ​λB=gFX-CFXTλC.$ (12)
Given a positive constant $\delta$ of the order of the machine precision, the Lagrange multiplier ${\lambda }_{j}$ corresponding to an inequality constraint in the working set is said to be optimal if ${\lambda }_{j}\le \delta$ when the associated constraint is at its upper bound, or if ${\lambda }_{j}\ge -\delta$ when the associated constraint is at its lower bound. If a multiplier is nonoptimal, the objective function (either the true objective or the sum of infeasibilities) can be reduced by deleting the corresponding constraint (with index Jdel; see Description of Monitoring Information) from the working set.
If optimal multipliers occur during the feasibility phase and the sum of infeasibilities is nonzero, there is no feasible point, and nag_opt_lsq_lincon_solve (e04nc) will continue until the minimum value of the sum of infeasibilities has been found. At this point, the Lagrange multiplier ${\lambda }_{j}$ corresponding to an inequality constraint in the working set will be such that $-\left(1+\delta \right)\le {\lambda }_{j}\le \delta$ when the associated constraint is at its upper bound, and $-\delta \le {\lambda }_{j}\le \left(1+\delta \right)$ when the associated constraint is at its lower bound. Lagrange multipliers for equality constraints will satisfy $\left|{\lambda }_{j}\right|\le 1+\delta$.
The choice of step length is based on remaining feasible with respect to the satisfied constraints. If ${R}_{Z}$ is nonsingular and $x+p$ is feasible, $\alpha$ will be taken as unity. In this case, the projected gradient at $\stackrel{-}{x}$ will be zero, and Lagrange multipliers are computed. Otherwise, $\alpha$ is set to ${\alpha }_{{\mathbf{m}}}$, the step to the ‘nearest’ constraint (with index Jadd; see Description of Monitoring Information), which is added to the working set at the next iteration.
If $A$ is not input as a triangular matrix, it is overwritten by a triangular matrix $R$ satisfying (8) obtained using the Cholesky factorization in the QP case, or the $QR$ factorization in the LS case. Column interchanges are used in both cases, and an estimate is made of the rank of the triangular factor. Thereafter, the dependent rows of $R$ are eliminated from the problem.
Each change in the working set leads to a simple change to ${C}_{\mathrm{FR}}$: if the status of a general constraint changes, a row of ${C}_{\mathrm{FR}}$ is altered; if a bound constraint enters or leaves the working set, a column of ${C}_{\mathrm{FR}}$ changes. Explicit representations are recurred of the matrices $T,{Q}_{\mathrm{FR}}$ and $R$; and of vectors ${Q}^{\mathrm{T}}g$, ${Q}^{\mathrm{T}}c$ and $f$, which are related by the formulae
 $f=Pb- R 0 QTx , b≡0 for the ​ QP ​ case ,$
and
 $QTg=QTc-RTf.$
Note that the triangular factor $R$ associated with the Hessian of the original problem is updated during both the optimality and the feasibility phases.
The treatment of the singular case depends critically on the following feature of the matrix updating schemes used in nag_opt_lsq_lincon_solve (e04nc): if a given factor ${R}_{Z}$ is nonsingular, it can become singular during subsequent iterations only when a constraint leaves the working set, in which case only its last diagonal element can become zero. This property implies that a vector satisfying (11) may be found using the single back-substitution ${\stackrel{-}{R}}_{Z}{p}_{Z}={e}_{Z}$, where ${\stackrel{-}{R}}_{Z}$ is the matrix ${R}_{Z}$ with a unit last diagonal, and ${e}_{Z}$ is a vector of all zeros except in the last position. If $H$ is singular, the matrix $R$ (and hence ${R}_{Z}$) may be singular at the start of the optimality phase. However, ${R}_{Z}$ will be nonsingular if enough constraints are included in the initial working set. (The matrix with no rows and columns is positive definite by definition, corresponding to the case when ${C}_{\mathrm{FR}}$ contains ${n}_{\mathrm{FR}}$ constraints.) The idea is to include as many general constraints as necessary to ensure a nonsingular ${R}_{Z}$.
At the beginning of each phase, an upper triangular matrix ${R}_{1}$ is determined that is the largest nonsingular leading sub-matrix of ${R}_{Z}$. The use of interchanges during the factorization of $A$ tends to maximize the dimension of ${R}_{1}$. (The rank of ${R}_{1}$ is estimated using the optional parameter Rank Tolerance.) Let ${Z}_{1}$ denote the columns of $Z$ corresponding to ${R}_{1}$, and let $Z$ be partitioned as $Z=\left({Z}_{1}\text{ }{Z}_{2}\right)$. A working set for which ${Z}_{1}$ defines the null space can be obtained by including the rows of ${Z}_{2}^{\mathrm{T}}$ as ‘artificial constraints’. Minimization of the objective function then proceeds within the subspace defined by ${Z}_{1}$.
The artificially augmented working set is given by
 $C-FR= CFR Z2T ,$ (13)
so that ${p}_{\mathrm{FR}}$ will satisfy ${C}_{\mathrm{FR}}{p}_{\mathrm{FR}}=0$ and ${Z}_{2}^{\mathrm{T}}{p}_{\mathrm{FR}}=0$. By definition of the $TQ$ factorization, ${\stackrel{-}{{\mathbf{c}}}}_{\mathrm{FR}}$ automatically satisfies the following:
 $C-FRQFR= CFR Z2T QFR= CFR Z2T Z1 Z2 Y = 0 T- ,$
where
 $T-= 0 T I 0 ,$
and hence the $TQ$ factorization of (13) requires no additional work.
The matrix ${Z}_{2}$ need not be kept fixed, since its role is purely to define an appropriate null space; the $TQ$ factorization can therefore be updated in the normal fashion as the iterations proceed. No work is required to ‘delete’ the artificial constraints associated with ${Z}_{2}$ when ${Z}_{1}^{\mathrm{T}}{g}_{\mathrm{FR}}=0$, since this simply involves repartitioning ${Q}_{\mathrm{FR}}$. When deciding which constraint to delete, the ‘artificial’ multiplier vector associated with the rows of ${Z}_{2}^{\mathrm{T}}$ is equal to ${Z}_{2}^{\mathrm{T}}{g}_{\mathrm{FR}}$, and the multipliers corresponding to the rows of the ‘true’ working set are the multipliers that would be obtained if the temporary constraints were not present.
The number of columns in ${Z}_{2}$ and ${Z}_{1}$, the Euclidean norm of ${Z}_{1}^{\mathrm{T}}{g}_{\mathrm{FR}}$, and the condition estimator of ${R}_{1}$ appear in the monitoring file output as Art, Zr, Norm Gz and Cond Rz respectively (see Description of Monitoring Information).
Although the algorithm of nag_opt_lsq_lincon_solve (e04nc) does not perform simplex steps in general, there is one exception: a linear program with fewer general constraints than variables (i.e., ${n}_{L}\le n$). Use of the simplex method in this situation leads to savings in storage. At the starting point, the ‘natural’ working set (the set of constraints exactly or nearly satisfied at the starting point) is augmented with a suitable number of ‘temporary’ bounds, each of which has the effect of temporarily fixing a variable at its current value. In subsequent iterations, a temporary bound is treated as a standard constraint until it is deleted from the working set, in which case it is never added again.
One of the most important features of nag_opt_lsq_lincon_solve (e04nc) is its control of the conditioning of the working set, whose nearness to linear dependence is estimated by the ratio of the largest to smallest diagonals of the $TQ$ factor $T$ (the printed value Cond T; see Description of Monitoring Information). In constructing the initial working set, constraints are excluded that would result in a large value of Cond T. Thereafter, nag_opt_lsq_lincon_solve (e04nc) allows constraints to be violated by as much as a user-specified optional parameter Feasibility Tolerance in order to provide, whenever possible, a choice of constraints to be added to the working set at a given iteration. Let ${\alpha }_{{\mathbf{m}}}$ denote the maximum step at which $x+{\alpha }_{{\mathbf{m}}}p$ does not violate any constraint by more than its feasibility tolerance. All constraints at distance $\alpha \left(\alpha \le {\alpha }_{{\mathbf{m}}}\right)$ along $p$ from the current point are then viewed as acceptable candidates for inclusion in the working set. The constraint whose normal makes the largest angle with the search direction is added to the working set. In order to ensure that the new iterate satisfies the constraints in the working set as accurately as possible, the step taken is the exact distance to the newly added constraint. As a consequence, negative steps are occasionally permitted, since the current iterate may violate the constraint to be added by as much as the feasibility tolerance.

## Optional Parameters

Several optional parameters in nag_opt_lsq_lincon_solve (e04nc) define choices in the problem specification or the algorithm logic. In order to reduce the number of formal arguments of nag_opt_lsq_lincon_solve (e04nc) 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 Description of the s.
Optional parameters may be specified by calling nag_opt_lsq_lincon_option_string (e04ne) before a call to nag_opt_lsq_lincon_solve (e04nc).
nag_opt_lsq_lincon_option_string (e04ne) can be called to supply options directly, one call being necessary for each optional parameter. For example,
```[lwsav, iwsav, rwsav, inform] = e04ne('Print Level = 1', lwsav, iwsav, rwsav);
```
nag_opt_lsq_lincon_option_string (e04ne) 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_lincon_solve (e04nc) (unless they define invalid values) and so remain in effect for subsequent calls 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$, $i$ 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)).
Keywords and character values are case and white space insensitive.
Cold Start
Default
Warm Start
This option specifies how the initial working set is chosen. With a Cold Start, nag_opt_lsq_lincon_solve (e04nc) chooses the initial working set 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 provide a valid definition of every element of the array istate. nag_opt_lsq_lincon_solve (e04nc) 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$, $-1\text{​ or ​}4$ will be reset to zero, as will any elements which are set to $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_lincon_solve (e04nc) is called repeatedly to solve related problems.
Crash Tolerance  $r$
Default $\text{}=0.01$
This value is used in conjunction with the optional parameter Cold Start (the default value) when nag_opt_lsq_lincon_solve (e04nc) selects an initial working set. If $0\le r\le 1$, the initial working set will include (if possible) bounds or general inequality constraints that lie within $r$ of their bounds. In particular, a constraint of the form ${c}_{j}^{\mathrm{T}}x\ge l$ will be included in the initial working set if $\left|{c}_{j}^{\mathrm{T}}x-l\right|\le r\left(1+\left|l\right|\right)$. If $r<0$ or $r>1$, the default value is used.
Defaults
This special keyword may be used to reset all optional parameters to their default values.
Feasibility Phase Iteration Limit  ${i}_{1}$
Default $\text{}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,5\left(n+{n}_{L}\right)\right)$
Optimality Phase Iteration Limit  ${i}_{2}$
Default $\text{}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,5\left(n+{n}_{L}\right)\right)$
The scalars ${i}_{1}$ and ${i}_{2}$ specify the maximum number of iterations allowed in the feasibility and optimality phases. Optional parameter Optimality Phase Iteration Limit is equivalent to optional parameter Iteration Limit. Setting ${i}_{2}=0$ and ${\mathbf{Print Level}}>0$ means that the workspace needed will be computed and printed, but no iterations will be performed. If ${i}_{1}<0$ or ${i}_{2}<0$, the default value is used.
Feasibility Tolerance  $r$
Default $\text{}=\sqrt{\epsilon }$
If $r>\epsilon$, $r$ defines the maximum acceptable absolute violation in each constraint at a ‘feasible’ point. For example, if the variables and the coefficients in the general constaints are of order unity, and the latter are correct to about $6$ decimal digits, it would be appropriate to specify $r$ as ${10}^{-6}$. If $0\le r<\epsilon$, the default value is used.
Note that a ‘feasible solution’ is a solution that satisfies the current constraints to within the tolerance $r$.
Hessian  $\overline{)\mathbf{N}}\mathbf{o}$
Default $\text{}=\mathrm{NO}$
This option controls the contents of the upper triangular matrix $R$ (see the description of a in Arguments). nag_opt_lsq_lincon_solve (e04nc) works exclusively with the transformed and reordered matrix ${H}_{Q}$ (8), and hence extra computation is required to form the Hessian itself. If ${\mathbf{Hessian}}=\mathrm{NO}$, a contains the Cholesky factor of the matrix ${H}_{Q}$ with columns ordered as indicated by kx (see Arguments). If ${\mathbf{Hessian}}=\mathrm{YES}$, a contains the Cholesky factor of the matrix $H$, with columns ordered as indicated by kx.
Infinite Bound Size  $r$
Default $\text{}={10}^{20}$
If $r>0$, $r$ defines the ‘infinite’ bound $\mathit{bigbnd}$ in the definition of the problem constraints. Any upper bound greater than or equal to $\mathit{bigbnd}$ will be regarded as $+\infty$ (and similarly any lower bound less than or equal to $-\mathit{bigbnd}$ will be regarded as $-\infty$). If $r<0$, the default value is used.
Infinite Step Size  $r$
Default $\text{}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\mathit{bigbnd},{10}^{20}\right)$
If $r>0$, $r$ specifies the magnitude of the change in variables that will be considered a step to an unbounded solution. (Note that an unbounded solution can occur only when the Hessian is singular and the objective contains an explicit linear term.) If the change in $x$ during an iteration would exceed the value of $r$, the objective function is considered to be unbounded below in the feasible region. If $r\le 0$, the default value is used.
Iteration Limit  $i$
Default $\text{}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,5\left(n+{n}_{L}\right)\right)$
Iters
Itns
See optional parameter Feasibility Phase Iteration Limit.
List
Nolist
Default for nag_opt_lsq_lincon_solve (e04nc) $\text{}={\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.
Monitoring File  $i$
Default $\text{}=-1$
If $i\ge 0$ and ${\mathbf{Print Level}}\ge 5$, monitoring information produced by nag_opt_lsq_lincon_solve (e04nc) at every iteration is sent to a file with logical unit number $i$. If $i<0$ and/or ${\mathbf{Print Level}}<5$, no monitoring information is produced.
Print Level  $i$
The value of $i$ controls the amount of printout produced by nag_opt_lsq_lincon_solve (e04nc), as indicated below. A detailed description of the printed output is given in Printed output (summary output at each iteration and the final solution) and Description of Monitoring Information (monitoring information at each iteration).
The following printout is sent to the current advisory message unit (as defined by nag_file_set_unit_advisory (x04ab)):
 $i$ Output $\phantom{\ge 0}0$ No output. $\phantom{\ge 0}1$ The final solution only. $\phantom{\ge 0}5$ One line of summary output ($\text{}<80$ characters; see Printed output) for each iteration (no printout of the final solution). $\text{}\ge 10$ The final solution and one line of summary output for each iteration.
The following printout is sent to the logical unit number defined by the optional parameter Monitoring File:
 $i$ Output $\text{}<5$ No output. $\text{}\ge 5$ One long line of output ($\text{}>80$ characters; see Description of Monitoring Information) for each iteration (no printout of the final solution). $\text{}\ge 20$ At each iteration, the Lagrange multipliers, the variables $x$, the constraint values $Cx$ and the constraint status. $\text{}\ge 30$ At each iteration, the diagonal elements of the matrix $T$ associated with the $TQ$ factorization (4) (see Definition of Search Direction) of the working set, and the diagonal elements of the upper triangular matrix $R$.
If ${\mathbf{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 is suppressed.
Problem Type  $a$
Default $=$ LS1
This option specifies the type of objective function to be minimized during the optimality phase. The following are the nine optional keywords and the dimensions of the arrays that must be specified in order to define the objective function:
 LP a and b not referenced, ${\mathbf{cvec}}\left({\mathbf{n}}\right)$; QP1 ${\mathbf{a}}\left(\mathit{lda},{\mathbf{n}}\right)$ symmetric, b and cvec not referenced; QP2 ${\mathbf{a}}\left(\mathit{lda},{\mathbf{n}}\right)$ symmetric, b not referenced, ${\mathbf{cvec}}\left({\mathbf{n}}\right)$; QP3 ${\mathbf{a}}\left(\mathit{lda},{\mathbf{n}}\right)$ upper trapezoidal, ${\mathbf{kx}}\left({\mathbf{n}}\right)$, b and cvec not referenced; QP4 ${\mathbf{a}}\left(\mathit{lda},{\mathbf{n}}\right)$ upper trapezoidal, ${\mathbf{kx}}\left({\mathbf{n}}\right)$, b not referenced, ${\mathbf{cvec}}\left({\mathbf{n}}\right)$; LS1 ${\mathbf{a}}\left(\mathit{lda},{\mathbf{n}}\right)$, ${\mathbf{b}}\left({\mathbf{m}}\right)$, cvec not referenced; LS2 ${\mathbf{a}}\left(\mathit{lda},{\mathbf{n}}\right)$, ${\mathbf{b}}\left({\mathbf{m}}\right)$, ${\mathbf{cvec}}\left({\mathbf{n}}\right)$; LS3 ${\mathbf{a}}\left(\mathit{lda},{\mathbf{n}}\right)$ upper trapezoidal, ${\mathbf{kx}}\left({\mathbf{n}}\right)$, ${\mathbf{b}}\left({\mathbf{m}}\right)$, cvec not referenced; LS4 ${\mathbf{a}}\left(\mathit{lda},{\mathbf{n}}\right)$ upper trapezoidal, ${\mathbf{kx}}\left({\mathbf{n}}\right)$, ${\mathbf{b}}\left({\mathbf{m}}\right)$, ${\mathbf{cvec}}\left({\mathbf{n}}\right)$.
For problems of type FP, the objective function is omitted and a, b and cvec are not referenced.
The following keywords are also acceptable. The minimum abbreviation of each keyword is underlined.
 $a$ Option Least LS1 Quadratic QP2 Linear LP
In addition, the keywords LS and LSQ are equivalent to the default option LS1, and the keyword QP is equivalent to the option QP2.
If $A=0$, i.e., the objective function is purely linear, the efficiency of nag_opt_lsq_lincon_solve (e04nc) may be increased by specifying $a$ as LP.
Rank Tolerance  $r$
Default $\text{}=100\epsilon$ or $10\sqrt{\epsilon }$ (see below)
Note that this option does not apply to problems of type FP or LP.
The default value of $r$ depends on the problem type. If $A$ occurs as a least squares matrix, as it does in problem types QP1, LS1 and LS3, then the default value of $r$ is $100\epsilon$. In all other cases, $A$ is treated as the ‘square root’ of the Hessian matrix $H$ and $r$ has the default value $10\sqrt{\epsilon }$.
This parameter enables you to control the estimate of the triangular factor ${R}_{1}$ (see Main Iteration). If ${\rho }_{i}$ denotes the function ${\rho }_{i}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left\{\left|{R}_{11}\right|,\left|{R}_{22}\right|,\dots ,\left|{R}_{ii}\right|\right\}$, the rank of $R$ is defined to be smallest index i such that $\left|{R}_{i+1,i+1}\right|\le r\left|{\rho }_{i+1}\right|$. If $r\le 0$, the default value is used.

## Description of Monitoring Information

This section describes the long line of output ($\text{}>80$ characters) which forms part of the monitoring information produced by nag_opt_lsq_lincon_solve (e04nc). (See also the description of the optional parameters Monitoring File and Print Level.) You can control the level of printed output.
To aid interpretation of the printed results, the following convention is used for numbering the constraints: indices $1$ through $n$ refer to the bounds on the variables, and indices $n+1$ through $n+{n}_{L}$ refer to the general constraints. When the status of a constraint changes, the index of the constraint is printed, along with the designation L (lower bound), U (upper bound), E (equality), F (temporarily fixed variable) or A (artificial constraint).
When ${\mathbf{Print Level}}\ge 5$ and ${\mathbf{Monitoring File}}\ge 0$, the following line of output is produced at every iteration 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.
 Itn is the iteration count. Jdel is the index of the constraint deleted from the working set. If Jdel is zero, no constraint was deleted. Jadd is the index of the constraint added to the working set. If Jadd is zero, no constraint was added. Step is the step taken along the computed search direction. If a constraint is added during the current iteration (i.e., Jadd is positive), Step will be the step to the nearest constraint. During the optimality phase, the step can be greater than one only if the factor ${R}_{Z}$ is singular. Ninf is the number of violated constraints (infeasibilities). This will be zero during the optimality phase. Sinf/Objective is the value of the current objective function. If $x$ is not feasible, Sinf gives a weighted sum of the magnitudes of constraint violations. If $x$ is feasible, Objective is the value of the objective function of (1). The output line for the final iteration of the feasibility phase (i.e., the first iteration for which Ninf is zero) will give the value of the true objective at the first feasible point.During the optimality phase the value of the objective function will be nonincreasing. During the feasibility phase the number of constraint infeasibilities will not increase until either a feasible point is found or the optimality of the multipliers implies that no feasible point exists. Once optimal multipliers are obtained the number of infeasibilities can increase, but the sum of infeasibilities will either remain constant or be reduced until the minimum sum of infeasibilities is found. 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. Art is the number of artificial constraints in the working set, i.e., the number of columns of ${Z}_{2}$ (see Main Iteration). Zr is the number of columns of ${Z}_{1}$ (see Definition of Search Direction). Zr is the dimension of the subspace in which the objective function is currently being minimized. The value of Zr is the number of variables minus the number of constraints in the working set; i.e., $\mathtt{Zr}=n-\left(\mathtt{Bnd}+\mathtt{Lin}+\mathtt{Art}\right)$.The value of ${n}_{Z}$, the number of columns of $Z$ (see Definition of Search Direction) can be calculated as ${n}_{Z}=n-\left(\mathtt{Bnd}+\mathtt{Lin}\right)$. A zero value of ${n}_{Z}$ implies that $x$ lies at a vertex of the feasible region. Norm Gz is $‖{Z}_{1}^{\mathrm{T}}{g}_{\mathrm{FR}}‖$, the Euclidean norm of the reduced gradient with respect to ${Z}_{1}$. During the optimality phase, this norm will be approximately zero after a unit step. Norm Gf is the Euclidean norm of the gradient function with respect to the free variables, i.e., variables not currently held at a bound. Cond T is a lower bound on the condition number of the working set. Cond Rz is a lower bound on the condition number of the triangular factor ${R}_{1}$ (the first Zr rows and columns of the factor ${R}_{Z}$). If the problem is specified to be of type LP or the estimated rank of the data matrix $A$ is zero then Cond Rz is not printed.

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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