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_band_solve (f12fg)

## Purpose

nag_sparseig_real_symm_band_solve (f12fg) is the main solver function in a suite of functions which includes nag_sparseig_real_symm_option (f12fd) and nag_sparseig_real_symm_band_init (f12ff). nag_sparseig_real_symm_band_solve (f12fg) must be called following an initial call to nag_sparseig_real_symm_band_init (f12ff) and following any calls to nag_sparseig_real_symm_option (f12fd).
nag_sparseig_real_symm_band_solve (f12fg) returns approximations to selected eigenvalues, and (optionally) the corresponding eigenvectors, of a standard or generalized eigenvalue problem defined by real banded symmetric matrices. The banded matrix must be stored using the LAPACK storage format for real banded nonsymmetric matrices.

## Syntax

[nconv, d, z, resid, v, comm, icomm, ifail] = f12fg(kl, ku, ab, mb, sigma, resid, comm, icomm)
[nconv, d, z, resid, v, comm, icomm, ifail] = nag_sparseig_real_symm_band_solve(kl, ku, ab, mb, sigma, resid, 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 banded, real and symmetric.
Following a call to the initialization function nag_sparseig_real_symm_band_init (f12ff), nag_sparseig_real_symm_band_solve (f12fg) 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 banded symmetric matrices. There is negligible additional computational cost to obtain eigenvectors; an orthonormal basis is always computed, but there is an additional storage cost if both are requested.
The banded matrices $A$ and $B$ must be stored using the LAPACK storage format for banded nonsymmetric matrices; please refer to Packed storage in the F07 Chapter Introduction for details on this storage format.
nag_sparseig_real_symm_band_solve (f12fg) is based on the banded driver functions dsbdr1 to dsbdr6 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). This suite of functions offers the same functionality as the ARPACK banded driver software for real symmetric problems, but the interface design is quite different in order to make the option setting clearer and to combine the different drivers into a general purpose function.
nag_sparseig_real_symm_band_solve (f12fg), is a general purpose forward communication function that must be called following initialization by nag_sparseig_real_symm_band_init (f12ff). nag_sparseig_real_symm_band_solve (f12fg) uses 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{kl}$int64int32nag_int scalar
The number of subdiagonals of the matrices $A$ and $B$.
Constraint: ${\mathbf{kl}}\ge 0$.
2:     $\mathrm{ku}$int64int32nag_int scalar
The number of superdiagonals of the matrices $A$ and $B$. Since $A$ and $B$ are symmetric, the normal case is ${\mathbf{ku}}={\mathbf{kl}}$.
Constraint: ${\mathbf{ku}}\ge 0$.
3:     $\mathrm{ab}\left(\mathit{ldab},:\right)$ – double array
The first dimension of the array ab must be at least $2×{\mathbf{kl}}+{\mathbf{ku}}+1$.
The second dimension of the array ab must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
Must contain the matrix $A$ in LAPACK banded storage format for nonsymmetric matrices (see Band storage in the F07 Chapter Introduction).
4:     $\mathrm{mb}\left(\mathit{ldmb},:\right)$ – double array
The first dimension of the array mb must be at least $2×{\mathbf{kl}}+{\mathbf{ku}}+1$.
The second dimension of the array mb must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
Must contain the matrix $B$ in LAPACK banded storage format for nonsymmetric matrices (see Band storage in the F07 Chapter Introduction).
5:     $\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.
6:     $\mathrm{resid}\left(:\right)$ – double array
The dimension of the array resid must be at least ${\mathbf{n}}$ (see nag_sparseig_real_symm_band_init (f12ff))
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 must contain an initial residual vector.
7:     $\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_band_init (f12ff))
On initial entry: must remain unchanged from the prior call to nag_sparseig_real_symm_option (f12fd) and nag_sparseig_real_symm_band_init (f12ff).
8:     $\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_band_init (f12ff))
On initial entry: must remain unchanged from the prior call to nag_sparseig_real_symm_iter (f12fb) and nag_sparseig_real_symm_option (f12fd).

None.

### Output Parameters

1:     $\mathrm{nconv}$int64int32nag_int scalar
The number of converged eigenvalues.
2:     $\mathrm{d}\left(:\right)$ – double array
The dimension of the array d will be ${\mathbf{ncv}}$ (see nag_sparseig_real_symm_band_init (f12ff))
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 eigenvalue $\mathit{i}-1$, for $\mathit{i}=1,2,\dots ,{\mathbf{nconv}}$, is stored in the $\mathit{i}$th column of z.
4:     $\mathrm{resid}\left(:\right)$ – double array
The dimension of the array resid will be ${\mathbf{n}}$ (see nag_sparseig_real_symm_band_init (f12ff))
Contains the final residual vector.
5:     $\mathrm{v}\left({\mathbf{n}}×{\mathbf{ncv}}\right)$ – double array
If the option Vectors (see nag_sparseig_real_symm_option (f12fd)) has been set to Schur or Ritz and a separate array z has been passed then the first ${\mathbf{nconv}}×n$ elements of v will contain approximate Schur vectors that span the desired invariant subspace.
The $j$th Schur vector is stored in the $i$th column of v.
6:     $\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_band_init (f12ff))
Contains no useful information.
7:     $\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_band_init (f12ff))
Contains no useful information.
8:     $\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:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

${\mathbf{ifail}}=1$
On entry, ${\mathbf{kl}}<0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{ku}}<0$.
${\mathbf{ifail}}=3$
On entry, $\mathit{ldab}<2×{\mathbf{kl}}+{\mathbf{ku}}+1$.
${\mathbf{ifail}}=4$
${\mathbf{Iteration Limit}}<0$.
${\mathbf{ifail}}=5$
The options Generalized and Regular are incompatible.
${\mathbf{ifail}}=6$
Eigenvalues from Both Ends of the spectrum were requested, but only one eigenvalue (nev) is requested.
${\mathbf{ifail}}=7$
The Initial Residual was selected but the starting vector held in resid is zero.
${\mathbf{ifail}}=8$
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}}=9$
On entry, the option ${\mathbf{Vectors}}=\text{Select}$ was selected, but this is not yet implemented.
${\mathbf{ifail}}=10$
The number of eigenvalues found to sufficient accuracy is zero.
${\mathbf{ifail}}=11$
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).
${\mathbf{ifail}}=12$
Unexpected error in internal call to compute eigenvalues and corresponding error bounds of the current symmetric tridiagonal matrix. Please contact NAG.
${\mathbf{ifail}}=13$
Unexpected error during calculation of a real Schur form: there was a failure to compute all the converged eigenvalues. Please contact NAG.
${\mathbf{ifail}}=14$
${\mathbf{ifail}}=15$
W  ${\mathbf{ifail}}=16$
The maximum number of iterations has been reached. Some Ritz values may have converged; nconv returns the number of converged values.
${\mathbf{ifail}}=17$
No shifts could be applied during a cycle of the implicitly restarted Lanczos iteration. One possibility is to increase the size of ncv relative to nev (see Arguments in nag_sparseig_real_symm_band_init (f12ff) for details of these arguments).
${\mathbf{ifail}}=18$
${\mathbf{ifail}}=19$
${\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 x$ in regular mode, where $A$ is obtained from the standard central difference discretization of the two-dimensional convection-diffusion operator $\frac{{d}^{2}u}{d{x}^{2}}+\frac{{d}^{2}u}{d{y}^{2}}=\rho \frac{du}{dx}$ on the unit square with zero Dirichlet boundary conditions. $A$ is stored in LAPACK banded storage format.
```function f12fg_example

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

nx  = int64(10);
n   = nx^2;
nev = int64(4);
ncv = int64(10);

% Banded matrices and dimensions
kl  = nx;
ku  = nx;
mb  = zeros(2*kl+ku+1,n);
ab  = zeros(2*kl+ku+1,n);

% Construct the matrix A in banded form and store in ab.
% Main diagonal of A.
h2 = 1/double((nx+1)*(nx+1));
ab(kl+ku+1,1:n) = 4/h2;

% First sub- and super-diagonal of A.
ab(kl+ku,   1:n) = -1/h2;
ab(kl+ku+2, 1:n) = -1/h2;
ab(kl+ku,   1:nx:n) = 0;
ab(kl+ku+2,nx:nx:n) = 0;
% kl-th subdiagonal and ku-th super-diagonal.
ab(kl+1     ,nx+1:n) = -1/h2;
ab(2*kl+ku+1,1:n-nx) = -1/h2;

% Solver setup
[icomm, comm, ifail] = f12ff( ...
n, nev, ncv);

% Solver
sigma = 0;
resid = zeros(n,1);
[nconv, d, z, resid, v, comm, icomm, ifail] = ...
f12fg( ...
kl, ku, ab, mb, sigma, resid, comm, icomm);

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

```
```f12fg example results

Largest 4 Eigenvalues
891.17
919.78
919.78
948.39
```