# [SciPy-dev] Matlab function eigs(A,B) in scipy

Nils Wagner nwagner at mecha.uni-stuttgart.de
Mon Jun 16 10:06:21 CDT 2003

```Hi all,

I wonder if the matlab function eigs will be available in scipy in the
near future.

Any suggestion ?

Nils

>>help eigs

EIGS  Find a few eigenvalues and eigenvectors of a matrix using ARPACK.
D = EIGS(A) returns a vector of A's 6 largest magnitude eigenvalues.
A must be square and should be large and sparse.

[V,D] = EIGS(A) returns a diagonal matrix D of A's 6 largest
magnitude
eigenvalues and a matrix V whose columns are the corresponding
eigenvectors.

[V,D,FLAG] = EIGS(A) also returns a convergence flag.  If FLAG is 0
then all the eigenvalues converged; otherwise not all converged.

EIGS(A,B) solves the generalized eigenvalue problem A*V == B*V*D.  B
must
be symmetric (or Hermitian) positive definite and the same size as
A.
EIGS(A,[],...) indicates the standard eigenvalue problem A*V == V*D.

EIGS(A,K) and EIGS(A,B,K) return the K largest magnitude
eigenvalues.

EIGS(A,K,SIGMA) and EIGS(A,B,K,SIGMA) return K eigenvalues based on
SIGMA:
'LM' or 'SM' - Largest or Smallest Magnitude
For real symmetric problems, SIGMA may also be:
'LA' or 'SA' - Largest or Smallest Algebraic
'BE' - Both Ends, one more from high end if K is odd
For nonsymmetric and complex problems, SIGMA may also be:
'LR' or 'SR' - Largest or Smallest Real part
'LI' or 'SI' - Largest or Smallest Imaginary part
If SIGMA is a real or complex scalar including 0, EIGS finds the
eigenvalues
closest to SIGMA.  For scalar SIGMA, and also when SIGMA = 'SM'
which uses
the same algorithm as SIGMA = 0, B need only be symmetric (or
Hermitian)
positive semi-definite since it is not Cholesky factored as in the
other cases.

EIGS(A,K,SIGMA,OPTS) and EIGS(A,B,K,SIGMA,OPTS) specify options:
OPTS.issym: symmetry of A or A-SIGMA*B represented by AFUN [{0} | 1]
OPTS.isreal: complexity of A or A-SIGMA*B represented by AFUN [0 |
{1}]
OPTS.tol: convergence: Ritz estimate residual <= tol*NORM(A) [scalar
| {eps}]
OPTS.maxit: maximum number of iterations [integer | {300}]
OPTS.p: number of Lanczos vectors: K+1<p<=N [integer | {2K}]
OPTS.v0: starting vector [N-by-1 vector | {randomly generated by
ARPACK}]
OPTS.disp: diagnostic information display level [0 | {1} | 2]
OPTS.cholB: B is actually its Cholesky factor CHOL(B) [{0} | 1]
OPTS.permB: sparse B is actually CHOL(B(permB,permB)) [permB |
{1:N}]

EIGS(AFUN,N) accepts the function AFUN instead of the matrix A.
Y = AFUN(X) should return
A*X            if SIGMA is not specified, or is a string other
than 'SM'
A\X            if SIGMA is 0 or 'SM'
(A-SIGMA*I)\X  if SIGMA is a nonzero scalar (standard eigenvalue
problem)
(A-SIGMA*B)\X  if SIGMA is a nonzero scalar (generalized
eigenvalue problem)
N is the size of A. The matrix A, A-SIGMA*I or A-SIGMA*B represented
by AFUN is
assumed to be real and nonsymmetric unless specified otherwise by
OPTS.isreal
and OPTS.issym. In all these EIGS syntaxes, EIGS(A,...) may be
replaced by
EIGS(AFUN,N,...).

EIGS(AFUN,N,K,SIGMA,OPTS,P1,P2,...) and
EIGS(AFUN,N,B,K,SIGMA,OPTS,P1,P2,...)
provide for additional arguments which are passed to
AFUN(X,P1,P2,...).

Examples:
A = delsq(numgrid('C',15));  d1 = eigs(A,5,'SM');
Equivalently, if dnRk is the following one-line function:
function y = dnRk(x,R,k)
y = (delsq(numgrid(R,k))) \ x;
then pass dnRk's additional arguments, 'C' and 15, to EIGS:
n = size(A,1);  opts.issym = 1;  d2 =
eigs(@dnRk,n,5,'SM',opts,'C',15);