Det() returns negative values for a correlation matrix

Sometimes det() function returns a negative number for a correlation matrix (even it’s just 3x3). I’m not sure what is wrong.

using Random, using Distributions

Random.seed!(3)

x = cor(rand(Uniform(-1,1),10,3))
3×3 Matrix{Float64}:
1.0 -0.618963 -0.538684
-0.618963 1.0 0.191318
-0.538684 0.191318 1.0

det(x)
-0.9523875996033169

isposdef(x)
true

This is what I got:

julia> using Random, Distributions, LinearAlgebra

julia> Random.seed!(3)
TaskLocalRNG()

julia> x = cor(rand(Uniform(-1,1),10,3))
3×3 Matrix{Float64}:
 1.0        0.336313   0.283692
 0.336313   1.0       -0.14194
 0.283692  -0.14194    1.0

julia> det(x)
0.7591802490614455

julia> isposdef(x)
true
1 Like

Thanks! It’s somebody else’s code and he wrote a different function under the same name.

i.e. you are calling some other function called det (not LinearAlgebra.det), and it’s not a determinant (or it is buggy).