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_complex_init (f12an)

Purpose

nag_sparseig_complex_init (f12an) is a setup function in a suite of functions consisting of nag_sparseig_complex_init (f12an), nag_sparseig_complex_iter (f12ap), nag_sparseig_complex_proc (f12aq), nag_sparseig_complex_option (f12ar) and nag_sparseig_complex_monit (f12as). It is used to find some of the eigenvalues (and optionally the corresponding eigenvectors) of a standard or generalized eigenvalue problem defined by complex nonsymmetric matrices.
The suite of functions is suitable for the solution of large sparse, standard or generalized, nonsymmetric complex eigenproblems where only a few eigenvalues from a selected range of the spectrum are required.

Syntax

[icomm, comm, ifail] = f12an(n, nev, ncv)
[icomm, comm, ifail] = nag_sparseig_complex_init(n, nev, ncv)

Description

The suite of functions is designed to calculate some of the eigenvalues, λ $\lambda$, (and optionally the corresponding eigenvectors, x $x$) of a standard complex eigenvalue problem Ax = λx $Ax=\lambda x$, or of a generalized complex eigenvalue problem Ax = λBx $Ax=\lambda Bx$ of order n $n$, where n $n$ is large and the coefficient matrices A $A$ and B $B$ are sparse, complex and nonsymmetric. The suite can also be used to find selected eigenvalues/eigenvectors of smaller scale dense, complex and nonsymmetric problems.
nag_sparseig_complex_init (f12an) is a setup function which must be called before nag_sparseig_complex_iter (f12ap), the reverse communication iterative solver, and before nag_sparseig_complex_option (f12ar), the options setting function. nag_sparseig_complex_proc (f12aq) is a post-processing function that must be called following a successful final exit from nag_sparseig_complex_iter (f12ap), while nag_sparseig_complex_monit (f12as) can be used to return additional monitoring information during the computation.
This setup function initializes the communication arrays, sets (to their default values) all options that can be set by you via the option setting function nag_sparseig_complex_option (f12ar), and checks that the lengths of the communication arrays as passed by you are of sufficient length. For details of the options available and how to set them see Section [Description of the Optional s] in (f12ar).

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:     n – int64int32nag_int scalar
The order of the matrix A$A$ (and the order of the matrix B$B$ for the generalized problem) that defines the eigenvalue problem.
Constraint: n > 0${\mathbf{n}}>0$.
2:     nev – int64int32nag_int scalar
The number of eigenvalues to be computed.
Constraint: 0 < nev < n1$0<{\mathbf{nev}}<{\mathbf{n}}-1$.
3:     ncv – int64int32nag_int scalar
The number of Arnoldi basis vectors to use during the computation.
At present there is no a priori analysis to guide the selection of ncv relative to nev. However, it is recommended that ncv2 × nev + 1${\mathbf{ncv}}\ge 2×{\mathbf{nev}}+1$. If many problems of the same type are to be solved, you should experiment with increasing ncv while keeping nev fixed for a given test problem. This will usually decrease the required number of matrix-vector operations but it also increases the work and 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: nev + 1 < ncvn${\mathbf{nev}}+1<{\mathbf{ncv}}\le {\mathbf{n}}$.

None.

licomm lcomm

Output Parameters

1:     icomm(max (1,licomm)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathit{licomm}\right)$) – int64int32nag_int array
Contains data to be communicated to the other functions in the suite.
2:     comm(max (1,lcomm)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathit{lcomm}\right)$) – complex array
Contains data to be communicated to the other functions in the suite.
3:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
On entry, n0${\mathbf{n}}\le 0$.
ifail = 2${\mathbf{ifail}}=2$
On entry, nev0${\mathbf{nev}}\le 0$.
ifail = 3${\mathbf{ifail}}=3$
On entry, ncv < nev + 2${\mathbf{ncv}}<{\mathbf{nev}}+2$ or ncv > n${\mathbf{ncv}}>{\mathbf{n}}$.
ifail = 4${\mathbf{ifail}}=4$
On entry, licomm < 140$\mathit{licomm}<140$ and licomm1$\mathit{licomm}\ne -1$.
ifail = 5${\mathbf{ifail}}=5$
On entry, lcomm < 3 × n + 3 × ncv × ncv + 5 × ncv + 60$\mathit{lcomm}<3×{\mathbf{n}}+3×{\mathbf{ncv}}×{\mathbf{ncv}}+5×{\mathbf{ncv}}+60$ and lcomm1$\mathit{lcomm}\ne -1$.

Not applicable.

None.

Example

function nag_sparseig_complex_init_example
n = int64(100);
nx = int64(10);
nev = int64(4);
ncv = int64(20);

irevcm = int64(0);
resid = complex(zeros(100,1));
v = complex(zeros(100,20));
x = complex(zeros(100,1));
mx = complex(zeros(100,1));

sigma = complex(0);

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

% Solve
while (irevcm ~= 5)
[irevcm, resid, v, x, mx, nshift, comm, icomm, ifail] = ...
nag_sparseig_complex_iter(irevcm, resid, v, x, mx, comm, icomm);
if (irevcm == 1 || irevcm == -1)
x = f12_av(nx, x);
elseif (irevcm == 4)
[niter, nconv, ritz, rzest] = nag_sparseig_complex_monit(icomm, comm);
fprintf('Iteration %d, No. converged = %d, norm of estimates = %16.8g\n',  ...
niter, nconv, norm(rzest(1:double(nev)),2));
end
end

% Post-process to compute eigenvalues/vectors
[nconv, d, z, v, comm, icomm, ifail] = ...
nag_sparseig_complex_proc(sigma, resid, v, comm, icomm);
% sort to avoid different orders showing up as error

function [w] = f12_av(nx, v)

inx = double(nx); % nx is int64

w = complex(zeros(inx*inx,1));

h2 = double(-(inx+1)^2);

w(1:inx) = tv(inx, v(1:inx));
w(1:inx) = h2*v(inx+1:2*inx)+w(1:inx);

for j=2:double(inx-1)
lo = (j-1)*inx +1;
hi = j*inx;

w(lo:hi) = tv(inx, v(lo:hi));
w(lo:hi) = h2*v(lo-inx:lo-1)+w(lo:hi);
w(lo:hi) = h2*v(hi+1:hi+inx)+w(lo:hi);
end

lo = (inx-1)*inx +1;
hi = inx*inx;
w(lo:hi) = tv(inx, v(lo:hi));
w(lo:hi) = h2*v(lo-inx:lo-1)+w(lo:hi);

function [y] = tv(inx,x)

y = zeros(inx,1);

dd = double(4*(inx+1)^2);
dl = double(-(inx+1)^2 - 0.5*100*(inx+1));
du = double(-(inx+1)^2 + 0.5*100*(inx+1));

y(1) = dd*x(1) + du*x(2);
for j=2:double(inx-1)
y(j) = dl*x(j-1) + dd*x(j) + du*x(j+1);
end
y(inx) = dl*x(inx-1) + dd*x(inx);

Iteration 1, No. converged = 0, norm of estimates =        133.43269
Iteration 2, No. converged = 0, norm of estimates =        99.725711
Iteration 3, No. converged = 0, norm of estimates =         42.48146
Iteration 4, No. converged = 0, norm of estimates =        8.1805323
Iteration 5, No. converged = 0, norm of estimates =        1.7794793
Iteration 6, No. converged = 0, norm of estimates =       0.49794897
Iteration 7, No. converged = 0, norm of estimates =       0.12604717
Iteration 8, No. converged = 0, norm of estimates =      0.026883649
Iteration 9, No. converged = 0, norm of estimates =     0.0070182429
Iteration 10, No. converged = 0, norm of estimates =     0.0014438635
Iteration 11, No. converged = 0, norm of estimates =    0.00040007427
Iteration 12, No. converged = 0, norm of estimates =     0.0001059392
Iteration 13, No. converged = 0, norm of estimates =     2.803229e-05
Iteration 14, No. converged = 0, norm of estimates =    7.7343157e-06
Iteration 15, No. converged = 0, norm of estimates =    1.9579037e-06
Iteration 16, No. converged = 0, norm of estimates =      6.15616e-07
Iteration 17, No. converged = 0, norm of estimates =    1.2591405e-07
Iteration 18, No. converged = 0, norm of estimates =    3.7790713e-08
Iteration 19, No. converged = 2, norm of estimates =    8.3787181e-09
Iteration 20, No. converged = 2, norm of estimates =    1.8827432e-09
Iteration 21, No. converged = 2, norm of estimates =    1.6920778e-10
Iteration 22, No. converged = 2, norm of estimates =     2.299125e-11
Iteration 23, No. converged = 2, norm of estimates =     3.391976e-12
Iteration 24, No. converged = 2, norm of estimates =    5.5954988e-13

function f12an_example
n = int64(100);
nx = int64(10);
nev = int64(4);
ncv = int64(20);

irevcm = int64(0);
resid = complex(zeros(100,1));
v = complex(zeros(100,20));
x = complex(zeros(100,1));
mx = complex(zeros(100,1));

sigma = complex(0);

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

% Solve
while (irevcm ~= 5)
[irevcm, resid, v, x, mx, nshift, comm, icomm, ifail] = ...
f12ap(irevcm, resid, v, x, mx, comm, icomm);
if (irevcm == 1 || irevcm == -1)
x = f12_av(nx, x);
elseif (irevcm == 4)
[niter, nconv, ritz, rzest] = f12as(icomm, comm);
fprintf('Iteration %d, No. converged = %d, norm of estimates = %16.8g\n', ...
niter, nconv, norm(rzest(1:double(nev)),2));
end
end

% Post-process to compute eigenvalues/vectors
[nconv, d, z, v, comm, icomm, ifail] = f12aq(sigma, resid, v, comm, icomm);
% sort to avoid different orders showing up as error

function [w] = f12_av(nx, v)

inx = double(nx); % nx is int64

w = complex(zeros(inx*inx,1));

h2 = double(-(inx+1)^2);

w(1:inx) = tv(inx, v(1:inx));
w(1:inx) = h2*v(inx+1:2*inx)+w(1:inx);

for j=2:double(inx-1)
lo = (j-1)*inx +1;
hi = j*inx;

w(lo:hi) = tv(inx, v(lo:hi));
w(lo:hi) = h2*v(lo-inx:lo-1)+w(lo:hi);
w(lo:hi) = h2*v(hi+1:hi+inx)+w(lo:hi);
end

lo = (inx-1)*inx +1;
hi = inx*inx;
w(lo:hi) = tv(inx, v(lo:hi));
w(lo:hi) = h2*v(lo-inx:lo-1)+w(lo:hi);

function [y] = tv(inx,x)

y = zeros(inx,1);

dd = double(4*(inx+1)^2);
dl = double(-(inx+1)^2 - 0.5*100*(inx+1));
du = double(-(inx+1)^2 + 0.5*100*(inx+1));

y(1) = dd*x(1) + du*x(2);
for j=2:double(inx-1)
y(j) = dl*x(j-1) + dd*x(j) + du*x(j+1);
end
y(inx) = dl*x(inx-1) + dd*x(inx);

Iteration 1, No. converged = 0, norm of estimates =        133.43269
Iteration 2, No. converged = 0, norm of estimates =        99.725711
Iteration 3, No. converged = 0, norm of estimates =         42.48146
Iteration 4, No. converged = 0, norm of estimates =        8.1805323
Iteration 5, No. converged = 0, norm of estimates =        1.7794793
Iteration 6, No. converged = 0, norm of estimates =       0.49794897
Iteration 7, No. converged = 0, norm of estimates =       0.12604717
Iteration 8, No. converged = 0, norm of estimates =      0.026883649
Iteration 9, No. converged = 0, norm of estimates =     0.0070182429
Iteration 10, No. converged = 0, norm of estimates =     0.0014438635
Iteration 11, No. converged = 0, norm of estimates =    0.00040007427
Iteration 12, No. converged = 0, norm of estimates =     0.0001059392
Iteration 13, No. converged = 0, norm of estimates =     2.803229e-05
Iteration 14, No. converged = 0, norm of estimates =    7.7343157e-06
Iteration 15, No. converged = 0, norm of estimates =    1.9579037e-06
Iteration 16, No. converged = 0, norm of estimates =      6.15616e-07
Iteration 17, No. converged = 0, norm of estimates =    1.2591405e-07
Iteration 18, No. converged = 0, norm of estimates =    3.7790713e-08
Iteration 19, No. converged = 2, norm of estimates =    8.3787181e-09
Iteration 20, No. converged = 2, norm of estimates =    1.8827432e-09
Iteration 21, No. converged = 2, norm of estimates =    1.6920778e-10
Iteration 22, No. converged = 2, norm of estimates =     2.299125e-11
Iteration 23, No. converged = 2, norm of estimates =     3.391976e-12
Iteration 24, No. converged = 2, norm of estimates =    5.5954988e-13