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

Syntax

C#
public static void e04pc(
	int itype,
	int m,
	int n,
	double[,] a,
	double[] b,
	double[] bl,
	double[] bu,
	double tol,
	double[] x,
	out double rnorm,
	out int nfree,
	double[] w,
	int[] indx,
	out int ifail
)
Visual Basic
Public Shared Sub e04pc ( _
	itype As Integer, _
	m As Integer, _
	n As Integer, _
	a As Double(,), _
	b As Double(), _
	bl As Double(), _
	bu As Double(), _
	tol As Double, _
	x As Double(), _
	<OutAttribute> ByRef rnorm As Double, _
	<OutAttribute> ByRef nfree As Integer, _
	w As Double(), _
	indx As Integer(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void e04pc(
	int itype, 
	int m, 
	int n, 
	array<double,2>^ a, 
	array<double>^ b, 
	array<double>^ bl, 
	array<double>^ bu, 
	double tol, 
	array<double>^ x, 
	[OutAttribute] double% rnorm, 
	[OutAttribute] int% nfree, 
	array<double>^ w, 
	array<int>^ indx, 
	[OutAttribute] int% ifail
)
F#
static member e04pc : 
        itype : int * 
        m : int * 
        n : int * 
        a : float[,] * 
        b : float[] * 
        bl : float[] * 
        bu : float[] * 
        tol : float * 
        x : float[] * 
        rnorm : float byref * 
        nfree : int byref * 
        w : float[] * 
        indx : int[] * 
        ifail : int byref -> unit 

Parameters

itype
Type: System..::..Int32
On entry: provides the choice of returning a regularized solution if the matrix is not of full rank.
itype=0
Specifies that a regularized solution is to be computed.
itype=1
Specifies that no regularization is to take place.
Suggested value: unless there is a definite need for a minimal length solution we recommend that itype=1 is used.
Constraint: itype=0 or 1.
m
Type: System..::..Int32
On entry: m, the number of linear equations.
Constraint: m0.
n
Type: System..::..Int32
On entry: n, the number of variables.
Constraint: n0.
a
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: dim1m
Note: the second dimension of the array a must be at least n.
On entry: the m by n matrix A.
On exit: if itype=1, a contains the product matrix QA, where Q is an m by m orthogonal matrix generated by e04pc; otherwise a is unchanged.
b
Type: array<System..::..Double>[]()[][]
An array of size [m]
On entry: the right-hand side vector b.
On exit: if itype=1, the product of Q times the original vector b, where Q is as described in parameter a; otherwise b is unchanged.
bl
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: bl[i-1] and bu[i-1] must specify the lower and upper bounds, li and ui respectively, to be imposed on the solution vector xi.
Constraint: bl[i-1]bu[i-1], for i=1,2,,n.
bu
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: bl[i-1] and bu[i-1] must specify the lower and upper bounds, li and ui respectively, to be imposed on the solution vector xi.
Constraint: bl[i-1]bu[i-1], for i=1,2,,n.
tol
Type: System..::..Double
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 machine precision 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 machine precision is recommended (see x02aj).
If on entry tol<machine precision, then machine precision is used.
Suggested value: tol=0.0
x
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the solution vector x.
rnorm
Type: System..::..Double%
On exit: the Euclidean norm of the residual vector b-Ax.
nfree
Type: System..::..Int32%
On exit: indicates the number of components of the solution vector that are not at one of the constraints.
w
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: contains the dual solution vector. The magnitude of w[i-1] gives a measure of the improvement in the objective value if the corresponding bound were to be relaxed so that xi could take different values.
A value of w[i-1] equal to the special value -999.0 is indicative of the matrix A not having full rank. It is only likely to occur when itype=1. However a matrix may have less than full rank without w[i-1] being set to -999.0. If itype=1 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 itype=0. Otherwise the values of w[i-1] have the following meaning:
w[i-1]=0
if xi is unconstrained.
w[i-1]<0
if xi is constrained by its lower bound.
w[i-1]>0
if xi is constrained by its upper bound.
w[i-1]
may be any value if li=ui.
indx
Type: array<System..::..Int32>[]()[][]
An array of size [n]
On exit: the contents of this array describe the components of the solution vector as follows:
indx[i-1], for i=1,2,,nfree
These elements of the solution have not hit a constraint; i.e., w[i-1]=0.
indx[i-1], for i=nfree+1,,k
These elements of the solution have been constrained by either the lower or upper bound.
indx[i-1], for i=k+1,,n
These elements of the solution are fixed by the bounds; i.e., bl[i-1]=bu[i-1].
Here k is determined from nfree and the number of fixed components. (Often the latter will be 0, so k will be n-nfree.)
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

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, e04pc computes an n-vector x that solves the least squares problem Ax=b subject to xi satisfying lixiui.
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.

References

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

Error Indicators and Warnings

Note: e04pc may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDA) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
ifail=1
One of the following input errors has occurred:
  • lda<m,
  • m<0,
  • n<0,
  • li>ui for at least one value of i.
ifail=2
The routine failed to converge in 3n iterations. This is not expected. Please contact NAG.
ifail=-9000
An error occured, see message report.
ifail=-4000
Invalid dimension for array value
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

Orthogonal rotations are used.

Parallelism and Performance

None.

Further Comments

If either m or n is zero on entry then e04pc sets ifail=0 and simply returns without setting any other output parameters.

Example

The example minimizes Ax-b2 where
A=0.050.050.25-0.250.250.250.05-0.050.350.351.75-1.751.751.750.35-0.350.30-0.300.300.300.40-0.400.400.40
and
b=1.02.03.04.05.06.0T
subject to 1x5.

Example program (C#): e04pce.cs

Example program data: e04pce.d

Example program results: e04pce.r

See Also