NAG Library Routine Document

e04pcf (bnd_lin_lsq)


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


Fortran Interface
Subroutine e04pcf ( itype, m, n, a, lda, b, bl, bu, tol, x, rnorm, nfree, w, indx, ifail)
Integer, Intent (In):: itype, m, n, lda
Integer, Intent (Inout):: ifail
Integer, Intent (Out):: nfree, indx(n)
Real (Kind=nag_wp), Intent (In):: bl(n), bu(n), tol
Real (Kind=nag_wp), Intent (Inout):: a(lda,*), b(m)
Real (Kind=nag_wp), Intent (Out):: x(n), rnorm, w(n)
C Header Interface
#include <nagmk26.h>
void  e04pcf_ (const Integer *itype, const Integer *m, const Integer *n, double a[], const Integer *lda, double b[], const double bl[], const double bu[], const double *tol, double x[], double *rnorm, Integer *nfree, double w[], Integer indx[], Integer *ifail)


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


1:     itype – IntegerInput
On entry: provides the choice of returning a regularized solution if the matrix is not of full rank.
Specifies that a regularized solution is to be computed.
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.
2:     m – IntegerInput
On entry: m, the number of linear equations.
Constraint: m0.
3:     n – IntegerInput
On entry: n, the number of variables.
Constraint: n0.
4:     alda* – Real (Kind=nag_wp) arrayInput/Output
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 e04pcf; otherwise a is unchanged.
5:     lda – IntegerInput
On entry: the first dimension of the array a as declared in the (sub)program from which e04pcf is called.
Constraint: ldam.
6:     bm – Real (Kind=nag_wp) arrayInput/Output
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 argument a; otherwise b is unchanged.
7:     bln – Real (Kind=nag_wp) arrayInput
8:     bun – Real (Kind=nag_wp) arrayInput
On entry: bli and bui must specify the lower and upper bounds, li and ui respectively, to be imposed on the solution vector xi.
Constraint: bli bui, for i=1,2,,n.
9:     tol – Real (Kind=nag_wp)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 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 x02ajf).
If on entry tol<machine precision, machine precision is used.
Suggested value: tol=0.0 
10:   xn – Real (Kind=nag_wp) arrayOutput
On exit: the solution vector x.
11:   rnorm – Real (Kind=nag_wp)Output
On exit: the Euclidean norm of the residual vector b-Ax.
12:   nfree – IntegerOutput
On exit: indicates the number of components of the solution vector that are not at one of the constraints.
13:   wn – Real (Kind=nag_wp) arrayOutput
On exit: contains the dual solution vector. The magnitude of wi 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 wi 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 wi 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 wi have the following meaning:
if xi is unconstrained.
if xi is constrained by its lower bound.
if xi is constrained by its upper bound.
may be any value if li=ui.
14:   indxn – Integer arrayOutput
On exit: the contents of this array describe the components of the solution vector as follows:
indxi, for i=1,2,,nfree
These elements of the solution have not hit a constraint; i.e., wi=0.
indxi, for i=nfree+1,,k
These elements of the solution have been constrained by either the lower or upper bound.
indxi, for i=k+1 ,,n
These elements of the solution are fixed by the bounds; i.e., bli=bui.
Here k is determined from nfree and the number of fixed components. (Often the latter will be 0, so k will be n-nfree.)
15:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1 or 1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if ifail0 on exit, the recommended value is -1. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Note: e04pcf may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
On entry, m=value.
Constraint: m0.
On entry, m=value and lda=value.
Constraint: ldam.
On entry, n=value.
Constraint: n0.
On entry, when i=value, bli=value and bui=value.
Constraint: blibui.
The routine failed to converge in 3×n iterations. This is not expected. Please contact NAG.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


Orthogonal rotations are used.

Parallelism and Performance

e04pcf 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

Further Comments

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


The example minimizes Ax-b2  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  
b = 1.0 2.0 3.0 4.0 5.0 6.0 T  
subject to 1x5.

Program Text

Program Text (e04pcfe.f90)

Program Data

Program Data (e04pcfe.d)

Program Results

Program Results (e04pcfe.r)