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)

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 mm by nn matrix AA, an nn-vector ll of lower bounds, an nn-vector uu of upper bounds, and an mm-vector bb, nag_bnd_lin_lsq (e04pc) computes an nn-vector xx that solves the least squares problem Ax = bAx=b subject to xixi satisfying li xi ui li xi ui .
A facility is provided to return a ‘regularized’ solution, which will closely approximate a minimal length solution whenever AA 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 RR. In general the elements of xx corresponding to the columns of RR will be the candidate non-zero solutions. If a diagonal element of RR is small compared to the other members of RR then this is undesirable. RR will be nearly singular and the equations for xx 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
Provides the choice of returning a regularized solution if the matrix is not of full rank.
itype = 0itype=0
Specifies that a regularized solution is to be computed.
itype = 1itype=1
Specifies that no regularization is to take place.
Default: itype = 1itype=1
Constraint: itype = 0itype=0 or 11.
2:     a(lda, : :) – double array
The first dimension of the array a must be at least mm
The second dimension of the array must be at least nn
The mm by nn matrix AA.
3:     b(m) – double array
m, the dimension of the array, must satisfy the constraint m0m0.
The right-hand side vector bb.
4:     bl(n) – double array
5:     bu(n) – double array
n, the dimension of the array, must satisfy the constraint n0n0.
bl(i)bli and bu(i)bui must specify the lower and upper bounds, lili and uiui respectively, to be imposed on the solution vector xixi.
Constraint: bl(i) bu(i)bli bui, for i = 1,2,,ni=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.)
mm, the number of linear equations.
Constraint: m0m0.
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.)
nn, the number of variables.
Constraint: n0n0.
3:     tol – double scalar
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 sqrt(machine precision)machine precision will increase the likelihood of additional elements of xx being set to zero. It may be worth experimenting with increasing values of tol to determine whether the nature of the solution, xx, changes significantly. In practice a value of sqrt(machine precision)machine precision is recommended (see nag_machine_precision (x02aj)).
If on entry tol < sqrt(machine precision)tol<machine precision, then sqrt(machine precision)machine precision is used.
Default: tol = 0.0tol=0.0

Input Parameters Omitted from the MATLAB Interface

lda

Output Parameters

1:     a(lda, : :) – double array
The first dimension of the array a will be mm
The second dimension of the array will be nn
ldamldam.
If itype = 1itype=1, a contains the product matrix QAQA, where QQ is an mm by mm orthogonal matrix generated by nag_bnd_lin_lsq (e04pc); otherwise a is unchanged.
2:     b(m) – double array
If itype = 1itype=1, the product of QQ times the original vector bb, where QQ is as described in parameter a; otherwise b is unchanged.
3:     x(n) – double array
The solution vector xx.
4:     rnorm – double scalar
The Euclidean norm of the residual vector bAxb-Ax.
5:     nfree – int64int32nag_int scalar
Indicates the number of components of the solution vector that are not at one of the constraints.
6:     w(n) – double array
Contains the dual solution vector. The magnitude of w(i)wi gives a measure of the improvement in the objective value if the corresponding bound were to be relaxed so that xixi could take different values.
A value of w(i)wi equal to the special value 999.0-999.0 is indicative of the matrix AA not having full rank. It is only likely to occur when itype = 1itype=1. However a matrix may have less than full rank without w(i)wi being set to 999.0-999.0. If itype = 1itype=1 then the values contained in w (other than those set to 999.0-999.0) may be unreliable; the corresponding values in indx may likewise be unreliable. If you have any doubts set itype = 0itype=0. Otherwise the values of w(i)wi have the following meaning:
w(i) = 0wi=0
if xixi is unconstrained.
w(i) < 0wi<0
if xixi is constrained by its lower bound.
w(i) > 0wi>0
if xixi is constrained by its upper bound.
w(i)wi
may be any value if li = uili=ui.
7:     indx(n) – int64int32nag_int array
The contents of this array describe the components of the solution vector as follows:
indx(i)indxi, for i = 1,2,,nfreei=1,2,,nfree
These elements of the solution have not hit a constraint; i.e., w(i) = 0wi=0.
indx(i)indxi, for i = nfree + 1,,ki=nfree+1,,k
These elements of the solution have been constrained by either the lower or upper bound.
indx(i)indxi, for i = k + 1 ,,ni=k+1 ,,n
These elements of the solution are fixed by the bounds; i.e., bl(i) = bu(i)bli=bui.
Here kk is determined from nfree and the number of fixed components. (Often the latter will be 00, so kk will be nnfreen-nfree.)
8:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 = 1ifail=1
Constraint: bl(i)bu(i)blibui.
Constraint: ldamldam.
Constraint: m0m0.
Constraint: n0n0.
  ifail = 2ifail=2
The function failed to converge in 3 × n3×n iterations. This is not expected. Please contact NAG.
  ifail = 999ifail=-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 = 0ifail=0 and simply returns without setting any other output parameters.

Example

function nag_bnd_lin_lsq_example
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] = ...
                nag_bnd_lin_lsq(itype, a, b, bl, bu);
fprintf('\nSolution vector:\n');
disp(x');
fprintf('Dual Solution:\n');
disp(w');
fprintf('Residual: %9.4f\n', rnorm);
 

Solution vector:
    1.8133    1.0000    5.0000    4.3467

Dual Solution:
         0   -2.7200    2.7200         0

Residual:    3.4246

function e04pc_example
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);
 

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–2013