Ask Your Question

# 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

## 1 answer

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

## Your Answer

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

Add Answer

## Stats

Asked: 2015-05-09 02:09:24 -0600

Seen: 429 times

Last updated: May 09 '15