NAG Library Routine Document
F04JGF
1 Purpose
F04JGF finds the solution of a linear least squares problem, , where is a real by matrix and is an element vector. If the matrix of observations is not of full rank, then the minimal least squares solution is returned.
2 Specification
SUBROUTINE F04JGF ( |
M, N, A, LDA, B, TOL, SVD, SIGMA, IRANK, WORK, LWORK, IFAIL) |
INTEGER |
M, N, LDA, IRANK, LWORK, IFAIL |
REAL (KIND=nag_wp) |
A(LDA,N), B(M), TOL, SIGMA, WORK(LWORK) |
LOGICAL |
SVD |
|
3 Description
The minimal least squares solution of the problem is the vector of minimum (Euclidean) length which minimizes the length of the residual vector .
The real
by
matrix
is factorized as
where
is an
by
orthogonal matrix and
is an
by
upper triangular matrix. If
is of full rank, then the least squares solution is given by
If
is not of full rank, then the singular value decomposition of
is obtained so that
is factorized as
where
and
are
by
orthogonal matrices and
is the
by
diagonal matrix
with
, these being the singular values of
. If the singular values
are negligible, but
is not negligible, relative to the data errors in
, then the rank of
is taken to be
and the minimal least squares solution is given by
where
.
This routine obtains the factorizations by a call to
F02WDF.
The routine also returns the value of the standard error
being the residual sum of squares and
the rank of
.
4 References
Lawson C L and Hanson R J (1974) Solving Least-squares Problems Prentice–Hall
5 Parameters
- 1: M – INTEGERInput
On entry:
, the number of rows of
A.
Constraint:
.
- 2: N – INTEGERInput
On entry: , the number of columns of .
Constraint:
.
- 3: A(LDA,N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the by matrix .
On exit: if
SVD is returned as .FALSE.,
A is overwritten by details of the
factorization of
(see
F02WDF for further details).
If
SVD is returned as .TRUE., the first
rows of
A are overwritten by the right-hand singular vectors, stored by rows; and the remaining rows of the array are used as workspace.
- 4: LDA – INTEGERInput
On entry: the first dimension of the array
A as declared in the (sub)program from which F04JGF is called.
Constraint:
.
- 5: B(M) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the right-hand side vector .
On exit: the first
elements of
B contain the minimal least squares solution vector
. The remaining
elements are used for workspace.
- 6: TOL – REAL (KIND=nag_wp)Input
On entry: a relative tolerance to be used to determine the rank of
.
TOL should be chosen as approximately the largest relative error in the elements of
. For example, if the elements of
are correct to about
significant figures then
TOL should be set to about
. See
Section 8 for a description of how
TOL is used to determine rank. If
TOL is outside the range
, where
is the
machine precision, then the value
is used in place of
TOL. For most problems this is unreasonably small.
- 7: SVD – LOGICALOutput
On exit: is returned as .FALSE. if the least squares solution has been obtained from the
factorization of
. In this case
is of full rank.
SVD is returned as .TRUE. if the least squares solution has been obtained from the singular value decomposition of
.
- 8: SIGMA – REAL (KIND=nag_wp)Output
On exit: the standard error, i.e., the value when , and the value zero when . Here is the residual vector and is the rank of .
- 9: IRANK – INTEGEROutput
On exit:
, the rank of the matrix
. It should be noted that it is possible for
IRANK to be returned as
and
SVD to be returned as .TRUE.. This means that the matrix
only just failed the test for nonsingularity.
- 10: WORK(LWORK) – REAL (KIND=nag_wp) arrayOutput
On exit: if
SVD is returned as .FALSE., then the first
elements of
WORK contain information on the
factorization of
(see parameter
A above and
F02WDF), and
contains the condition number
of the upper triangular matrix
.
If
SVD is returned as .TRUE., then the first
elements of
WORK contain the singular values of
arranged in descending order and
contains the total number of iterations taken by the
algorithm. The rest of
WORK is used as workspace.
- 11: LWORK – INTEGERInput
On entry: the dimension of the array
WORK as declared in the (sub)program from which F04JGF is called.
Constraint:
.
- 12: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
On entry, | , |
or | , |
or | , |
or | . |
The algorithm has failed to converge to the singular values in iterations. This failure can only happen when the singular value decomposition is employed, but even then it is not likely to occur.
7 Accuracy
The computed factors
,
,
,
and
satisfy the relations
where
being the
machine precision, and
and
being modest functions of
and
. Note that
.
For a fuller discussion, covering the accuracy of the solution
see
Lawson and Hanson (1974), especially pages 50 and 95.
If the least squares solution is obtained from the factorization then the time taken by the routine is approximately proportional to . If the least squares solution is obtained from the singular value decomposition then the time taken is approximately proportional to . The approximate proportionality factor is the same in each case.
This routine is column biased and so is suitable for use in paged environments.
Following the
factorization of
the condition number
is determined and if
is such that
then
is regarded as singular and the singular values of
are computed. If this test is not satisfied,
is regarded as nonsingular and the rank of
is set to
. When the singular values are computed the rank of
, say
, is returned as the largest integer such that
unless
in which case
is returned as zero. That is, singular values which satisfy
are regarded as negligible because relative perturbations of order
TOL can make such singular values zero.
9 Example
This example obtains a least squares solution for
, where
and the value
TOL is to be taken as
.
9.1 Program Text
Program Text (f04jgfe.f90)
9.2 Program Data
Program Data (f04jgfe.d)
9.3 Program Results
Program Results (f04jgfe.r)