# NAG CL Interfacee04pcc (bnd_​lin_​lsq)

Settings help

CL Name Style:

## 1Purpose

e04pcc solves a linear least squares problem subject to fixed lower and upper bounds on the variables.

## 2Specification

 #include
 void e04pcc (Nag_RegularizedType itype, Integer m, Integer n, double a[], Integer pda, double b[], const double bl[], const double bu[], double tol, double x[], double *rnorm, Integer *nfree, double w[], Integer indx[], NagError *fail)
The function may be called by the names: e04pcc or nag_opt_bnd_lin_lsq.

## 3Description

Given an $m×n$ matrix $A$, an $n$-vector $l$ of lower bounds, an $n$-vector $u$ of upper bounds, and an $m$-vector $b$, e04pcc computes an $n$-vector $x$ that solves the least squares problem $Ax=b$ subject to ${x}_{i}$ satisfying ${l}_{i}\le {x}_{i}\le {u}_{i}$.
A facility is provided to return a ‘regularized’ solution, which will closely approximate a minimal length solution whenever $A$ is not of full rank. A minimal length solution is the solution to the problem which has the smallest Euclidean norm.
The algorithm works by applying orthogonal transformations to the matrix and to the right-hand side to obtain within the matrix an upper triangular matrix $R$. In general the elements of $x$ corresponding to the columns of $R$ will be the candidate nonzero solutions. If a diagonal element of $R$ is small compared to the other members of $R$ then this is undesirable. $R$ will be nearly singular and the equations for $x$ thus ill-conditioned. You may specify the tolerance used to determine the relative linear dependence of a column vector for a variable moved from its initial value.
Lawson C L and Hanson R J (1974) Solving Least Squares Problems Prentice–Hall

## 5Arguments

1: $\mathbf{itype}$Nag_RegularizedType Input
On entry: provides the choice of returning a regularized solution if the matrix is not of full rank.
${\mathbf{itype}}=\mathrm{Nag_Regularized}$
Specifies that a regularized solution is to be computed.
${\mathbf{itype}}=\mathrm{Nag_NotRegularized}$
Specifies that no regularization is to take place.
Suggested value: unless there is a definite need for a minimal length solution we recommend that ${\mathbf{itype}}=\mathrm{Nag_NotRegularized}$ is used.
Constraint: ${\mathbf{itype}}=\mathrm{Nag_Regularized}$ or $\mathrm{Nag_NotRegularized}$.
2: $\mathbf{m}$Integer Input
On entry: $m$, the number of linear equations.
Constraint: ${\mathbf{m}}\ge 0$.
3: $\mathbf{n}$Integer Input
On entry: $n$, the number of variables.
Constraint: ${\mathbf{n}}\ge 0$.
4: $\mathbf{a}\left[{\mathbf{pda}}×{\mathbf{n}}\right]$double Input/Output
Note: the $\left(i,j\right)$th element of the matrix $A$ is stored in ${\mathbf{a}}\left[\left(j-1\right)×{\mathbf{pda}}+i-1\right]$.
On entry: the $m×n$ matrix $A$.
On exit: if ${\mathbf{itype}}=\mathrm{Nag_NotRegularized}$, a contains the product matrix $QA$, where $Q$ is an $m×m$ orthogonal matrix generated by e04pcc; otherwise, a is unchanged.
5: $\mathbf{pda}$Integer Input
On entry: the stride separating matrix row elements in the array a.
Constraint: ${\mathbf{pda}}\ge {\mathbf{m}}$.
6: $\mathbf{b}\left[{\mathbf{m}}\right]$double Input/Output
On entry: the right-hand side vector $b$.
On exit: if ${\mathbf{itype}}=\mathrm{Nag_NotRegularized}$, the product of $Q$ times the original vector $b$, where $Q$ is as described in argument a; otherwise, b is unchanged.
7: $\mathbf{bl}\left[{\mathbf{n}}\right]$const double Input
8: $\mathbf{bu}\left[{\mathbf{n}}\right]$const double Input
On entry: ${\mathbf{bl}}\left[\mathit{i}-1\right]$ and ${\mathbf{bu}}\left[\mathit{i}-1\right]$ must specify the lower and upper bounds, ${l}_{i}$ and ${u}_{i}$ respectively, to be imposed on the solution vector ${x}_{i}$.
Constraint: ${\mathbf{bl}}\left[\mathit{i}-1\right]\le {\mathbf{bu}}\left[\mathit{i}-1\right]$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
9: $\mathbf{tol}$double Input
On entry: tol specifies a parameter used to determine the relative linear dependence of a column vector for a variable moved from its initial value. It determines the computational rank of the matrix. Increasing its value from will increase the likelihood of additional elements of $x$ being set to zero. It may be worth experimenting with increasing values of tol to determine whether the nature of the solution, $x$, changes significantly. In practice a value of is recommended (see X02AJC).
If on entry , is used.
Suggested value: ${\mathbf{tol}}=0.0$
10: $\mathbf{x}\left[{\mathbf{n}}\right]$double Output
On exit: the solution vector $x$.
11: $\mathbf{rnorm}$double * Output
On exit: the Euclidean norm of the residual vector $b-Ax$.
12: $\mathbf{nfree}$Integer * Output
On exit: indicates the number of components of the solution vector that are not at one of the constraints.
13: $\mathbf{w}\left[{\mathbf{n}}\right]$double Output
On exit: contains the dual solution vector. The magnitude of ${\mathbf{w}}\left[i-1\right]$ gives a measure of the improvement in the objective value if the corresponding bound were to be relaxed so that ${x}_{i}$ could take different values.
A value of ${\mathbf{w}}\left[i-1\right]$ equal to the special value $-999.0$ is indicative of the matrix $A$ not having full rank. It is only likely to occur when ${\mathbf{itype}}=\mathrm{Nag_NotRegularized}$. However a matrix may have less than full rank without ${\mathbf{w}}\left[i-1\right]$ being set to $-999.0$. If ${\mathbf{itype}}=\mathrm{Nag_NotRegularized}$, then the values contained in w (other than those set to $-999.0$) may be unreliable; the corresponding values in indx may likewise be unreliable. If you have any doubts set ${\mathbf{itype}}=\mathrm{Nag_Regularized}$. Otherwise, the values of ${\mathbf{w}}\left[i-1\right]$ have the following meaning:
${\mathbf{w}}\left[i-1\right]=0$
if ${x}_{i}$ is unconstrained.
${\mathbf{w}}\left[i-1\right]<0$
if ${x}_{i}$ is constrained by its lower bound.
${\mathbf{w}}\left[i-1\right]>0$
if ${x}_{i}$ is constrained by its upper bound.
${\mathbf{w}}\left[i-1\right]$
may be any value if ${l}_{i}={u}_{i}$.
14: $\mathbf{indx}\left[{\mathbf{n}}\right]$Integer Output
On exit: the contents of this array describe the components of the solution vector as follows:
${\mathbf{indx}}\left[\mathit{i}-1\right]$, for $\mathit{i}=1,2,\dots ,{\mathbf{nfree}}$
These elements of the solution have not hit a constraint; i.e., ${\mathbf{w}}\left[i-1\right]=0$.
${\mathbf{indx}}\left[\mathit{i}-1\right]$, for $\mathit{i}={\mathbf{nfree}}+1,\dots ,k$
These elements of the solution have been constrained by either the lower or upper bound.
${\mathbf{indx}}\left[\mathit{i}-1\right]$, for $\mathit{i}=k+1,\dots ,{\mathbf{n}}$
These elements of the solution are fixed by the bounds; i.e., ${\mathbf{bl}}\left[i-1\right]={\mathbf{bu}}\left[i-1\right]$.
Here $k$ is determined from nfree and the number of fixed components. (Often the latter will be $0$, so $k$ will be ${\mathbf{n}}-{\mathbf{nfree}}$.)
15: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_CONVERGENCE
The function failed to converge in $3×n$ iterations. This is not expected. Please contact NAG.
NE_INT
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 0$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 0$.
NE_INT_2
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{pda}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pda}}\ge {\mathbf{m}}$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL_2
On entry, when $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{bl}}\left[i-1\right]=⟨\mathit{\text{value}}⟩$ and ${\mathbf{bu}}\left[i-1\right]=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{bl}}\left[i-1\right]\le {\mathbf{bu}}\left[i-1\right]$.

## 7Accuracy

Orthogonal rotations are used.

## 8Parallelism and Performance

e04pcc makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

If either m or n is zero on entry then e04pcc sets ${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_NOERROR and simply returns without setting any other output arguments.

## 10Example

The example minimizes ${‖Ax-b‖}_{2}$ where
 $A = ( 0.05 0.05 0.25 -0.25 0.25 0.25 0.05 -0.05 0.35 0.35 1.75 -1.75 1.75 1.75 0.35 -0.35 0.30 -0.30 0.30 0.30 0.40 -0.40 0.40 0.40 )$
and
 $b = ( 1.0 2.0 3.0 4.0 5.0 6.0 ) T$
subject to $1\le x\le 5$.

### 10.1Program Text

Program Text (e04pcce.c)

### 10.2Program Data

Program Data (e04pcce.d)

### 10.3Program Results

Program Results (e04pcce.r)