eigvals

eigvals(A,[irange,][vl,][vu]) -> values

Returns the eigenvalues of A. If A is Symmetric, Hermitian or SymTridiagonal, it is possible to calculate only a subset of the eigenvalues by specifying either a UnitRange irange covering indices of the sorted eigenvalues, or a pair vl and vu for the lower and upper boundaries of the eigenvalues.

For general non-symmetric matrices it is possible to specify how the matrix is balanced before the eigenvector calculation. The option permute=true permutes the matrix to become closer to upper triangular, and scale=true scales the matrix by its diagonal elements to make rows and columns moreequal in norm. The default is true for both options.

Examples

eigvals(A, [irange,][vl,][vu]) -> values

Returns the eigenvalues of `A`. If `A` is `Symmetric`, `Hermitian`, or `SymTridiagonal`, it is possible to calculate only a subset of the eigenvalues by specifying either a `UnitRange` `irange` covering indices of the sorted eigenvalues, or a pair `vl` and `vu` for the lower and upper boundaries of the eigenvalues.

For general non-symmetric matrices, it is possible to specify how the matrix is balanced before the eigenvector calculation. The option `permute=true` permutes the matrix to become closer to upper triangular, and `scale=true` scales the matrix by its diagonal elements to make rows and columns more equal in norm. The default is `true` for both options.

# Examples

```julia
julia> A = [1 2; 3 4];
julia> eigvals(A)
2-element Array{Complex{Float64},1}:
 -0.3722813232690143 + 0.0im
  5.372281323269014 + 0.0im

In this example, the function eigvals computes and returns the eigenvalues of the matrix A.

julia> B = [1 2 3; 4 5 6; 7 8 9];
julia> eigvals(B, [2:3])
2-element Array{Complex{Float64},1}:
 -1.5615528128088303 + 0.0im
 16.561552812808827 + 0.0im

Here, the function eigvals calculates only the eigenvalues with indices 2 to 3 (inclusive) from the matrix B.

julia> C = [1 2 3; 4 5 6; 7 8 9];
julia> eigvals(C, 1, 10)
3-element Array{Complex{Float64},1}:
 -1.116843969807043 + 0.0im
 15.116843969807043 + 0.0im
  0.0 + 0.0im

In this example, the function eigvals calculates only the eigenvalues within the range of 1 to 10 (inclusive) from the matrix C.

julia> D = [1 2; 3 4];
julia> eigvals(D, permute=true, scale=true)
2-element Array{Complex{Float64},1}:
 0.3722813232690143 + 0.0im
 5.6277186767309855 + 0.0im

Here, the function eigvals calculates the eigenvalues of matrix D with matrix balancing options enabled.

julia> E = [1 2 3; 4 5 6; 7 8 9];
julia> eigvals(E, [1:2], permute=false, scale=false)
2-element Array{Complex{Float64},1}:
 -4.999999999999998 + 0.0im
 24.999999999999993 + 0.0im

In this example, the function eigvals calculates only the eigenvalues with indices 1 to 2 (inclusive) from the matrix E without performing matrix balancing.

Common Mistake

julia> F = [1 2; 3 4];
julia> eigvals(F, [3:4])
ERROR: ArgumentError: Invalid range [3:4] for eigenvalue subset.

In this example, the provided range [3:4] is invalid because the matrix F only has 2 eigenvalues. Ensure that the range or boundaries provided for the eigenvalue subset are within the valid range to avoid this error.

See Also

Ac_ldiv_B, Ac_ldiv_Bc, Ac_mul_B, Ac_mul_Bc, Ac_rdiv_B, Ac_rdiv_Bc, At_ldiv_B, At_ldiv_Bt, At_mul_B, At_mul_Bt, At_rdiv_B, At_rdiv_Bt, A_ldiv_Bc, A_ldiv_Bt, A_mul_B!, A_mul_Bc, A_mul_Bt, A_rdiv_Bc, A_rdiv_Bt, Bidiagonal, cond, conv2, det, diag, diagind, diagm, diff, eig, eigvals, eigvecs, expm, eye, full, inv, isdiag, ishermitian, isposdef, isposdef!, issym, istril, istriu, logabsdet, logdet, lyap, norm, qrfact, rank, repmat, rot180, rotl90, rotr90, sortrows, sqrtm, SymTridiagonal, trace, Tridiagonal, tril, tril!, triu, triu!, writedlm,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: