Isposdef() true with small negative eigenvalues?

So basically your matrix is singular, which means that the tiniest deviation caused by floating point inaccuracy can change its character. What isposdef does is to try and compute a Cholesky decomposition and in fact this succeeds:

julia> cholesky(r'r)
Cholesky{Float64, Matrix{Float64}}
U factor:
9×9 UpperTriangular{Float64, Matrix{Float64}}:
 1.41421  -2.12132    0.707107    0.0      …  0.0       0.0        0.0
  ⋅        0.707107  -0.707107    0.0         0.0       0.0        0.0
  ⋅         ⋅         2.10734e-8  0.0         0.0       0.0        0.0
  ⋅         ⋅          ⋅          1.41421     0.0       0.0        0.0
  ⋅         ⋅          ⋅           ⋅          0.0       0.0        0.0
  ⋅         ⋅          ⋅           ⋅       …  0.0       0.0        0.0
  ⋅         ⋅          ⋅           ⋅          1.41421  -2.12132    0.707107
  ⋅         ⋅          ⋅           ⋅           ⋅        0.707107  -0.707107
  ⋅         ⋅          ⋅           ⋅           ⋅         ⋅         2.10734e-8

So from a numerical point of view your matrix might as well be positive definite. Probably the safest way to check for semi-definiteness is to also examine the eigenvalues/singular values and see whether they are large enough.

julia> diag(ans.L)
9-element Vector{Float64}:
 1.4142135623730951
 0.7071067811865481
 2.1073424255447017e-8
 1.4142135623730951
 0.7071067811865481
 2.1073424255447017e-8
 1.4142135623730951
 0.7071067811865481
 2.1073424255447017e-8

You see 3 values of order \sqrt{eps} which means that the original matrix might as well be singular (and it is in this case). Generally determining exactly whether a matrix is singular is a difficult task numerically and essentially impossible. Best you can do is compute some eigen-/singular values and use a cutoff to decide which should be zero. This is what rank does e.g.

julia> rank(r'r)
6

So to summarize: The title is not quite true. Your matrix is singular which is hard to detect. Perhaps the docstring of isposdef should warn about this more.

1 Like