NAG Library Routine Document
F02WGF
1 Purpose
F02WGF returns leading terms in the singular value decomposition (SVD) of a real general matrix and computes the corresponding left and right singular vectors.
2 Specification
SUBROUTINE F02WGF ( |
M, N, K, NCV, AV, NCONV, SIGMA, U, LDU, V, LDV, RESID, IUSER, RUSER, IFAIL) |
INTEGER |
M, N, K, NCV, NCONV, LDU, LDV, IUSER(*), IFAIL |
REAL (KIND=nag_wp) |
SIGMA(NCV), U(LDU,NCV), V(LDV,NCV), RESID(NCV), RUSER(*) |
EXTERNAL |
AV |
|
3 Description
F02WGF computes a few,
, of the largest singular values and corresponding vectors of an
by
matrix
. The value of
should be small relative to
and
, for example
. The full singular value decomposition (SVD) of an
by
matrix
is given by
where
and
are orthogonal and
is an
by
diagonal matrix with real diagonal elements,
, such that
The are the singular values of and the first columns of and are the left and right singular vectors of .
If
,
denote the leading
columns of
and
respectively, and if
denotes the leading principal submatrix of
, then
is the best rank-
approximation to
in both the
-norm and the Frobenius norm.
The singular values and singular vectors satisfy
where
and
are the
th columns of
and
respectively.
Thus, for
, the largest singular values and corresponding right singular vectors are computed by finding eigenvalues and eigenvectors for the symmetric matrix
. For
, the largest singular values and corresponding left singular vectors are computed by finding eigenvalues and eigenvectors for the symmetric matrix
. These eigenvalues and eigenvectors are found using routines from
Chapter F12. You should read the
F12 Chapter Introduction for full details of the method used here.
The real matrix
is not explicitly supplied to F02WGF. Instead, you are required to supply a routine,
AV, that must calculate one of the requested matrix-vector products
or
for a given real vector
(of length
or
respectively).
4 References
Wilkinson J H (1978) Singular Value Decomposition – Basic Aspects Numerical Software – Needs and Availability (ed D A H Jacobs) Academic Press
5 Parameters
- 1: – INTEGERInput
-
On entry: , the number of rows of the matrix .
Constraint:
.
If , an immediate return is effected.
- 2: – INTEGERInput
-
On entry: , the number of columns of the matrix .
Constraint:
.
If , an immediate return is effected.
- 3: – INTEGERInput
-
On entry: , the number of singular values to be computed.
Constraint:
.
- 4: – INTEGERInput
-
On entry: the dimension of the arrays
SIGMA and
RESID and the second dimension of the arrays
U and
V as declared in the (sub)program from which F02WGF is called.
This is the number of Lanczos basis vectors to use during the computation of the largest eigenvalues of
(
) or
(
).
At present there is no
a priori analysis to guide the selection of
NCV relative to
K. However, it is recommended that
. If many problems of the same type are to be solved, you should experiment with varying
NCV while keeping
K fixed for a given test problem. This will usually decrease the required number of matrix-vector operations but it also increases the internal storage required to maintain the orthogonal basis vectors. The optimal ‘cross-over’ with respect to CPU time is problem dependent and must be determined empirically.
Constraint:
.
- 5: – SUBROUTINE, supplied by the user.External Procedure
-
AV must return the vector result of the matrix-vector product
or
, as indicated by the input value of
IFLAG, for the given vector
.
AV is called from F02WGF with the parameter
IUSER and
RUSER as supplied to F02WGF. You are free to use these arrays to supply information to
AV.
The specification of
AV is:
INTEGER |
IFLAG, M, N, IUSER(*) |
REAL (KIND=nag_wp) |
X(*), AX(*), RUSER(*) |
|
- 1: – INTEGERInput/Output
-
On entry: if
,
AX must return the
-vector result of the matrix-vector product
.
If
,
AX must return the
-vector result of the matrix-vector product
.
On exit: may be used as a flag to indicate a failure in the computation of
or
. If
IFLAG is negative on exit from
AV, F02WGF will exit immediately with
IFAIL set to
IFLAG.
- 2: – INTEGERInput
-
On entry: the number of rows of the matrix .
- 3: – INTEGERInput
-
On entry: the number of columns of the matrix .
- 4: – REAL (KIND=nag_wp) arrayInput
-
On entry: the vector to be pre-multiplied by the matrix or .
- 5: – REAL (KIND=nag_wp) arrayOutput
-
On exit: if
, contains the
-vector result of the matrix-vector product
.
If , contains the -vector result of the matrix-vector product .
- 6: – INTEGER arrayUser Workspace
- 7: – REAL (KIND=nag_wp) arrayUser Workspace
-
AV is called with the parameters
IUSER and
RUSER as supplied to F02WGF. You are free to use the arrays
IUSER and
RUSER to supply information to
AV as an alternative to using COMMON global variables.
AV must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which F02WGF is called. Parameters denoted as
Input must
not be changed by this procedure.
- 6: – INTEGEROutput
-
On exit: the number of converged singular values found.
- 7: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the
NCONV converged singular values are stored in the first
NCONV elements of
SIGMA.
- 8: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the left singular vectors corresponding to the singular values stored in
SIGMA.
The
th element of the th left singular vector is stored in , for and .
- 9: – INTEGERInput
-
On entry: the first dimension of the array
U as declared in the (sub)program from which F02WGF is called.
Constraint:
.
- 10: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the right singular vectors corresponding to the singular values stored in
SIGMA.
The
th element of the th right singular vector is stored in , for and .
- 11: – INTEGERInput
-
On entry: the first dimension of the array
V as declared in the (sub)program from which F02WGF is called.
Constraint:
.
- 12: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the residual , for , or , for , for each of the converged singular values and corresponding left and right singular vectors and .
- 13: – INTEGER arrayUser Workspace
- 14: – REAL (KIND=nag_wp) arrayUser Workspace
-
IUSER and
RUSER are not used by F02WGF, but are passed directly to
AV and may be used to pass information to this routine as an alternative to using COMMON global variables.
- 15: – 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).
F02WGF returns with if at least singular values have converged and the corresponding left and right singular vectors have been computed.
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, .
Constraint: .
-
On entry, .
Constraint: .
-
On entry, .
Constraint: .
-
On entry, , , and .
Constraint: .
-
On entry, and .
Constraint: .
-
On entry, and .
Constraint: .
-
The maximum number of iterations has been reached. The maximum number of iterations . The number of converged eigenvalues .
-
No shifts could be applied during a cycle of the implicitly restarted Lanczos iteration.
-
Could not build a full Lanczos factorization.
-
The number of eigenvalues found to sufficient accuracy is zero.
-
An error occurred during an internal call. Consider increasing the size of
NCV relative to
K.
-
On output from user-defined routine
AV,
IFLAG was set to a negative value,
.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
See
Section 2.14.2 in the F08 Chapter Introduction.
8 Parallelism and Performance
F02WGF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
F02WGF 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.
None.
10 Example
This example finds the four largest singular values (
) and corresponding right and left singular vectors for the matrix
, where
is the
by
real matrix derived from the simplest finite difference discretization of the two-dimensional kernal
where
10.1 Program Text
Program Text (f02wgfe.f90)
10.2 Program Data
Program Data (f02wgfe.d)
10.3 Program Results
Program Results (f02wgfe.r)