# Find out if matrix is positive semidefinite

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:

reset()
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])
mm.is_positive_definite()


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 close merge delete

Sort by » oldest newest most voted

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.

more