I need to diagonalize a symbolic matrix with python. In Mathematica it can be done easily, but when using the module numpy.linalg I get problems.
For concreteness, consider the matrix
[[2, x], [x, 3]]
where x is a symbolic variable. I guess I get problems because the numpy package is provided for numerical computations, not symbolic, but I cannot find how to do it with sympy.
You can compute it from the eigenvalues, but there is actually a method that will do it for you,
diagonalizeM.diagonalize()returns a pair of matrices(P, D)such thatM = P*D*P**-1. If it can't compute enough eigenvalues, either because the matrix is not diagonalizable or becausesolve()can't find all the roots of the characteristic polynomial, it will raiseMatrixError.See also this section of the SymPy tutorial.