Scilab Function
eigen - Eigenvalues and eigenvectors of sparse
matrix,
using ARPACK.
nv : Numbers of eigenvalues and eigenvectors
mode : 'R1'...'R7', 'S1'...'S6' or 'Z1'...'Z5', similar of the ARPACK modes.
which
'LM', eigenvalues of largest magnitude.
'SM', eigenvalues of smallest magnitude.
'LA', largest algebraic eigenvalues.
'SA', smallest algebraic eigenvalues.
For modes R2...7, S2...6 or Z2...5:
'LM', eigenvalues of largest magnitude.
'SM, eigenvalues of smallest magnitude.
'LR', eigenvalues of largest real part.
'SR', eigenvalues of smallest real part.
'LI', eigenvalues of largest imaginary part .
'SI', eigenvalues of smallest imaginary part.
OP : square sparse matrix, dependent of the problem.
sigm
:
The shift of eigenvalue.
M : square sparse matrix, dependent of the problem.
Problem: Ax= λ x
[va,ve]=eigen(nv, mode, which, OP );
where:
va - vector with eigenvalues.
ve - Matrix, each column is
the ith eigenvector.
nv - number
of eigenvalues and eigenvectors
mode = 's1' for A real and symmetric.
'r1' for A real and non-symetric.
'z1' for A complex.
which - string:
'LM', eigenvalues of largest magnitude,
'SM, eigenvalues of smallest magnitude,
'LA', largest algebraic eigenvalues,
'SA', smallest algebraic eigenvalues,
'BE', compute new eigenvalues, half from each end of
spectrum.
When nv is odd, compute one more from the high end than
from the low end.
OP.' = A.' , sparse
matrix.
Problem: Ax= λ x
[va,ve]=eigen(nv,mode,which,OP,sigm);
where:
va - vector with eigenvalues.
ve - Matrix, each column is
the ith eigenvector.
nv - number
of eigenvalues and eigenvectors.
mode = 's2' for A real and symmetric.
'r2' for A real and non-symetric.
'z2' for A complex.
which =
'LM', eigenvalues of largest magnitude.
'SM', eigenvalues of smallest
magnitude.
'LR', eigenvalues of largest real
part.
'SR', eigenvalues of smallest real
part.
'LI', eigenvalues of largest imaginary part
.
'SI', eigenvalues of smallest imaginary part.
OP.' = (A – sigm
I).' , sparse matrix, where sigm is a shift in
eigenvalues
and I the identity matrix.
sigm =
σ, shift in eigenvalues.
Problem: Ax= λ
B x, B IF
YOU DO NOT KNOW IF MATRIX B IS
POSITIVE SEMI-DEFINITE OR NOT!
[va,ve]=eigen(nv,mode,which,OP,sigm, M);
where:
va - vector with eigenvalues.
ve - Matrix, each column is
the ith eigenvector.
nv - number
of eigenvalues and eigenvectors.
mode = 'Z5 for A and B real.
which =
'LM', eigenvalues of largest magnitude.
'SM', eigenvalues of smallest
magnitude.
'LR', eigenvalues of largest real
part.
'SR', eigenvalues of smallest real
part.
'LI', eigenvalues of largest imaginary part
.
'SI', eigenvalues of smallest imaginary part.
OP.' = (A – sigm
B).' , sparse matrix, where sigm is a shift in
eigenvalues
and I the identity matrix.
sigm =
σ, shift in eigenvalues.
M.' = B. '
Problem: Ax= λ B x, B IF YOU DO NOT KNOW IF MATRIX B IS
POSITIVE SEMI-DEFINITE OR NOT!
[va,ve]=eigen(nv,mode,which,OP,sigm, M);
where:
va - vector with eigenvalues.
ve - Matrix, each column is
the ith eigenvector.
nv - number
of eigenvalues and eigenvectors.
mode = 'R5' for A and B real.
which =
'LM', eigenvalues of largest magnitude.
'SM', eigenvalues of smallest
magnitude.
'LR', eigenvalues of largest real
part.
'SR', eigenvalues of smallest real
part.
'LI', eigenvalues of largest imaginary part
.
'SI', eigenvalues of smallest imaginary part.
OP.' = (A – sigm
B).' , sparse matrix, where sigm is a shift in
eigenvalues
and I the identity matrix.
sigm =
σ, shift in eigenvalues.
M.' = B. ' ,POSITIVE
SEMI-DEFINITE
Problem: Ax= λ
B x, MATRIX
B MUST BE POSITIVE SEMI-DEFINITE
[va,ve]=eigen(nv,mode,which,OP,M);
where:
va - vector with eigenvalues.
ve - Matrix, each column is
the ith eigenvector.
nv - number
of eigenvalues and eigenvectors.
mode = 'S3' for A and B real and symmetric.
'R3' for A and B real and one of then
non-symetric.
'Z3' for A or B complex.
which =
'LM', eigenvalues of largest magnitude.
'SM', eigenvalues of smallest
magnitude.
'LR', eigenvalues of largest real
part.
'SR', eigenvalues of smallest real
part.
'LI', eigenvalues of largest imaginary part
.
'SI', eigenvalues of smallest imaginary part.
OP.' = B.' . Sparse matrix.
M.' = A.', Sparse matrix.
Problem:
Ax= λ B x,
B MUST BE POSITIVE SEMI-DEFINITE
[va,ve]=eigen(nv,mode,which,OP,sigm,M);
where:
va - vector with eigenvalues.
ve - Matrix, each column is
the ith eigenvector.
nv - number
of eigenvalues and eigenvectors.
mode = 'S4' for A and B real and symmetric.
'R4' for A and B real and one of then
non-symetric.
'Z4' for A or B complex.
which =
'LM', eigenvalues of largest magnitude.
'SM', eigenvalues of smallest
magnitude.
'LR', eigenvalues of largest real
part.
'SR', eigenvalues of smallest real
part.
'LI', eigenvalues of largest imaginary part
.
'SI', eigenvalues of smallest imaginary part.
OP.' = (A – sigm
B).' , sparse matrix, where sigm is a shift in
eigenvalues
and I the identity matrix.
sigm =
σ, shift in eigenvalues.
M.' = B. '
// MATRIX EIGENVALUES
//A complex.
n=20;
A=rand(n,n)+%i*rand(n,n);
MATA=sparse(A);
which='LM';amode='Z1';nv=6;
[Z ,vasp]=spec(A);vasp=diag(vasp);
[va,ve]=eigen(nv,amode,which,MATA );
max(abs(A*ve(:,1)-ve(:,1)* va(1)))
max(abs(A* Z(:,1)- Z(:,1)*vasp(1)))
[vat,ps]=sort(real(vasp));
[vat,pe]=sort(real(va ));
[vasp(ps(1:size(va,1))) va(pe)]
//A real.
n=20;
A=rand(n,n);
MATA=sparse(A);
which='LM';amode='R1';nv=6;
[Z ,vasp]=spec(A);vasp=diag(vasp);
[va,ve]=eigen(nv,amode,which,MATA );
max(abs(A*ve(:,1)-ve(:,1)* va(1)))
max(abs(A* Z(:,1)- Z(:,1)*vasp(1)))
[vat,ps]=sort(real(vasp));
[vat,pe]=sort(real(va ));
[vasp(ps(1:size(va,1))) va(pe)]
//A real and symmetric.
n=20;
A=rand(n,n);
A=A+A';
MATA=sparse(A);
which='LM';amode='R1';nv=6;
[Z ,vasp]=spec(A);vasp=diag(vasp);
[va,ve]=eigen(nv,amode,which,MATA );
max(abs(A*ve(:,1)-ve(:,1)* va(1)))
max(abs(A* Z(:,1)- Z(:,1)*vasp(1)))
[vat,ps]=sort(real(vasp));
[vat,pe]=sort(real(va ));
[vasp(ps(1:size(va,1))) va(pe)]
// PENCIL EIGENVALUES
//A and B real.
n=20;
A=rand(n,n);
B=rand(n,n);
A=A+A';
B=B+B';
sigm=8;
OP=A-sigm*B;
MATOP=sparse(OP);
MATM=sparse(B);
which='LM';amode='R7';nv=6;
[al,be,Q,Z]=spec(A,B);vasp=al./be;
[va,ve]=eigen(nv,amode,which,MATOP,sigm,MATM);
max(abs(A*ve(:,1)-B*ve(:,1)* va(1)))
max(abs(A* Z(:,1)-B* Z(:,1)*vasp(1)))
[vat,ps]=sort(real(vasp));
[vat,pe]=sort(real(va ));
[vasp(ps(1:size(va,1))) va(pe)]
//A or B complex.
n=20;
A=rand(n,n)+rand(n,n)*%i;
B=rand(n,n)+rand(n,n)*%i;
sigm=8;
OP=A-sigm*B;
MATOP=sparse(OP);
MATM=sparse(B);
which='LM';amode='Z5';nv=6;
[al,be,Q,Z]=spec(A,B);vasp=al./be;
[va,ve]=eigen(nv,amode,which,MATOP,sigm,MATM);
max(abs(A*ve(:,1)-B*ve(:,1)* va(1)))
max(abs(A* Z(:,1)-B* Z(:,1)*vasp(1)))
[vat,ps]=sort(real(vasp));
[vat,pe]=sort(real(va ));
[vasp(ps(1:size(va,1))) va(pe)]
//A and B real, B positive semi-definite
n=20;
A=rand(n,n);
B=rand(n,n);
for i=1:n,B(i,i)=100*B(i,i);,end
if max(imag(spec(B)))== 0 then,
sigma=8;
MATOP=sparse(B);
MATM=sparse(A);
which='LR';amode='R3';nv=6;
[al,be,Q,Z]=spec(A,B);vasp=al./be;
[va,ve]=eigen(nv,amode,which,MATOP,MATM);
max(abs(A*ve(:,1)-B*ve(:,1)* va(1)))
max(abs(A* Z(:,1)-B* Z(:,1)*vasp(1)))
[vat,ps]=sort(real(vasp));
[vat,pe]=sort(real(va ));
[vasp(ps(1:size(va,1))) va(pe)],
end
//A and B real, B positive semi-definite
n=20;
A=rand(n,n);
B=rand(n,n);
for i=1:n,B(i,i)=100*B(i,i);,end
if max(imag(spec(B)))== 0 then,
sigm=8;
MATOP=sparse(A-sigm*B);
MATM=sparse(B);
which='LM';amode='R4';nv=6;
[al,be,Q,Z]=spec(A,B);vasp=al./be;
[va,ve]=eigen(nv,amode,which,MATOP,sigm,MATM);
max(abs(A*ve(:,1)-B*ve(:,1)* va(1)))
max(abs(A* Z(:,1)-B* Z(:,1)*vasp(1)))
[vat,ps]=sort(real(vasp));
[vat,pe]=sort(real(va ));
[vasp(ps(1:size(va,1))) va(pe)],
end
//A and B real, symmetric, B positive semi-definite
n=20;
A=rand(n,n);
B=rand(n,n);
A=A+A';B=B+B' ;
for i=1:n,B(i,i)=100*B(i,i);,end
if max(imag(spec(B)))== 0 then,
sigma=8;
MATOP=sparse(B);
MATM=sparse(A);
which='LM';amode='S3';nv=6;
[al,be,Q,Z]=spec(A,B);vasp=al./be;
[va,ve]=eigen(nv,amode,which,MATOP,MATM);
max(abs(A*ve(:,1)-B*ve(:,1)* va(1)))
max(abs(A* Z(:,1)-B* Z(:,1)*vasp(1)))
[vat,ps]=sort(real(vasp));
[vat,pe]=sort(real(va ));
[vasp(ps(1:size(va,1))) va(pe)],
end
//A and B real, symmetric, B positive semi-definite
n=20;
A=rand(n,n);
B=rand(n,n);
A=A+A';B=B+B' ;
for i=1:n,B(i,i)=100*B(i,i);,end
if max(imag(spec(B)))== 0 then,
sigm=8;
MATOP=sparse(A-sigm*B);
MATM=sparse(B);
which='LM';amode='S4';nv=6;
[al,be,Q,Z]=spec(A,B);vasp=al./be;
[va,ve]=eigen(nv,amode,which,MATOP,sigm,MATM);
max(abs(A*ve(:,1)-B*ve(:,1)* va(1)))
max(abs(A* Z(:,1)-B* Z(:,1)*vasp(1)))
[vat,ps]=sort(real(vasp));
[vat,pe]=sort(real(va ));
[vasp(ps(1:size(va,1))) va(pe)],
end
spec ;