Jutho / KrylovKit.jl

Krylov methods for linear problems, eigenvalues, singular values and matrix functions
Other
284 stars 37 forks source link

[Question] Eigenvalue from eigsolve by Lanczos is not correct #66

Closed zxm403089989 closed 1 year ago

zxm403089989 commented 1 year ago

I am trying to obtain the smallest eigenvalue of a real symmetric matrix. Here are my codes:

using LinearAlgebra,KrylovKit,Arpack
A = rand(Float64,(10,10)) .- one(Float64)/2;
A=(A+A')/2;
eigsolve(A,1,:SR;krylovdim =4, maxiter =100, tol = precision(Float64))[1]
1-element Vector{Float64}:
 -0.02558177613350929
data = eigen(A);
data.values[1]
-0.978221881847597

Clearly I catch the wrong answer. Compare with Arpack result:

eigs(A,nev=1,which=:SR,maxiter=2)[1]
1-element Vector{Float64}:
 -0.9782218818475978

Probably my inputs are not correct, if so, I hope some explicit examples to use KrylovKit.

zxm403089989 commented 1 year ago

I remove the precision(Float64) then it's correct.

Jutho commented 1 year ago

Note that precision(Float64) equals 53, so that is probably not the tolerance you want, and the result you got is correct within that tolerance window :-) . You probably intended something like eps(Float64).