PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_lapack_dgesvd (f08kb)
Purpose
nag_lapack_dgesvd (f08kb) computes the singular value decomposition (SVD) of a real by matrix , optionally computing the left and/or right singular vectors.
Syntax
[
a,
s,
u,
vt,
work,
info] = f08kb(
jobu,
jobvt,
a, 'm',
m, 'n',
n)
[
a,
s,
u,
vt,
work,
info] = nag_lapack_dgesvd(
jobu,
jobvt,
a, 'm',
m, 'n',
n)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: |
work was made an output parameter |
Description
The SVD is written as
where
is an
by
matrix which is zero except for its
diagonal elements,
is an
by
orthogonal matrix, and
is an
by
orthogonal matrix. The diagonal elements of
are the singular values of
; they are real and non-negative, and are returned in descending order. The first
columns of
and
are the left and right singular vectors of
.
Note that the function returns , not .
References
Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999)
LAPACK Users' Guide (3rd Edition) SIAM, Philadelphia
http://www.netlib.org/lapack/lug
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Parameters
Compulsory Input Parameters
- 1:
– string (length ≥ 1)
-
Specifies options for computing all or part of the matrix
.
- All columns of are returned in array u.
- The first columns of (the left singular vectors) are returned in the array u.
- The first columns of (the left singular vectors) are overwritten on the array a.
- No columns of (no left singular vectors) are computed.
Constraint:
, , or .
- 2:
– string (length ≥ 1)
-
Specifies options for computing all or part of the matrix
.
- All rows of are returned in the array vt.
- The first rows of (the right singular vectors) are returned in the array vt.
- The first rows of (the right singular vectors) are overwritten on the array a.
- No rows of (no right singular vectors) are computed.
Constraints:
- , , or ;
- jobvt and jobu cannot both be .
- 3:
– 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 .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the first dimension of the array
a.
, the number of rows of the matrix .
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the second dimension of the array
a.
, the number of columns of the matrix .
Constraint:
.
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 is overwritten with the first
columns of
(the left singular vectors, stored column-wise).
If
,
a is overwritten with the first
rows of
(the right singular vectors, stored row-wise).
If
and
, the contents of
a are destroyed.
- 2:
– double array
-
The dimension of the array
s will be
The singular values of , sorted so that .
- 3:
– double array
-
The first dimension,
, of the array
u will be
- if or , ;
- otherwise .
The second dimension of the array
u will be
if
,
if
and
otherwise.
If
,
u contains the
by
orthogonal matrix
.
If
,
u contains the first
columns of
(the left singular vectors, stored column-wise).
If
or
,
u is not referenced.
- 4:
– double array
-
The first dimension,
, of the array
vt will be
- if , ;
- if , ;
- otherwise .
The second dimension of the array
vt will be
if
or
and
otherwise.
If
,
vt contains the
by
orthogonal matrix
.
If
,
vt contains the first
rows of
(the right singular vectors, stored row-wise).
If
or
,
vt is not referenced.
- 5:
– double array
-
If
,
returns the optimal
lwork.
If
,
contains the unconverged superdiagonal elements of an upper bidiagonal matrix
whose diagonal is in
s (not necessarily sorted).
satisfies
, so it has the same singular values as
, and singular vectors related by
and
.
- 6:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
-
If , argument had an illegal value. An explanatory message is output, and execution of the program is terminated.
-
-
If
nag_lapack_dgesvd (f08kb) did not converge,
info specifies how many superdiagonals of an intermediate bidiagonal form did not converge to zero.
Accuracy
The computed singular value decomposition is nearly the exact singular value decomposition for a nearby matrix
, where
and
is the
machine precision. In addition, the computed singular vectors are nearly orthogonal to working precision. See Section 4.9 of
Anderson et al. (1999) for further details.
Further Comments
The total number of floating-point operations is approximately proportional to when and otherwise.
The singular values are returned in descending order.
The complex analogue of this function is
nag_lapack_zgesvd (f08kp).
Example
This example finds the singular values and left and right singular vectors of the
by
matrix
together with approximate error bounds for the computed singular values and vectors.
The example program for
nag_lapack_dgesdd (f08kd) illustrates finding a singular value decomposition for the case
.
Open in the MATLAB editor:
f08kb_example
function f08kb_example
fprintf('f08kb example results\n\n');
a = [ 2.27, -1.54, 1.15, -1.94;
0.28, -1.67, 0.94, -0.78;
-0.48, -3.09, 0.99, -0.21;
1.07, 1.22, 0.79, 0.63;
-2.35, 2.93, -1.45, 2.30;
0.62, -7.39, 1.03, -2.57];
[m,n] = size(a);
b = ones(m,1);
jobu = 'Singular vectors part of U';
jobvt = 'Singular vectors part of VT';
[~, s, u, vt, work, info] = f08kb( ...
jobu, jobvt, a);
disp('Singular values of A');
disp(s');
y = u'*b;
y = y./s;
x = vt'*y;
disp('Least squares solution:');
disp(x');
disp('Norm of Residual:');
disp(norm(b - a*x));
f08kb example results
Singular values of A
9.9966 3.6831 1.3569 0.5000
Least squares solution:
-0.0563 -0.1700 0.8202 0.5545
Norm of Residual:
1.7472
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015