2

The Python SymPy Matrix API has a method to determine the eigenvalue. I would like to do similar thing with SymPy MutableDenseMatrix. Unfortunately, the API doesn't allow me to do it.

Is there any way to do it?

Omar Shehab
  • 1,004
  • 3
  • 14
  • 26
  • 1
    Maybe look at implementation of Matrix.eigenvals() and see if this can be implemented for MutableDenseMatrix - or can you for the prupose of determining the eigenvalues by transforming the MutableDenseMatrix instance into a Matrix instance ;-) – Dilettant Jun 04 '16 at 10:08
  • @Dilettant, how can I transform MutableDenseMatrix into Matrix? – Omar Shehab Jun 04 '16 at 10:13
  • 1
    Did you try already something like `b = MutableDenseMatrix(...); a = Matrix(b); b.eigenvals()` - sometimes it is as simple as this, where a copy of the values of a is used to initialize b ...? – Dilettant Jun 04 '16 at 10:29
  • 1
    It worked nicely - only had to install sympy first. Please cf. my answer and if you like it, maybe accept it :-) Thanks for the question, and maybe next time simply try this pattern, when simlar classes have a missing method (and intuition does not make clear, why it is missing in the first place). – Dilettant Jun 04 '16 at 10:36

1 Answers1

3

As suggested in my comment, it must of course be a square matrix, but then simply construct a Matrix out of your MutableDenseMatrix:

>>> from sympy.matrices.dense import MutableDenseMatrix
>>> from sympy.matrices import Matrix
>>> a = MutableDenseMatrix([[1,0,0], [0,0,0], [2, -2, 3]])
>>> b = Matrix(a)
>>> b.eigenvals()
{0: 1, 1: 1, 3: 1}
Dilettant
  • 3,267
  • 3
  • 29
  • 29