PDF version (NAG web site
, 64-bit version, 64-bit version)
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 by matrix , an -vector of lower bounds, an -vector of upper bounds, and an -vector , nag_bnd_lin_lsq (e04pc) computes an -vector that solves the least squares problem subject to satisfying .
A facility is provided to return a ‘regularized’ solution, which will closely approximate a minimal length solution whenever 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 . In general the elements of corresponding to the columns of will be the candidate non-zero solutions. If a diagonal element of is small compared to the other members of then this is undesirable. will be nearly singular and the equations for 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:
– int64int32nag_int scalar
Default:
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.
Constraint:
or .
- 2:
– double array
-
The first dimension of the array
a must be at least
.
The second dimension of the array
a must be at least
.
The by matrix .
- 3:
– double array
-
The right-hand side vector .
- 4:
– double array
- 5:
– double array
-
and must specify the lower and upper bounds, and respectively, to be imposed on the solution vector .
Constraint:
, for .
Optional Input Parameters
- 1:
– 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.)
, the number of linear equations.
Constraint:
.
- 2:
– 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.)
, the number of variables.
Constraint:
.
- 3:
– double scalar
Default:
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
being set to zero. It may be worth experimenting with increasing values of
tol to determine whether the nature of the solution,
, changes significantly. In practice a value of
is recommended (see
nag_machine_precision (x02aj)).
If on entry , then is used.
Output Parameters
- 1:
– double array
-
The first dimension of the array
a will be
.
The second dimension of the array
a will be
.
If
,
a contains the product matrix
, where
is an
by
orthogonal matrix generated by
nag_bnd_lin_lsq (e04pc); otherwise
a is unchanged.
- 2:
– double array
-
If
, the product of
times the original vector
, where
is as described in argument
a; otherwise
b is unchanged.
- 3:
– double array
-
The solution vector .
- 4:
– double scalar
-
The Euclidean norm of the residual vector .
- 5:
– int64int32nag_int scalar
-
Indicates the number of components of the solution vector that are not at one of the constraints.
- 6:
– double array
-
Contains the dual solution vector. The magnitude of
gives a measure of the improvement in the objective value if the corresponding bound were to be relaxed so that
could take different values.
A value of
equal to the special value
is indicative of the matrix
not having full rank. It is only likely to occur when
. However a matrix may have less than full rank without
being set to
. If
then the values contained in
w (other than those set to
) may be unreliable; the corresponding values in
indx may likewise be unreliable. If you have any doubts set
. Otherwise the values of
have the following meaning:
- if is unconstrained.
- if is constrained by its lower bound.
- if is constrained by its upper bound.
- may be any value if .
- 7:
– int64int32nag_int array
-
The contents of this array describe the components of the solution vector as follows:
- , for
- These elements of the solution have not hit a constraint; i.e., .
- , for
- These elements of the solution have been constrained by either the lower or upper bound.
- , for
- These elements of the solution are fixed by the bounds; i.e., .
Here
is determined from
nfree and the number of fixed components. (Often the latter will be
, so
will be
.)
- 8:
– int64int32nag_int scalar
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:
-
-
Constraint: .
Constraint: .
Constraint: .
Constraint: .
-
-
The function failed to converge in
iterations. This is not expected. Please contact
NAG.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
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
and simply returns without setting any other output arguments.
Example
The example minimizes
where
and
subject to
.
Open in the MATLAB editor:
e04pc_example
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)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015