# [SciPy-user] any symbolic manipulation of eigenvalue in Scipy?

Harald Schilly harald.schilly@gmail....
Tue Jun 9 11:46:20 CDT 2009

```On Tue, Jun 9, 2009 at 18:35, Xiaojian Wang<wangxj.uc@gmail.com> wrote:
> if not, do you guy know any other programs can do this?

I don't know it about scipy, but In Sage ( http://www.sagemath.org )
you can do this:

sage: var('a b c')
(a, b, c)
sage: m = matrix([[a, b, a*b], [a + b, 0, 0], [c, a, b + c]])
sage: m_evals = m.eigenvalues()
sage: m_evals

[-1/18*(-I*sqrt(3) + 1)*(((3*c + 2)*b - c)*a + a^2 + 4*b^2 + 2*b*c +
c^2)/(1/54*(27*b + 2)*a^3 + 1/18*((3*c + 2)*b + 9*b^2 - c)*a^2 -
8/27*b^3 - 2/9*b^2*c + 1/9*b*c^2 + 1/27*c^3 + 1/18*((3*c - 4)*b^2 +
(3*c^2 - 8*c)*b - c^2)*a + 1/18*sqrt(4*a^6*b - 32*a^2*b^5 - ((a^2 +
4)*b^2 - 2*(a^2 - 2*a)*b + a^2)*c^4 + (27*a^4 - 56*a^3 - 16*a^2)*b^4 +
2*(27*a^5 - 6*a^4 - 8*a^3)*b^3 - 2*((2*a^3 + a^2 + 10*a + 8)*b^3 -
(5*a^3 - 5*a^2 - 4*a)*b^2 - a^3 + 2*(a^3 - a^2)*b)*c^3 + (27*a^6 +
16*a^5 - 4*a^4)*b^2 - ((13*a^2 + 40*a + 16)*b^4 - 4*(4*a^3 - 5*a^2 +
4*a)*b^3 + a^4 - (17*a^4 - 8*a^3 + 24*a^2)*b^2 + 4*(a^4 - a^3)*b)*c^2
- 2*(16*a*b^5 - (9*a^3 - 32*a^2 + 16*a)*b^4 - 2*(9*a^4 - 23*a^3 +
4*a^2)*b^3 - (9*a^5 - 27*a^4 - 4*a^3)*b^2 + (3*a^5 +
2*a^4)*b)*c)*sqrt(3))^(1/3) - 1/2*(I*sqrt(3) + 1)*(1/54*(27*b + 2)*a^3
+ 1/18*((3*c + 2)*b + 9*b^2 - c)*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2 + 40*a +
16)*b^4 - 4*(4*a^3 - 5*a^2 + 4*a)*b^3 + a^4 - (17*a^4 - 8*a^3 +
24*a^2)*b^2 + 4*(a^4 - a^3)*b)*c^2 - 2*(16*a*b^5 - (9*a^3 - 32*a^2 +
16*a)*b^4 - 2*(9*a^4 - 23*a^3 + 4*a^2)*b^3 - (9*a^5 - 27*a^4 -
4*a^3)*b^2 + (3*a^5 + 2*a^4)*b)*c)*sqrt(3))^(1/3)]

and then do stuff like

sage: v = m_evals[0]

sage: v(a=1,b=-1.1, c=0)
-1/2*(I*sqrt(3) + 1)*((8.44590139893299e-18 +
0.137932037299462*I)*sqrt(3) + 0.0952962962962964)^(1/3) -
0.202222222222222*(-I*sqrt(3) + 1)/((8.44590139893299e-18 +
0.137932037299462*I)*sqrt(3) + 0.0952962962962964)^(1/3) -
0.0333333333333334

sage: _.n()
-0.193821989474223

Harald
```