# Det() returns negative values for a correlation matrix

**URL:** <https://discourse.julialang.org/t/det-returns-negative-values-for-a-correlation-matrix/92316>\
**Category:** General Usage\
**Tags:** linearalgebra\
**Created:** [December 30, 2022, 12:53pm UTC](https://discourse.julialang.org/t/det-returns-negative-values-for-a-correlation-matrix/92316 "2022-12-30T12:53:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mind4Ness](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mind4ness/32/38331_2.png) [@Mind4Ness](https://discourse.julialang.org/u/Mind4Ness)\
**Post date:** [December 30, 2022, 12:53pm UTC](https://discourse.julialang.org/t/det-returns-negative-values-for-a-correlation-matrix/92316/1 "2022-12-30T12:53:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [December 30, 2022, 1:40pm UTC](https://discourse.julialang.org/t/det-returns-negative-values-for-a-correlation-matrix/92316/2 "2022-12-30T13:40:19Z")

</div>

This is what I got:

```julia
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

```

---

<div class="post-metadata">

**Author:** ![Mind4Ness](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mind4ness/32/38331_2.png) [@Mind4Ness](https://discourse.julialang.org/u/Mind4Ness)\
**Post date:** [December 30, 2022, 1:53pm UTC](https://discourse.julialang.org/t/det-returns-negative-values-for-a-correlation-matrix/92316/3 "2022-12-30T13:53:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 30, 2022, 2:00pm UTC](https://discourse.julialang.org/t/det-returns-negative-values-for-a-correlation-matrix/92316/4 "2022-12-30T14:00:20Z")

</div>

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