PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_sparseig_real_symm_iter (f12fb)
Purpose
nag_sparseig_real_symm_iter (f12fb) is an iterative solver in a suite of functions consisting of
nag_sparseig_real_symm_init (f12fa),
nag_sparseig_real_symm_iter (f12fb),
nag_sparseig_real_symm_proc (f12fc),
nag_sparseig_real_symm_option (f12fd) and
nag_sparseig_real_symm_monit (f12fe). It is used to find some of the eigenvalues (and optionally the corresponding eigenvectors) of a standard or generalized eigenvalue problem defined by real symmetric matrices.
Syntax
[
irevcm,
resid,
v,
x,
mx,
nshift,
comm,
icomm,
ifail] = f12fb(
irevcm,
resid,
v,
x,
mx,
comm,
icomm)
[
irevcm,
resid,
v,
x,
mx,
nshift,
comm,
icomm,
ifail] = nag_sparseig_real_symm_iter(
irevcm,
resid,
v,
x,
mx,
comm,
icomm)
Description
The suite of functions is designed to calculate some of the eigenvalues, , (and optionally the corresponding eigenvectors, ) of a standard eigenvalue problem , or of a generalized eigenvalue problem of order , where is large and the coefficient matrices and are sparse, real and symmetric. The suite can also be used to find selected eigenvalues/eigenvectors of smaller scale dense, real and symmetric problems.
nag_sparseig_real_symm_iter (f12fb) is a
reverse communication function, based on the ARPACK routine
dsaupd, using the Implicitly Restarted Arnoldi iteration method, which for symmetric problems reduces to a variant of the Lanczos method. The method is described in
Lehoucq and Sorensen (1996) and
Lehoucq (2001) while its use within the ARPACK software is described in great detail in
Lehoucq et al. (1998). An evaluation of software for computing eigenvalues of sparse symmetric matrices is provided in
Lehoucq and Scott (1996). This suite of functions offers the same functionality as the ARPACK software for real symmetric problems, but the interface design is quite different in order to make the option setting clearer and to simplify the interface of
nag_sparseig_real_symm_iter (f12fb).
The setup function
nag_sparseig_real_symm_init (f12fa) must be called before
nag_sparseig_real_symm_iter (f12fb), the reverse communication iterative solver. Options may be set for
nag_sparseig_real_symm_iter (f12fb) by prior calls to the option setting function
nag_sparseig_real_symm_option (f12fd) and a post-processing function
nag_sparseig_real_symm_proc (f12fc) must be called following a successful final exit from
nag_sparseig_real_symm_iter (f12fb).
nag_sparseig_real_symm_monit (f12fe), may be called following certain flagged, intermediate exits from
nag_sparseig_real_symm_iter (f12fb) to provide additional monitoring information about the computation.
nag_sparseig_real_symm_iter (f12fb) uses
reverse communication, i.e., it returns repeatedly to the calling program with the argument
irevcm (see
Arguments) set to specified values which require the calling program to carry out one of the following tasks:
– |
compute the matrix-vector product , where is defined by the computational mode; |
– |
compute the matrix-vector product ; |
– |
notify the completion of the computation; |
– |
allow the calling program to monitor the solution. |
The problem type to be solved (standard or generalized), the spectrum of eigenvalues of interest, the mode used (regular, regular inverse, shifted inverse, Buckling or Cayley) and other options can all be set using the option setting function
nag_sparseig_real_symm_option (f12fd).
References
Lehoucq R B (2001) Implicitly restarted Arnoldi methods and subspace iteration SIAM Journal on Matrix Analysis and Applications 23 551–562
Lehoucq R B and Scott J A (1996) An evaluation of software for computing eigenvalues of sparse nonsymmetric matrices Preprint MCS-P547-1195 Argonne National Laboratory
Lehoucq R B and Sorensen D C (1996) Deflation techniques for an implicitly restarted Arnoldi iteration SIAM Journal on Matrix Analysis and Applications 17 789–821
Lehoucq R B, Sorensen D C and Yang C (1998) ARPACK Users' Guide: Solution of Large-scale Eigenvalue Problems with Implicitly Restarted Arnoldi Methods SIAM, Philidelphia
Parameters
Note: this function uses
reverse communication. Its use involves an initial entry, intermediate exits and re-entries, and a final exit, as indicated by the argument
irevcm. Between intermediate exits and re-entries,
all arguments other than x, mx and comm must remain unchanged.
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
On initial entry: , otherwise an error condition will be raised.
On intermediate re-entry: must be unchanged from its previous exit value. Changing
irevcm to any other value between calls will result in an error.
Constraint:
on initial entry,
; on re-entry
irevcm must remain unchanged.
- 2:
– double array
-
The dimension of the array
resid
must be at least
(see
nag_sparseig_real_symm_init (f12fa))
On initial entry: need not be set unless the option
Initial Residual has been set in a prior call to
nag_sparseig_real_symm_option (f12fd) in which case
resid should contain an initial residual vector, possibly from a previous run.
On intermediate re-entry: must be unchanged from its previous exit. Changing
resid to any other value between calls may result in an error exit.
- 3:
– double array
-
The first dimension of the array
v must be at least
.
The second dimension of the array
v must be at least
.
On initial entry: need not be set.
On intermediate re-entry: must be unchanged from its previous exit.
- 4:
– double array
-
The dimension of the array
x
must be at least
(see
nag_sparseig_real_symm_init (f12fa))
On initial entry: need not be set, it is used as a convenient mechanism for accessing elements of
comm.
On intermediate re-entry: if
,
x need not be set.
If
,
x must contain the result of
when
irevcm returns the value
or
. It must return the real parts of the computed shifts when
irevcm returns the value
.
- 5:
– double array
-
The dimension of the array
mx
must be at least
(see
nag_sparseig_real_symm_init (f12fa))
On initial entry: need not be set, it is used as a convenient mechanism for accessing elements of
comm.
On intermediate re-entry: if
,
mx need not be set.
If
,
mx must contain the result of
when
irevcm returns the value
. It must return the imaginary parts of the computed shifts when
irevcm returns the value
.
- 6:
– double array
-
The dimension of the array
comm
must be at least
(see
nag_sparseig_real_symm_init (f12fa))
On initial entry: must remain unchanged following a call to the setup function
nag_sparseig_real_symm_init (f12fa).
- 7:
– int64int32nag_int array
-
The dimension of the array
icomm
must be at least
(see
nag_sparseig_real_symm_init (f12fa))
On initial entry: must remain unchanged following a call to the setup function
nag_sparseig_real_symm_init (f12fa).
Optional Input Parameters
None.
Output Parameters
- 1:
– int64int32nag_int scalar
-
On intermediate exit:
has the following meanings.
- The calling program must compute the matrix-vector product , where is stored in x (by default) or in the array comm (starting from the location given by the first element of icomm) when the option is set in a prior call to nag_sparseig_real_symm_option (f12fd). The result is returned in x (by default) or in the array comm (starting from the location given by the second element of icomm) when the option is set.
- The calling program must compute the matrix-vector product . This is similar to the case except that the result of the matrix-vector product (as required in some computational modes) has already been computed and is available in mx (by default) or in the array comm (starting from the location given by the third element of icomm) when the option is set.
- The calling program must compute the matrix-vector product , where is stored in x and is returned in mx (by default) or in the array comm (starting from the location given by the second element of icomm) when the option is set.
- Compute the nshift real and imaginary parts of the shifts where the real parts are to be returned in the first nshift locations of the array x and the imaginary parts are to be returned in the first nshift locations of the array mx. Only complex conjugate pairs of shifts may be applied and the pairs must be placed in consecutive locations. This value of irevcm will only arise if the optional parameter Supplied Shifts is set in a prior call to nag_sparseig_real_symm_option (f12fd) which is intended for experienced users only; the default and recommended option is to use exact shifts (see Lehoucq et al. (1998) for details and guidance on the choice of shift strategies).
- Monitoring step: a call to nag_sparseig_real_symm_monit (f12fe) can now be made to return the number of Arnoldi iterations, the number of converged Ritz values, their real and imaginary parts, and the corresponding Ritz estimates.
On final exit:
:
nag_sparseig_real_symm_iter (f12fb) has completed its tasks. The value of
ifail determines whether the iteration has been successfully completed, or whether errors have been detected. On successful completion
nag_sparseig_real_symm_proc (f12fc) must be called to return the requested eigenvalues and eigenvectors (and/or Schur vectors).
- 2:
– double array
-
The dimension of the array
resid will be
(see
nag_sparseig_real_symm_init (f12fa))
On intermediate exit:
contains the current residual vector.
On final exit: contains the final residual vector.
- 3:
– double array
-
The first dimension of the array
v will be
.
The second dimension of the array
v will be
.
On intermediate exit:
contains the current set of Arnoldi basis vectors.
On final exit: contains the final set of Arnoldi basis vectors.
- 4:
– double array
-
The dimension of the array
x will be
(see
nag_sparseig_real_symm_init (f12fa))
On intermediate exit:
if
,
x is not referenced.
If
,
x contains the vector
when
irevcm returns the value
or
.
On final exit: does not contain useful data.
- 5:
– double array
-
The dimension of the array
mx will be
(see
nag_sparseig_real_symm_init (f12fa))
On intermediate exit:
if
,
mx is not referenced.
If
,
mx contains the vector
when
irevcm returns the value
.
On final exit: does not contain any useful data.
- 6:
– int64int32nag_int scalar
-
On intermediate exit:
if the option
Supplied Shifts is set and
irevcm returns a value of
,
nshift returns the number of complex shifts required.
- 7:
– double array
-
The dimension of the array
comm will be
(see
nag_sparseig_real_symm_init (f12fa))
Contains data defining the current state of the iterative process.
- 8:
– int64int32nag_int array
-
The dimension of the array
icomm will be
(see
nag_sparseig_real_symm_init (f12fa))
Contains data defining the current state of the iterative process.
- 9:
– int64int32nag_int scalar
On final exit:
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
On initial entry, the maximum number of iterations
, the option
Iteration Limit has been set to a non-positive value.
-
-
The options
Generalized and
Regular are incompatible.
-
-
Eigenvalues from both ends of the spectrum were requested, but the number of eigenvalues requested is one.
-
-
The option
Initial Residual was selected but the starting vector held in
resid is zero.
- W
-
The maximum number of iterations has been reached. Some Ritz values may have converged; a subsequent call to
nag_sparseig_real_symm_proc (f12fc) will return the number of converged values and the converged values.
-
-
No shifts could be applied during a cycle of the implicitly restarted Arnoldi iteration. One possibility is to increase the size of
ncv relative to
nev (see
Arguments in
nag_sparseig_real_symm_init (f12fa) for details of these arguments).
-
-
Could not build a Lanczos factorization. Consider changing
ncv or
nev in the initialization function (see
Arguments in
nag_sparseig_real_symm_init (f12fa) for details of these arguments).
-
-
Unexpected error in internal call to compute eigenvalues and corresponding error bounds of the current upper Hessenberg matrix. Please contact
NAG.
-
-
An unexpected error has occurred. Please contact
NAG.
-
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
The relative accuracy of a Ritz value,
, is considered acceptable if its Ritz estimate
. The default
Tolerance used is the
machine precision given by
nag_machine_precision (x02aj).
Further Comments
None.
Example
For this function two examples are presented, with a main program and two example problems given in Example 1 (EX1) and Example 2 (EX2).
Example 1 (EX1)
The example solves in shift-invert mode, where is obtained from the standard central difference discretization of the one-dimensional Laplacian operator with zero Dirichlet boundary conditions. Eigenvalues closest to the shift are sought.
Example 2 (EX2)
This example illustrates the use of
nag_sparseig_real_symm_iter (f12fb) to compute the leading terms in the singular value decomposition of a real general matrix
. The example finds a few of the largest singular values (
) and corresponding right singular values (
) for the matrix
by solving the symmetric problem:
Here
is the
by
real matrix derived from the simplest finite difference discretization of the two-dimensional kernal
where
Open in the MATLAB editor:
f12fb_example
function f12fb_example
fprintf('f12fb example results\n\n');
fprintf('Example 1:\n');
ex1;
fprintf('Example 2:\n\n');
ex2;
function ex1
n = int64(100);
nev = int64(4);
ncv = int64(10);
imon = 0;
irevcm = int64(0);
resid = zeros(n,1);
v = zeros(n,ncv);
x = zeros(n,1);
mx = zeros(n,1);
sig = 0;
h = 1/double(n+1);
h2 = h*h;
ad(1:n) = 2/h2 - sig;
adl(1:n) = -1/h2;
adu(1:n) = adl(1:n);
[adl, ad, adu, adu2, ipiv, info] = f07cd( ...
adl, ad, adu);
[icomm, comm, ifail] = f12fa( ...
n, nev, ncv);
[icomm, comm, ifail] = f12fd( ...
'Shifted Inverse', icomm, comm);
while (irevcm ~= 5)
[irevcm, resid, v, x, mx, nshift, comm, icomm, ifail] = ...
f12fb( ...
irevcm, resid, v, x, mx, comm, icomm);
if (irevcm == 1 || irevcm == -1)
[x, info] = f07ce( ...
'N', adl, ad, adu, adu2, ipiv, x);
elseif (irevcm == 4 && imon==1)
[niter, nconv, ritz, rzest] = f12fe( ...
icomm, comm);
fprintf(['Iteration %2d, No. converged = %d, ', ...
'norm of estimates = %10.2e\n'], ...
niter, nconv, norm(rzest(1:nev),2));
end
end
[nconv, d, z, v, comm, icomm, ifail] = ...
f12fc( ...
sig, resid, v, comm, icomm);
fprintf('\nThe %d Eigenvalues of smallest magnitude are:\n',nconv);
disp(d(1:nconv));
function ex2
m = int64(500);
n = int64(100);
nev = int64(4);
ncv = int64(10);
irevcm = int64(0);
resid = zeros(n,1);
v = zeros(n,ncv);
x = zeros(n,1);
mx = zeros(n,1);
sigma = 0;
[icomm, comm, ifail] = f12fa( ...
n, nev, ncv);
while (irevcm ~= 5)
[irevcm, resid, v, x, mx, nshift, comm, icomm, ifail] = ...
f12fb( ...
irevcm, resid, v, x, mx, comm, icomm);
if (irevcm == 1 || irevcm == -1)
y = f12fb_Ax(m,n,x);
x = f12fb_Atx(m,n,y);
end
end
[nconv, d, z, v, comm, icomm, ifail] = ...
f12fc( ...
sigma, resid, v, comm, icomm);
for j = 1:nconv
d(j,1) = sqrt(d(j,1));
ax = f12fb_Ax(m,n,v(:,j));
u(:,j) = ax/norm(ax);
resid(j) = norm(ax - d(j,1)*u(:,j));
end
fprintf('Leading %d singular values and direct residuals:\n',nconv);
fprintf('%9.5f%12.2e\n',[d(1:nconv) resid(1:nconv)]');
function [y] = f12fb_Ax(m,n,x)
y = zeros(m,1);
h = 1/double(m+1);
k = 1/double(n+1);
t = 0;
for j=1:n
t = t + k;
s = 0;
for l = 1:j
s = s + h;
y(l) = y(l) + k*s*(t-1)*x(j);
end
for l = j+1:m
s = s + h;
y(l) = y(l) + k*t*(s-1)*x(j);
end
end
function [y] = f12fb_Atx(m,n,x)
y = zeros(n,1);
h = 1/double(m+1);
k = 1/double(n+1);
t = 0;
for j=1:n
t = t + k;
s = 0;
for l = 1:j
s = s + h;
y(j) = y(j) + k*s*(t-1)*x(l);
end
for l = j+1:m
s = s + h;
y(j) = y(j) + k*t*(s-1)*x(l);
end
end
f12fb example results
Example 1:
The 4 Eigenvalues of smallest magnitude are:
9.8688
39.4657
88.7620
157.7101
Example 2:
Leading 4 singular values and direct residuals:
0.04101 2.74e-17
0.06049 2.83e-17
0.11784 5.62e-17
0.55723 2.28e-16
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015