Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_sparseig_real_symm_proc (f12fc)

## Purpose

nag_sparseig_real_symm_proc (f12fc) is a post-processing function in a suite of functions which includes nag_sparseig_real_symm_init (f12fa), nag_sparseig_real_symm_iter (f12fb), nag_sparseig_real_symm_option (f12fd) and nag_sparseig_real_symm_monit (f12fe). nag_sparseig_real_symm_proc (f12fc) must be called following a final exit from nag_sparseig_real_symm_iter (f12fb).

## Syntax

[nconv, d, z, v, comm, icomm, ifail] = f12fc(sigma, resid, v, comm, icomm)
[nconv, d, z, v, comm, icomm, ifail] = nag_sparseig_real_symm_proc(sigma, resid, v, comm, icomm)

## Description

The suite of functions is designed to calculate some of the eigenvalues, $\lambda$, (and optionally the corresponding eigenvectors, $x$) of a standard eigenvalue problem $Ax=\lambda x$, or of a generalized eigenvalue problem $Ax=\lambda Bx$ of order $n$, where $n$ is large and the coefficient matrices $A$ and $B$ are sparse, real and symmetric. The suite can also be used to find selected eigenvalues/eigenvectors of smaller scale dense, real and symmetric problems.
Following a call to nag_sparseig_real_symm_iter (f12fb), nag_sparseig_real_symm_proc (f12fc) returns the converged approximations to eigenvalues and (optionally) the corresponding approximate eigenvectors and/or an orthonormal basis for the associated approximate invariant subspace. The eigenvalues (and eigenvectors) are selected from those of a standard or generalized eigenvalue problem defined by real symmetric matrices. There is negligible additional cost to obtain eigenvectors; an orthonormal basis is always computed, but there is an additional storage cost if both are requested.
nag_sparseig_real_symm_proc (f12fc) is based on the function dseupd from the ARPACK package, which uses the Implicitly Restarted Lanczos iteration 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 some of the interfaces.
nag_sparseig_real_symm_proc (f12fc), is a post-processing function that must be called following a successful final exit from nag_sparseig_real_symm_iter (f12fb). nag_sparseig_real_symm_proc (f12fc) uses data returned from nag_sparseig_real_symm_iter (f12fb) and options, set either by default or explicitly by calling nag_sparseig_real_symm_option (f12fd), to return the converged approximations to selected eigenvalues and (optionally):
 – the corresponding approximate eigenvectors; – an orthonormal basis for the associated approximate invariant subspace; – both.

## 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

### Compulsory Input Parameters

1:     $\mathrm{sigma}$ – double scalar
If one of the Shifted Inverse (see nag_sparseig_real_symm_option (f12fd)) modes has been selected then sigma contains the real shift used; otherwise sigma is not referenced.
2:     $\mathrm{resid}\left(:\right)$ – double array
The dimension of the array resid must be at least ${\mathbf{n}}$ (see nag_sparseig_real_symm_init (f12fa))
Must not be modified following a call to nag_sparseig_real_symm_iter (f12fb) since it contains data required by nag_sparseig_real_symm_proc (f12fc).
3:     $\mathrm{v}\left(\mathit{ldv},:\right)$ – double array
The first dimension of the array v must be at least $n$.
The second dimension of the array v must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncv}}\right)$.
The ncv columns of v contain the Lanczos basis vectors for $\mathrm{OP}$ as constructed by nag_sparseig_real_symm_iter (f12fb).
4:     $\mathrm{comm}\left(:\right)$ – double array
The dimension of the array comm must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{lcomm}}\right)$ (see nag_sparseig_real_symm_init (f12fa))
On initial entry: must remain unchanged from the prior call to nag_sparseig_real_symm_init (f12fa).
5:     $\mathrm{icomm}\left(:\right)$int64int32nag_int array
The dimension of the array icomm must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{licomm}}\right)$ (see nag_sparseig_real_symm_init (f12fa))
On initial entry: must remain unchanged from the prior call to nag_sparseig_real_symm_init (f12fa).

None.

### Output Parameters

1:     $\mathrm{nconv}$int64int32nag_int scalar
The number of converged eigenvalues as found by nag_sparseig_real_symm_iter (f12fb).
2:     $\mathrm{d}\left(:\right)$ – double array
The dimension of the array d will be ${\mathbf{ncv}}$ (see nag_sparseig_real_symm_init (f12fa))
The first nconv locations of the array d contain the converged approximate eigenvalues.
3:     $\mathrm{z}\left({\mathbf{n}}×\left({\mathbf{nev}}+1\right)\right)$ – double array
If the default option ${\mathbf{Vectors}}=\mathrm{RITZ}$ (see nag_sparseig_real_symm_option (f12fd)) has been selected then z contains the final set of eigenvectors corresponding to the eigenvalues held in d. The real eigenvector associated with an eigenvalue is stored in the corresponding column of z.
4:     $\mathrm{v}\left(\mathit{ldv},:\right)$ – double array
The first dimension of the array v will be $n$.
The second dimension of the array v will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ncv}}\right)$.
If the option ${\mathbf{Vectors}}=\mathrm{SCHUR}$ has been set, or the option ${\mathbf{Vectors}}=\mathrm{RITZ}$ has been set and a separate array z has been passed (i.e., z does not equal v), then the first nconv columns of v will contain approximate Schur vectors that span the desired invariant subspace.
5:     $\mathrm{comm}\left(:\right)$ – double array
The dimension of the array comm will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{lcomm}}\right)$ (see nag_sparseig_real_symm_init (f12fa))
Contains data on the current state of the solution.
6:     $\mathrm{icomm}\left(:\right)$int64int32nag_int array
The dimension of the array icomm will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{licomm}}\right)$ (see nag_sparseig_real_symm_init (f12fa))
Contains data on the current state of the solution.
7:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
On entry, $\mathit{ldz}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ or $\mathit{ldz}<1$ when no vectors are required.
${\mathbf{ifail}}=2$
On entry, the option ${\mathbf{Vectors}}=\text{Select}$ was selected, but this is not yet implemented.
${\mathbf{ifail}}=3$
The number of eigenvalues found to sufficient accuracy prior to calling nag_sparseig_real_symm_proc (f12fc), as communicated through the argument icomm, is zero.
${\mathbf{ifail}}=4$
The number of converged eigenvalues as calculated by nag_sparseig_real_symm_iter (f12fb) differ from the value passed to it through the argument icomm.
${\mathbf{ifail}}=5$
Unexpected error during calculation of a tridiagonal form: there was a failure to compute all the converged eigenvalues. Please contact NAG.
${\mathbf{ifail}}=6$
${\mathbf{ifail}}=7$
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The relative accuracy of a Ritz value, $\lambda$, is considered acceptable if its Ritz estimate $\le {\mathbf{Tolerance}}×\left|\lambda \right|$. The default Tolerance used is the machine precision given by nag_machine_precision (x02aj).

None.

## Example

This example solves $Ax=\lambda Bx$ in regular mode, where $A$ and $B$ are obtained from the standard central difference discretization of the one-dimensional Laplacian operator $\frac{{d}^{2}u}{d{x}^{2}}$ on $\left[0,1\right]$, with zero Dirichlet boundary conditions.
```function f12fc_example

fprintf('f12fc example results\n\n');

n   = int64(100);
nev = int64(4);
ncv = int64(10);
imon = 0;

irevcm = int64(0);
resid = ones(n,1);
v     = zeros(n,ncv);
x     = zeros(n,1);
mx    = zeros(n,1);

sigma = 0;

% Setup and factorize B
h   = 1/double(n+1);

% Initialisation Step
[icomm, comm, ifail] = f12fa( ...
n, nev, ncv);

% Set Optional Parameters
[icomm, comm, ifail] = f12fd( ...
'Generalized', icomm, comm);
% Solve
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)
% Solve By = Ax
mx = f12fc_Ax(n, x);
[x, info] = f07ce( ...
elseif (irevcm == 2)
% y = Bx
mx = f12fc_Bx(n, 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

% Post-process to compute eigenvalues/vectors
[nconv, d, z, v, comm, icomm, ifail] = ...
f12fc( ...
sigma, resid, v, comm, icomm);

fprintf('Largest %d Eigenvalues are:\n',nconv);
fprintf('%10.1f\n',d(1:nconv));

function [y] = f12fc_Ax(n, x)

y = zeros(n,1);
h = 1/double(n+1);

y(1) = 2*x(1) - x(2);
for j=2:n-1
y(j) = -x(j-1) + 2*x(j) - x(j+1);
end
y(n) = -x(n-1) + 2*x(n);
y = y/h;

function [y] = f12fc_Bx(n,x)

y = zeros(n,1);
h = 1/(6*double(n+1));

y(1) = 4*x(1) + x(2);
for j=2:n-1
y(j) = x(j-1) + 4*x(j) + x(j+1);
end
y(n) = x(n-1) + 4*x(n);
y = y*h;
```
```f12fc example results

Largest 4 Eigenvalues are:
121003.5
121616.6
122057.5
122323.2
```