NAG Library Routine Document
f02wdf
(withdraw_real_gen_qu_svd)
1
Purpose
f02wdf returns the Householder factorization of a real rectangular by matrix . Further, on request or if is not of full rank, part or all of the singular value decomposition of is returned.
2
Specification
Fortran Interface
Subroutine f02wdf ( |
m,
n,
a,
lda,
wantb,
b,
tol,
svd,
irank,
z,
sv,
wantr,
r,
ldr,
wantpt,
pt,
ldpt,
work,
lwork,
ifail) |
Integer, Intent (In) | :: |
m,
n,
lda,
ldr,
ldpt,
lwork | Integer, Intent (Inout) | :: |
ifail | Integer, Intent (Out) | :: |
irank | Real (Kind=nag_wp), Intent (In) | :: |
tol | Real (Kind=nag_wp), Intent (Inout) | :: |
a(lda,n),
b(m),
r(ldr,n),
pt(ldpt,n) | Real (Kind=nag_wp), Intent (Out) | :: |
z(n),
sv(n),
work(lwork) | Logical, Intent (In) | :: |
wantb,
wantr,
wantpt | Logical, Intent (Inout) | :: |
svd |
|
C Header Interface
#include nagmk26.h
void |
f02wdf_ (
const Integer *m,
const Integer *n,
double a[],
const Integer *lda,
const logical *wantb,
double b[],
const double *tol,
logical *svd,
Integer *irank,
double z[],
double sv[],
const logical *wantr,
double r[],
const Integer *ldr,
const logical *wantpt,
double pt[],
const Integer *ldpt,
double work[],
const Integer *lwork,
Integer *ifail) |
|
3
Description
The real
by
matrix
is first factorized as
where
is an
by
orthogonal matrix and
is an
by
upper triangular matrix.
If either
is singular or
svd is supplied as .TRUE., then the singular value decomposition (SVD) of
is obtained so that
is factorized as
where
and
are
by
orthogonal matrices and
is the
by
diagonal matrix
with
Note that the SVD of
is then given by
the diagonal elements of
being the singular values of
.
The option to form a vector , or if appropriate , is also provided.
The rank of the matrix
, based upon a user-supplied argument
tol, is also returned.
The factorization of is obtained by Householder transformations. To obtain the SVD of the matrix is first reduced to bidiagonal form by means of plane rotations and then the algorithm is used to obtain the SVD of the bidiagonal form.
4
References
Wilkinson J H (1978) Singular Value Decomposition – Basic Aspects Numerical Software – Needs and Availability (ed D A H Jacobs) Academic Press
5
Arguments
- 1: – IntegerInput
-
On entry: , the number of rows of the matrix .
Constraint:
.
- 2: – IntegerInput
-
On entry: , the number of columns of the matrix .
Constraint:
.
- 3: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: the leading
by
part of
a must contain the matrix to be factorized.
On exit: the leading
by
part of
a, together with the
-element vector
z, contains details of the Householder
factorization.
Details of the storage of the
factorization are given in
Section 9.4.
- 4: – IntegerInput
-
On entry: the first dimension of the array
a as declared in the (sub)program from which
f02wdf is called.
Constraint:
.
- 5: – LogicalInput
-
On entry: must be .TRUE. if
or
is required.
If on entry
,
b is not referenced.
- 6: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: if
wantb is supplied as .TRUE.,
b must contain the
element vector
. Otherwise,
b is not referenced.
On exit: contains
if
svd is returned as .TRUE. and
if
svd is returned as .FALSE..
- 7: – Real (Kind=nag_wp)Input
-
On entry: must specify 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,
tol should be set to about
. See
Section 9.3 for a description of how
tol is used to determine rank.
If
tol is outside the range
, where
is the
machine precision, the value
is used in place of
tol. For most problems this is unreasonably small.
- 8: – LogicalInput/Output
-
On entry: must be .TRUE. if the singular values are to be found even if
is of full rank.
If before entry, and is determined to be of full rank, only the factorization of is computed.
On exit: is returned as .FALSE. if only the factorization of has been obtained and is returned as .TRUE. if the singular values of have been obtained.
- 9: – IntegerOutput
-
On exit: returns 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., even if
svd was supplied as .FALSE.. This means that the matrix
only just failed the test for nonsingularity.)
- 10: – Real (Kind=nag_wp) arrayOutput
-
On exit: the
-element vector
z contains some details of the Householder transformations. See
Section 9.4 for further information.
- 11: – Real (Kind=nag_wp) arrayOutput
-
On exit: if
svd is returned as .TRUE.,
sv contains the
singular values of
arranged in descending order.
- 12: – LogicalInput
-
On entry: must be .TRUE. if the orthogonal matrix
is required when the singular values are computed.
If on entry
,
r is not referenced.
- 13: – Real (Kind=nag_wp) arrayOutput
-
Note: the second dimension of the array
r
must be at least
if
, and at least
otherwise.
On exit: if
svd is returned as .TRUE. and
wantr was supplied as .TRUE., the leading
by
part of
r will contain the left-hand orthogonal matrix of the
svd of
.
- 14: – IntegerInput
-
On entry: the first dimension of the array
r as declared in the (sub)program from which
f02wdf is called.
Constraints:
- if , ;
- otherwise .
- 15: – LogicalInput
-
On entry: must be .TRUE. if the orthogonal matrix
is required when the singular values are computed.
Note that if
svd is returned as .TRUE.,
pt is referenced even if
wantpt is supplied as .FALSE., but see argument
pt.
- 16: – Real (Kind=nag_wp) arrayOutput
-
On exit: if
svd is returned as .TRUE. and
wantpt was supplied as .TRUE., the leading
by
part of
pt contains the orthogonal matrix
.
If
svd is returned as .TRUE., but
wantpt was supplied as .FALSE., the leading
by
part of
pt is used for internal workspace.
- 17: – IntegerInput
-
On entry: the first dimension of the array
pt as declared in the (sub)program from which
f02wdf is called.
Constraint:
.
- 18: – Real (Kind=nag_wp) arrayOutput
-
On exit: if
svd is returned as .FALSE.,
contains the condition number
of the upper triangular matrix
.
If
svd is returned as .TRUE.,
will contain the total number of iterations taken by the
algorithm.
The rest of the array is used as workspace and so contains no meaningful information.
- 19: – IntegerInput
-
On entry: the dimension of the array
work as declared in the (sub)program from which
f02wdf is called.
Constraint:
.
- 20: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, 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 | when , |
or | |
or | . |
(The routine only checks
ldr if
wantr is supplied as .TRUE..)
-
The algorithm has failed to converge to the singular values in iterations. In this case may not have been correctly found and the remaining singular values may not be the smallest singular values. The matrix has nevertheless been factorized as , where is an upper bidiagonal matrix with as its diagonal elements and as its superdiagonal elements.
This failure cannot occur if
svd is returned as .FALSE. and in any case is extremely rare.
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.
7
Accuracy
The computed factors
,
,
,
and
satisfy the relations
where
,
,
being the machine precision and and are modest functions of and . Note that .
8
Parallelism and Performance
f02wdf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f02wdf 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.
The time taken by f02wdf to obtain the Householder factorization is approximately proportional to .
The additional time taken to obtain the singular value decomposition is approximately proportional to , where the constant of proportionality depends upon whether or not the orthogonal matrices and are required.
Singular vectors associated with a zero or multiple singular value, are not uniquely determined, even in exact arithmetic, and very different results may be obtained if they are computed on different machines.
Unless otherwise stated in the
Users' Note for your implementation, the routine may be called with the same array for arguments
z and
sv, in which case, if
svd is returned as .TRUE., the singular values will overwrite the original contents of
z; also, if
, it may be called with the same array for arguments
r and
pt. However this is not standard Fortran, and may not work on all systems.
This routine is called by the least squares routine
f04jgf.
Following the
factorization of
, if
svd is supplied as
.FALSE., then the condition number of
given by
is found, where
denotes the Frobenius norm, and if
is such that
then
is regarded as singular and the singular values of
are computed. If this test is not satisfied, then the rank of
is set to
. Note that if
svd is supplied as .TRUE. then this test is omitted.
When the singular values are computed, then the rank of
,
, 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.
The
th Householder transformation matrix,
, used in the
factorization is chosen to introduce the zeros into the
th column and has the form
where
is an
element vector.
In place of
the routine actually computes the vector
given by
The first element of
is stored in
and the remaining elements of
are overwritten on the subdiagonal elements of the
th column of
a. The upper triangular matrix
is overwritten on the
by
upper triangular part of
a.
10
Example
This example obtains the rank and the singular value decomposition of the
by
matrix
given by
the value
tol to be taken as
.
10.1
Program Text
Program Text (f02wdfe.f90)
10.2
Program Data
Program Data (f02wdfe.d)
10.3
Program Results
Program Results (f02wdfe.r)