g g
g g

Reputation: 314

Sympy: Why is cholesky not working for this symmetric matrix?

I would like to find a symbolic Cholesky factorisation with Sympy. The Matrix M (see example) is real symmetric (hence hermitian). But Sympy raises ValueError: Matrix must be Hermitian.

Two questions:

  1. Why the error?
  2. What do I need to do to find my Cholesky factors?
from sympy import *
x, y = symbols('x y')

M = Matrix([
    [ exp(x**2), exp(x*y)],
    [  exp(x*y), exp(y**2)]
])

print(M == M.T) #True
L = M.cholesky() #ValueError: Matrix must be Hermitian.

Upvotes: 1

Views: 1188

Answers (1)

Vadim Shkaberda
Vadim Shkaberda

Reputation: 2936

  1. Matrix M is not Hermitian, because there is no restriction for values x and y to be complex.
  2. Since M is not necessary Hermitian, you should use

    M.cholesky(hermitian=False)
    
    Out[17]: 
    Matrix([
    [         sqrt(exp(x**2)),                                       0],
    [exp(x*y)/sqrt(exp(x**2)), sqrt(exp(y**2) - exp(-x**2)*exp(2*x*y))]])
    

hermitian is a parameter that appears in sympy version 1.4. You can find changes on this page. For earlier versions cholesky method works with your example as is.

Upvotes: 2

Related Questions