NAG CL Interface
f08mec (dbdsqr)
1
Purpose
f08mec computes the singular value decomposition of a real upper or lower bidiagonal matrix, or of a real general matrix which has been reduced to bidiagonal form.
2
Specification
void |
f08mec (Nag_OrderType order,
Nag_UploType uplo,
Integer n,
Integer ncvt,
Integer nru,
Integer ncc,
double d[],
double e[],
double vt[],
Integer pdvt,
double u[],
Integer pdu,
double c[],
Integer pdc,
NagError *fail) |
|
The function may be called by the names: f08mec, nag_lapackeig_dbdsqr or nag_dbdsqr.
3
Description
f08mec computes the singular values and, optionally, the left or right singular vectors of a real upper or lower bidiagonal matrix
. In other words, it can compute the singular value decomposition (SVD) of
as
Here
is a diagonal matrix with real diagonal elements
(the singular values of
), such that
is an orthogonal matrix whose columns are the left singular vectors
;
is an orthogonal matrix whose rows are the right singular vectors
. Thus
To compute
and/or
, the arrays
u and/or
vt must be initialized to the unit matrix before
f08mec is called.
The function may also be used to compute the SVD of a real general matrix
which has been reduced to bidiagonal form by an orthogonal transformation:
. If
is
by
with
, then
is
by
and
is
by
; if
is
by
with
, then
is
by
and
is
by
. In this case, the matrices
and/or
must be formed explicitly by
f08kfc and passed to
f08mec in the arrays
u and/or
vt respectively.
f08mec also has the capability of forming , where is an arbitrary real matrix; this is needed when using the SVD to solve linear least squares problems.
f08mec uses two different algorithms. If any singular vectors are required (i.e., if
or
or
), the bidiagonal
algorithm is used, switching between zero-shift and implicitly shifted forms to preserve the accuracy of small singular values, and switching between
and
variants in order to handle graded matrices effectively (see
Demmel and Kahan (1990)). If only singular values are required (i.e., if
), they are computed by the differential qd algorithm (see
Fernando and Parlett (1994)), which is faster and can achieve even greater accuracy.
The singular vectors are normalized so that , but are determined only to within a factor .
4
References
Demmel J W and Kahan W (1990) Accurate singular values of bidiagonal matrices SIAM J. Sci. Statist. Comput. 11 873–912
Fernando K V and Parlett B N (1994) Accurate singular values and differential qd algorithms Numer. Math. 67 191–229
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
5
Arguments
-
1:
– Nag_OrderType
Input
-
On entry: the
order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by
. See
Section 3.1.3 in the Introduction to the NAG Library CL Interface for a more detailed explanation of the use of this argument.
Constraint:
or .
-
2:
– Nag_UploType
Input
-
On entry: indicates whether
is an upper or lower bidiagonal matrix.
- is an upper bidiagonal matrix.
- is a lower bidiagonal matrix.
Constraint:
or .
-
3:
– Integer
Input
-
On entry: , the order of the matrix .
Constraint:
.
-
4:
– Integer
Input
-
On entry: , the number of columns of the matrix of right singular vectors. Set if no right singular vectors are required.
Constraint:
.
-
5:
– Integer
Input
-
On entry: , the number of rows of the matrix of left singular vectors. Set if no left singular vectors are required.
Constraint:
.
-
6:
– Integer
Input
-
On entry: , the number of columns of the matrix . Set if no matrix is supplied.
Constraint:
.
-
7:
– double
Input/Output
-
Note: the dimension,
dim, of the array
d
must be at least
.
On entry: the diagonal elements of the bidiagonal matrix .
On exit: the singular values in decreasing order of magnitude, unless
NE_CONVERGENCE (in which case see
Section 6).
-
8:
– double
Input/Output
-
Note: the dimension,
dim, of the array
e
must be at least
.
On entry: the off-diagonal elements of the bidiagonal matrix .
On exit:
e is overwritten, but if
NE_CONVERGENCE see
Section 6.
-
9:
– double
Input/Output
-
Note: the dimension,
dim, of the array
vt
must be at least
when
and at least
when
.
The
th element of the matrix is stored in
- when ;
- when .
On entry: if
,
vt must contain an
by
matrix. If the right singular vectors of
are required,
and
vt must contain the unit matrix; if the right singular vectors of
are required,
vt must contain the orthogonal matrix
returned by
f08kfc with
.
On exit: the
by
matrix
or
of right singular vectors, stored by rows.
If
,
vt is not referenced.
-
10:
– Integer
Input
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
vt.
Constraints:
- if ,
- if , ;
- otherwise ;
- if ,
- if ,
;
- otherwise .
-
11:
– double
Input/Output
-
Note: the dimension,
dim, of the array
u
must be at least
- when
;
- when
.
The
th element of the matrix
is stored in
- when ;
- when .
On entry: if
,
u must contain an
by
matrix. If the left singular vectors of
are required,
and
u must contain the unit matrix; if the left singular vectors of
are required,
u must contain the orthogonal matrix
returned by
f08kfc with
.
On exit: the
by
matrix
or
of left singular vectors, stored as columns of the matrix.
If
,
u is not referenced.
-
12:
– Integer
Input
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
u.
Constraints:
- if ,
;
- if , .
-
13:
– double
Input/Output
-
Note: the dimension,
dim, of the array
c
must be at least
when
and at least
when
.
The
th element of the matrix
is stored in
- when ;
- when .
On entry: the by matrix if .
On exit:
c is overwritten by the matrix
. If
,
c is not referenced.
-
14:
– Integer
Input
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
c.
Constraints:
- if ,
- if , ;
- otherwise ;
- if , .
-
15:
– NagError *
Input/Output
-
The NAG error argument (see
Section 7 in the Introduction to the NAG Library CL Interface).
6
Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_CONVERGENCE
-
off-diagonals did not converge. The arrays
d and
e contain the diagonal and off-diagonal elements, respectively, of a bidiagonal matrix orthogonally equivalent to
.
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_2
-
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: if ,
;
otherwise .
- NE_INT_3
-
On entry, , and .
Constraint: if , ;
otherwise .
On entry, , and .
Constraint: if , ;
otherwise .
- NE_INTERNAL_ERROR
-
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
See
Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library CL Interface for further information.
7
Accuracy
Each singular value and singular vector is computed to high relative accuracy. However, the reduction to bidiagonal form (prior to calling the function) may exclude the possibility of obtaining high relative accuracy in the small singular values of the original matrix if its singular values vary widely in magnitude.
If
is an exact singular value of
and
is the corresponding computed value, then
where
is a modestly increasing function of
and
, and
is the
machine precision. If only singular values are computed, they are computed more accurately (i.e., the function
is smaller), than when some singular vectors are also computed.
If
is the corresponding exact left singular vector of
, and
is the corresponding computed left singular vector, then the angle
between them is bounded as follows:
where
is the relative gap between
and the other singular values, defined by
A similar error bound holds for the right singular vectors.
8
Parallelism and Performance
f08mec is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f08mec 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 function. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
The total number of floating-point operations is roughly proportional to if only the singular values are computed. About additional operations are required to compute the left singular vectors and about to compute the right singular vectors. The operations to compute the singular values must all be performed in scalar mode; the additional operations to compute the singular vectors can be vectorized and on some machines may be performed much faster.
The complex analogue of this function is
f08msc.
10
Example
This example computes the singular value decomposition of the upper bidiagonal matrix
, where
See also the example for
f08kfc, which illustrates the use of the function to compute the singular value decomposition of a general matrix.
10.1
Program Text
10.2
Program Data
10.3
Program Results