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.Thu, 07 Oct 2021 10:53:53 +0200Diagonalize matrix numerically over $\mathbb{C}$https://ask.sagemath.org/question/59263/diagonalize-matrix-numerically-over-mathbbc/Suppose I have a matrix m:
$$
m = \left(\begin{array}{rr}
2 & -3 \\\\
1 & 0
\end{array}\right).
$$
It is diagonalizable and has complex eigenvalues.
I now want to diagonalize it, but get an error:
In [20]: m = matrix([[2, -3], [1, 0]]); m.diagonalization()
...
ValueError: matrix entries must be from a field
When I specify the field `m = matrix(CDF, [[2, -3], [1, 0]])`, I get `ValueError: base field must be exact, but Complex Double Field is not`. Specifying `ComplexLazyField()` instead of `CDF` raises `NotImplementedError`.
So, apparently, Sage is trying to diagonalize the matrix symbolically, i.e. exactly. But what if I don't care about exactness and just want a straightforward numerical answer?
This is how I would do it with `sympy`:
In [22]: import sympy as sp
...: m = sp.Matrix([[2, -3], [1, 0]])
...: m.diagonalize()
Out[22]:
(Matrix([
[1 - sqrt(2)*I, 1 + sqrt(2)*I],
[ 1, 1]]),
Matrix([
[1 - sqrt(2)*I, 0],
[ 0, 1 + sqrt(2)*I]]))
Notice that the output is actually exact. I know I can run this same Python code in Sage, but I assume there's a more native way to do it.
To sum up, **how do I get Sage to diagonalize a matrix over $\mathbb{C}$? How do I change the code if I only need the numerical answer?**SageUserNickThu, 07 Oct 2021 10:53:53 +0200https://ask.sagemath.org/question/59263/Orthonormal basis consisting of eigenvectors of a matrixhttps://ask.sagemath.org/question/26525/orthonormal-basis-consisting-of-eigenvectors-of-a-matrix/ How to find an orthonormal basis consisting of eigenvectors of a matrix. We assume that the matrix is over reals.Uday BhaskarTue, 14 Apr 2015 11:21:01 +0200https://ask.sagemath.org/question/26525/