PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_eigen_real_gen_partialsvd (f02wg)
Purpose
nag_eigen_real_gen_partialsvd (f02wg) returns leading terms in the singular value decomposition (SVD) of a real general matrix and computes the corresponding left and right singular vectors.
Syntax
[
nconv,
sigma,
u,
v,
resid,
user,
ifail] = f02wg(
m,
n,
k,
ncv,
av, 'user',
user)
[
nconv,
sigma,
u,
v,
resid,
user,
ifail] = nag_eigen_real_gen_partialsvd(
m,
n,
k,
ncv,
av, 'user',
user)
Description
nag_eigen_real_gen_partialsvd (f02wg) 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 functions 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
nag_eigen_real_gen_partialsvd (f02wg). Instead, you are required to supply a function,
av, that must calculate one of the requested matrix-vector products
or
for a given real vector
(of length
or
respectively).
References
Wilkinson J H (1978) Singular Value Decomposition – Basic Aspects Numerical Software – Needs and Availability (ed D A H Jacobs) Academic Press
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
, the number of rows of the matrix .
Constraint:
.
If , an immediate return is effected.
- 2:
– int64int32nag_int scalar
-
, the number of columns of the matrix .
Constraint:
.
If , an immediate return is effected.
- 3:
– int64int32nag_int scalar
-
, the number of singular values to be computed.
Constraint:
.
- 4:
– int64int32nag_int scalar
-
The dimension of the arrays
sigma and
resid and the second dimension of the arrays
u and
v.
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:
– function handle or string containing name of m-file
-
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
nag_eigen_real_gen_partialsvd (f02wg) with the argument
user as supplied to
nag_eigen_real_gen_partialsvd (f02wg). You are free to use these arrays to supply information to
av.
[iflag, ax, user] = av(iflag, m, n, x, user)
Input Parameters
- 1:
– int64int32nag_int scalar
-
If
,
ax must return the
-vector result of the matrix-vector product
.
If
,
ax must return the
-vector result of the matrix-vector product
.
- 2:
– int64int32nag_int scalar
-
The number of rows of the matrix .
- 3:
– int64int32nag_int scalar
-
The number of columns of the matrix .
- 4:
– double array
-
The vector to be pre-multiplied by the matrix or .
- 5:
– Any MATLAB object
av is called from
nag_eigen_real_gen_partialsvd (f02wg) with the object supplied to
nag_eigen_real_gen_partialsvd (f02wg).
Output Parameters
- 1:
– int64int32nag_int scalar
-
May be used as a flag to indicate a failure in the computation of
or
. If
iflag is negative on exit from
av,
nag_eigen_real_gen_partialsvd (f02wg) will exit immediately with
ifail set to
iflag.
- 2:
– double array
-
If
, contains the
-vector result of the matrix-vector product
.
If , contains the -vector result of the matrix-vector product .
- 3:
– Any MATLAB object
Optional Input Parameters
- 1:
– Any MATLAB object
user is not used by
nag_eigen_real_gen_partialsvd (f02wg), but is passed to
av. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files than to use
user.
Output Parameters
- 1:
– int64int32nag_int scalar
-
The number of converged singular values found.
- 2:
– double array
-
The
nconv converged singular values are stored in the first
nconv elements of
sigma.
- 3:
– double array
-
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 .
- 4:
– double array
-
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 .
- 5:
– double array
-
The residual , for , or , for , for each of the converged singular values and corresponding left and right singular vectors and .
- 6:
– Any MATLAB object
- 7:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
nag_eigen_real_gen_partialsvd (f02wg) returns with if at least singular values have converged and the corresponding left and right singular vectors have been computed.
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
Constraint: .
-
-
Constraint: .
-
-
Constraint: .
-
-
Constraint: .
-
-
Constraint: .
-
-
Constraint: .
-
-
The maximum number of iterations has been reached.
-
-
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 function
av,
iflag was set to a negative value, .
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
See
The singular value decomposition in the F08 Chapter Introduction.
Further Comments
None.
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
Open in the MATLAB editor:
f02wg_example
function f02wg_example
fprintf('f02wg example results\n\n');
m = int64(100);
n = int64(500);
k = int64(4);
ncv = int64(10);
[nconv, sigma, u, v, resid, user, ifail] = ...
f02wg(m, n, k, ncv, @av);
res = [sigma(1:nconv) resid(1:nconv)];
fprintf(' Singular Value Residual\n');
fprintf(' %10.5f %12.2e\n',res');
function [iflag, ax, user] = av(iflag, m, n, x, user)
if (iflag == 1)
ax = zeros(m, 1);
else
ax = zeros(n, 1);
end
h = 1/(double(m)+1);
k = 1/(double(n)+1);
if (iflag == 1)
t = 0;
for j = 1:n
t = t + k;
s = 0;
ktx = k*(t-1)*x(j);
for i = 1:min(j,m)
s = s + h;
ax(i) = ax(i) + ktx*s;
end
ktx = k*t*x(j);
for i = j+1:m
s = s + h;
ax(i) = ax(i) + ktx*(s-1);
end
end
else
t = 0;
for j = 1:n
t = t + k;
s = 0;
for i = 1:min(j,m)
s = s + h;
ax(j) = ax(j) + k*s*(t-1)*x(i);
end
for i = j+1:m
s = s + h;
ax(j) = ax(j) + k*t*(s-1)*x(i);
end
end
end
f02wg example results
Singular Value Residual
0.00830 1.82e-18
0.01223 3.95e-18
0.02381 1.95e-17
0.11274 2.53e-17
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015