1

I was expecting eigenvalues 0, 1, 3 (that's what I got with WolframAlpha and SageMath). What happened?

julia> using LinearAlgebra

julia> eigvals([1 -1 0; -1 2 -1; 0 -1 1])
3-element Array{Float64,1}:
 3.9250536344271737e-17
 0.9999999999999998
 3.0
peterh
  • 11,875
  • 18
  • 85
  • 108
sbac
  • 1,897
  • 1
  • 18
  • 31
  • 1
    They basically are. Those are essentially 0, 1 and 3; just with some error. – Carcigenicate Jun 07 '19 at 00:01
  • 4
    Possible duplicate of [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Carcigenicate Jun 07 '19 at 00:02
  • 2
    Specifically of note is that eigenvalues of integer matrices aren't always integers. – Oscar Smith Jun 07 '19 at 02:21
  • 1
    This is expected behaviour. Wolfram and Sage probably calculates the eigenvalues symbolically for small matrices. Julia (like Matlab, Numpy, etc.) does it numerically, and there you can expect floating point errors. The errors you see are in line with these other languages. – DNF Jun 07 '19 at 07:54
  • @DNF Yes, using Numpy: ```In [5]: print("Eigenvalues : ",np.linalg.eigvals(np.mat("1 -1 0; -1 2 -1; ...: 0 -1 1"))) Eigenvalues : [ 3.00000000e+00 1.00000000e+00 -3.36770206e-17]``` – sbac Jun 08 '19 at 12:21

0 Answers0