I'm having some problems getting sympy to compute eigenvalues of a matrix with symbolic coefficients.
A trivial example is: In [4]: M = Matrix([[y, 0], [0, z]]) In [5]: M Out[5]: ⎡y 0⎤ ⎢ ⎥ ⎣0 z⎦ In [6]: M.eigenvals() Out[6]: ⎧ __________ __________ ⎫ ⎪ ╱ 2 ╱ 2 ⎪ ⎨y z ╲╱ (y - z) y z ╲╱ (y - z) ⎬ ⎪─ + ─ - ─────────────: 1, ─ + ─ + ─────────────: 1⎪ ⎩2 2 2 2 2 2 ⎭ Clearly the eigenvalues should be y and z so something has gone wrong. It seems that perhaps what happens is that the characteristic polynomial is expanded and then not re-factored when finding solutions: In [7]: (M - x*eye(2)) Out[7]: ⎡-x + y 0 ⎤ ⎢ ⎥ ⎣ 0 -x + z⎦ In [8]: (M - x*eye(2)).det() Out[8]: 2 x - x⋅y - x⋅z + y⋅z In [9]: solve((M - x*eye(2)).det(), x) Out[9]: ⎡ __________ __________⎤ ⎢ ╱ 2 ╱ 2 ⎥ ⎢y z ╲╱ (y - z) y z ╲╱ (y - z) ⎥ ⎢─ + ─ - ─────────────, ─ + ─ + ─────────────⎥ ⎣2 2 2 2 2 2 ⎦ In [10]: factor((M - x*eye(2)).det()) Out[10]: (x - y)⋅(x - z) In [11]: solve(factor((M - x*eye(2)).det()), x) Out[11]: [y, z] Presumably det calls expand and I'm not sure why it would want to do that. Also solve has clearly spotted that this is a second order polynomial since we're using the quadratic formula but no attempt at factorisation is made. I guess that without knowing knowing the sign of y - z you can't know whether sqrt((y-z)**2) is y - z or z - y so the quadratic formula cannot be simplified even though the original polynomial could. Is there some way to adjust this behaviour with flags etc.? Or is it just a case where sympy has some room for improvement? Oscar -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxQqEwSOnm0rR3qnfpKBEorgdcMYgVFSjjYL3Rc%2B5K4YeQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.