ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 09 May 2015 10:40:42 +0200Find out if matrix is positive semidefinitehttps://ask.sagemath.org/question/26773/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 precisionSat, 09 May 2015 09:09:24 +0200https://ask.sagemath.org/question/26773/find-out-if-matrix-is-positive-semidefinite/Answer by tmonteil for <p>What can I do to find out if a real or complex (symmetric/hermitian) matrix is positive definite (or better: positive semidefinite).</p>
<p>More specifically, the following code doesn't work:</p>
<pre><code>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()
</code></pre>
<p>It gives the error:</p>
<pre><code>TypeError: entries of the matrix must be in an exact ring, not Complex
Field with 53 bits of precision
</code></pre>
https://ask.sagemath.org/question/26773/find-out-if-matrix-is-positive-semidefinite/?answer=26775#post-id-26775When 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.
Sat, 09 May 2015 10:40:42 +0200https://ask.sagemath.org/question/26773/find-out-if-matrix-is-positive-semidefinite/?answer=26775#post-id-26775