Get an eigvec by eigval, using eigvecs, only allow SymTridiagonal?

The eigvecs(A, λ) method is currently only implemented for SymTridiagonal matrices. For other matrix types there is currently only eigvecs(A).

In principle, we could easily extend this to real-symmetric/Hermitian matrices, since they can be transformed into real SymTridiagonal matrices by the Hessenberg factorization. This should work:

using LinearAlgebra
import LinearAlgebra: eigvecs, RealHermSymComplexHerm

function eigvecs(A::RealHermSymComplexHerm, λ::AbstractVector{<:Real})
    F = hessenberg(A) # transform to SymTridiagonal form
    X = eigvecs(F.H, λ)
    return F.Q * X    # transform eigvecs of F.H back to eigvecs of A
end

For only computing a small subset of the eigenvectors, it seems to be a couple times faster than eigvecs, especially if you don’t count the cost of the eigenvalues (e.g. you already have them for some other reason).

Might be worth putting together a PR to LinearAlgebra.jl if you are interested in this functionality? eigvecs(A::Hermitian, eigvals) method? · Issue #1248 · JuliaLang/LinearAlgebra.jl · GitHub

No. nullspace employs an SVD, which is as costly as computing all the eigenvectors and eigenvalues with eigen. (In fact, the SVD calls eigen for Hermitian matrices.)

1 Like