Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find characteristic polynomial of matrices by python?

Let $A$ be a $n\times n$ matrice. I want to calculate characteristic polynomial of $A$ i.e. I want to calculate $$det(xI-A)$$.

Is there any function which find this in python ?

like image 390
mesel Avatar asked Jan 06 '23 18:01

mesel


1 Answers

It sounds like you are interested in a symbolic solution? The characteristic polynomial doesn't make much sense numerically, where you would probably be more interested in the eigenvalues. To obtain the characteristic polynomial of a symbolic matrix M in SymPy you want to use the M.charpoly method.

For more information, see the SymPy documentation on matrices and linear algebra: http://docs.sympy.org/latest/modules/matrices/matrices.html

If you want to find the eigenvalues of a numpy array, numpy.linalg.eigvals (or numpy.linalg.eigvalsh if you have a Hermitian matrix) is what you want.

like image 90
dalum Avatar answered Jan 09 '23 20:01

dalum