Ask Your Question

Find out if matrix is positive semidefinite

asked 2015-05-09 09:09:24 +0200

Oderyn gravatar image

updated 2020-06-01 11:43:58 +0200

FrédéricC gravatar image

What can I do to find out if a real or complex (symmetric/hermitian) matrix is positive definite (or better: positive semidefinite).

More specifically, the following code doesn't work:

f(t) = exp(I*t)
ts = [random() for k in range(3)]
var('k, l')
mm = matrix(CC,len(ts))
for k in range(1,len(ts)):
    for l in range(1,len(ts)):
        mm[k,l] = f(ts[k] - ts[l])

It gives the error:

TypeError: entries of the matrix must be in an exact ring, not Complex
Field with 53 bits of precision
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-05-09 10:40:42 +0200

tmonteil gravatar image

updated 2015-05-09 10:43:15 +0200

When you use random() and CC, you deal with approximate floating-point numbers. Since the fact of being positive semidefinite is sensitive to small perturbation, you will not get reliable result, this is why the field should be exact (i.e. not made of approximate numbers). Since you use exponentials, it is not clear how to deal in an exact ring provided by Sage (such as algebraic numbers).

That said, it seems that working with CDF instead of CC (the former uses algorithms provided by numpy/scipy which are supposed to be numerically more stable than the ones for CC which are usually quite naive) answers something, but you should be careful with interpreting the result.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-05-09 09:09:24 +0200

Seen: 1,587 times

Last updated: May 09 '15