Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia: eigs() function doesn't return all eigenvalues

Tags:

arrays

julia

I am using the eigs() function (from the Arpack package) to find the eigenvalues of a sparse matrix (eigen() doesn't work for spare matrices). Apparently, eigs() fails to find all the eigenvalues, even in a very simple case:

using Arpack
M = spdiagm(0 => [1,2,3])
eigs(M, nev = 3)

The output of the last line is a vector contacting only 2 eigenvalues, "2" and "3" ("1" is missing). What am I missing? Is there a different function for computing the eigenvalues of a sparse matrix (the actual sparse matrix is much large than the above M).

like image 561
Sergey Avatar asked Mar 03 '23 03:03

Sergey


1 Answers

It actually shows at warning:

julia> eigs(Matrix(M), nev = 3);
┌ Warning: Adjusting nev from 3 to 2
└ @ Arpack c:\JuliaPkg\Julia1.5.0\packages\Arpack\o35I5\src\Arpack.jl:82

Looking at the source code this can return a maximum of LinearAlgebra.checksquare(M) - 1 values.

What you could try to do is to use a BandedMatrix instead which is also sparse:

julia> m=BandedMatrix(0=>1:3)
3×3 BandedMatrix{Int64,Array{Int64,2},Base.OneTo{Int64}}:
 1  ⋅  ⋅
 ⋅  2  ⋅
 ⋅  ⋅  3

julia> eigen(m)
Eigen{Float64,Float64,Array{Float64,2},Array{Float64,1}}
values:
3-element Array{Float64,1}:
 1.0
 2.0
 3.0
vectors:
3×3 Array{Float64,2}:
 1.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  1.0
like image 164
Przemyslaw Szufel Avatar answered Mar 06 '23 17:03

Przemyslaw Szufel