hide long namesshow long names
hide short namesshow short names
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_bnd_lin_lsq (e04pc)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

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

Syntax

[a, b, x, rnorm, nfree, w, indx, ifail] = e04pc(itype, a, b, bl, bu, 'm', m, 'n', n, 'tol', tol)
[a, b, x, rnorm, nfree, w, indx, ifail] = nag_bnd_lin_lsq(itype, a, b, bl, bu, 'm', m, 'n', n, 'tol', tol)

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_bnd_lin_lsq (e04pc) 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 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

Parameters

Compulsory Input Parameters

1:     itype int64int32nag_int scalar
Default: itype=1
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.
Constraint: itype=0 or 1.
2:     alda: – double array
The first dimension of the array a must be at least m.
The second dimension of the array a must be at least n.
The m by n matrix A.
3:     bm – double array
The right-hand side vector b.
4:     bln – double array
5:     bun – double array
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.

Optional Input Parameters

1:     m int64int32nag_int scalar
Default: the first dimension of the array a and the dimension of the array b. (An error is raised if these dimensions are not equal.)
m, the number of linear equations.
Constraint: m0.
2:     n int64int32nag_int scalar
Default: the second dimension of the array a and the dimension of the arrays bl, bu. (An error is raised if these dimensions are not equal.)
n, the number of variables.
Constraint: n0.
3:     tol – double scalar
Default: tol=0.0
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 nag_machine_precision (x02aj)).
If on entry tol<machine precision, then machine precision is used.

Output Parameters

1:     alda: – double array
The first dimension of the array a will be m.
The second dimension of the array a will be n.
If itype=1, a contains the product matrix QA, where Q is an m by m orthogonal matrix generated by nag_bnd_lin_lsq (e04pc); otherwise a is unchanged.
2:     bm – double array
If itype=1, the product of Q times the original vector b, where Q is as described in argument a; otherwise b is unchanged.
3:     xn – double array
The solution vector x.
4:     rnorm – double scalar
The Euclidean norm of the residual vector b-Ax.
5:     nfree int64int32nag_int scalar
Indicates the number of components of the solution vector that are not at one of the constraints.
6:     wn – double array
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:
wi=0
if xi is unconstrained.
wi<0
if xi is constrained by its lower bound.
wi>0
if xi is constrained by its upper bound.
wi
may be any value if li=ui.
7:     indxn int64int32nag_int array
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.)
8:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Note: nag_bnd_lin_lsq (e04pc) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
   ifail=1
Constraint: blibui.
Constraint: ldam.
Constraint: m0.
Constraint: n0.
   ifail=2
The function failed to converge in 3×n iterations. This is not expected. Please contact NAG.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Orthogonal rotations are used.

Further Comments

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

Example

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  
and
b = 1.0 2.0 3.0 4.0 5.0 6.0 T  
subject to 1x5.
function e04pc_example


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

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,  2,  3,  4,  5,  6,];
bl = [1, 1, 1, 1];
bu = [5, 5, 5, 5];
itype = int64(1);


[a, b, x, rnorm, nfree, w, indx, ifail] = e04pc(itype, a, b, bl, bu);
fprintf('\nSolution vector:\n');
disp(x');
fprintf('Dual Solution:\n');
disp(w');
fprintf('Residual: %9.4f\n', rnorm);


e04pc example results


Solution vector:
    1.8133    1.0000    5.0000    4.3467

Dual Solution:
         0   -2.7200    2.7200         0

Residual:    3.4246

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