Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LinearAlgebra] strange isposdef behavior #32106

Closed
utotch opened this issue May 21, 2019 · 2 comments
Closed

[LinearAlgebra] strange isposdef behavior #32106

utotch opened this issue May 21, 2019 · 2 comments

Comments

@utotch
Copy link

utotch commented May 21, 2019

In my observation, isposdef sometimes return false for positive definite matrices.

I think isposdef in the code below should both return true.
C's eigval is all positive, thus C should be posdef, I think, but posdef(C) returns false.

Am I wrong?

using Random
using LinearAlgebra
Random.seed!(0)

R = rand(3,3)
A = R./eigvals(R)[1]
B = A'*(2.0*[1 0 0; 0 1 0; 0 0 1])*A
C = A'*(3.0*[1 0 0; 0 1 0; 0 0 1])*A
@show eigvals(B) # all positive
@show eigvals(C) # all positive
@show isposdef(B) # true
@show isposdef(C) # false!

versioninfo()

eigvals(B) = [0.00334175, 0.24934, 2.97084]
eigvals(C) = [4.45626, 0.374009, 0.00501262] <-- All Positive
isposdef(B) = true
isposdef(C) = false <- Why?
Julia Version 1.1.1
Commit 55e36cc (2019-05-16 04:10 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin15.6.0)
CPU: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, broadwell)
Environment:
JULIA_DIR = /Applications/Julia-1.1.app/Contents/Resources/julia
JULIA_HOME = /Applications/Julia-1.1.app/Contents/Resources/julia/bin
JULIA_EDITOR = atom -a
JULIA_NUM_THREADS = 2

@dkarrasch
Copy link
Member

This is due to ishermitian(C) gives false, for which the reason is that

julia> C-C'
3×3 Array{Float64,2}:
  0.0          0.0  5.55112e-17
  0.0          0.0  0.0        
 -5.55112e-17  0.0  0.0

So, I guess the question is whether one wants to allow for some tolerance in the asymmetry/non-Hermitianess.

julia> isposdef(Hermitian(C))
true

On the other hand, I suspect that one would like to enforce users to wrap their presumably Hermitian matrices as Hermitians explicitly.

@KristofferC
Copy link
Member

See e.g. JuliaLang/LinearAlgebra.jl#182.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants