e04 Chapter Contents
e04 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_opt_bnd_lin_lsq (e04pcc)

## 1  Purpose

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

## 2  Specification

 #include #include
 void nag_opt_bnd_lin_lsq (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)

## 3  Description

Given an $m$ by $n$ matrix $A$, an $n$-vector $l$ of lower bounds, an $n$-vector $u$ of upper bounds, and an $m$-vector $b$, nag_opt_bnd_lin_lsq (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 non-zero 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.

## 4  References

Lawson C L and Hanson R J (1974) Solving Least Squares Problems Prentice–Hall

## 5  Arguments

1:     itypeNag_RegularizedTypeInput
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:     mIntegerInput
On entry: $m$, the number of linear equations.
Constraint: ${\mathbf{m}}\ge 0$.
3:     nIntegerInput
On entry: $n$, the number of variables.
Constraint: ${\mathbf{n}}\ge 0$.
4:     a[${\mathbf{pda}}×{\mathbf{n}}$]doubleInput/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$ by $n$ matrix $A$.
On exit: if ${\mathbf{itype}}=\mathrm{Nag_NotRegularized}$, a contains the product matrix $QA$, where $Q$ is an $m$ by $m$ orthogonal matrix generated by nag_opt_bnd_lin_lsq (e04pcc); otherwise a is unchanged.
5:     pdaIntegerInput
On entry: the stride separating matrix row elements in the array a.
Constraint: ${\mathbf{pda}}\ge {\mathbf{m}}$.
6:     b[m]doubleInput/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:     bl[n]const doubleInput
8:     bu[n]const doubleInput
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:     toldoubleInput
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 nag_machine_precision (X02AJC)).
If on entry , then  is used.
Suggested value: ${\mathbf{tol}}=0.0$
10:   x[n]doubleOutput
On exit: the solution vector $x$.
11:   rnormdouble *Output
On exit: the Euclidean norm of the residual vector $b-Ax$.
12:   nfreeInteger *Output
On exit: indicates the number of components of the solution vector that are not at one of the constraints.
13:   w[n]doubleOutput
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:   indx[n]IntegerOutput
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:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
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.
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]$.

## 7  Accuracy

Orthogonal rotations are used.

## 8  Parallelism and Performance

nag_opt_bnd_lin_lsq (e04pcc) is not threaded by NAG in any implementation.
nag_opt_bnd_lin_lsq (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.

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

## 10  Example

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.1  Program Text

Program Text (e04pcce.c)

### 10.2  Program Data

Program Data (e04pcce.d)

### 10.3  Program Results

Program Results (e04pcce.r)