I'm calculating the eigenvalues of a matrix with the .eigenvals() function. When I do so for my matrix, a new variable that I never declared occurs in the solution and I don't know where it comes from, nor do I expect it to happen, but it definitly influences the solution. I have the problem with numpy and sympy. Here is my code for sympy:
from sympy import *
D,Bm,Bp,Bz,l=symbols('D Bm Bp Bz l')
H=Matrix(([D+Bz,Bm,0],[Bp,0,Bm],[0,Bp,D-Bz]))
ev=H.eigenvals()
sol=ev.keys()
print sol[0]
print
print sol[1]
print
print sol[2]
The solutions look like this, with this strange 'I' in there. When I want to use the calculated eigenvalues, I have to define, what 'I' is, otherwise it won't solve my formulas.
2*D/3 + (-2*Bm*Bp/3 - Bz**2/3 - D**2/9)/(Bm*Bp*D - 8*D**3/27 + D*(-2*Bm*Bp - Bz**2 + D**2)/3 + sqrt((-2*Bm*Bp/3 - Bz**2/3 - D**2/9)**3 + (2*Bm*Bp*D - 16*D**3/27 + 2*D*(-2*Bm*Bp - Bz**2 + D**2)/3)**2/4))**(1/3) - (Bm*Bp*D - 8*D**3/27 + D*(-2*Bm*Bp - Bz**2 + D**2)/3 + sqrt((-2*Bm*Bp/3 - Bz**2/3 - D**2/9)**3 + (2*Bm*Bp*D - 16*D**3/27 + 2*D*(-2*Bm*Bp - Bz**2 + D**2)/3)**2/4))**(1/3)
2*D/3 + (-2*Bm*Bp/3 - Bz**2/3 - D**2/9)/((-1/2 - sqrt(3)*I/2)*(Bm*Bp*D - 8*D**3/27 + D*(-2*Bm*Bp - Bz**2 + D**2)/3 + sqrt((-2*Bm*Bp/3 - Bz**2/3 - D**2/9)**3 + (2*Bm*Bp*D - 16*D**3/27 + 2*D*(-2*Bm*Bp - Bz**2 + D**2)/3)**2/4))**(1/3)) - (-1/2 - sqrt(3)*I/2)*(Bm*Bp*D - 8*D**3/27 + D*(-2*Bm*Bp - Bz**2 + D**2)/3 + sqrt((-2*Bm*Bp/3 - Bz**2/3 - D**2/9)**3 + (2*Bm*Bp*D - 16*D**3/27 + 2*D*(-2*Bm*Bp - Bz**2 + D**2)/3)**2/4))**(1/3)
2*D/3 + (-2*Bm*Bp/3 - Bz**2/3 - D**2/9)/((-1/2 + sqrt(3)*I/2)*(Bm*Bp*D - 8*D**3/27 + D*(-2*Bm*Bp - Bz**2 + D**2)/3 + sqrt((-2*Bm*Bp/3 - Bz**2/3 - D**2/9)**3 + (2*Bm*Bp*D - 16*D**3/27 + 2*D*(-2*Bm*Bp - Bz**2 + D**2)/3)**2/4))**(1/3)) - (-1/2 + sqrt(3)*I/2)*(Bm*Bp*D - 8*D**3/27 + D*(-2*Bm*Bp - Bz**2 + D**2)/3 + sqrt((-2*Bm*Bp/3 - Bz**2/3 - D**2/9)**3 + (2*Bm*Bp*D - 16*D**3/27 + 2*D*(-2*Bm*Bp - Bz**2 + D**2)/3)**2/4))**(1/3)
I can also do it numerically with the result, that all my symbols are numbers then, but the 'I' stays in the solution at the same point.
Has anyone ever seen this before or knows, what python is doing here or what this 'I' stands for? It would be a great help to know, what is happening there, since the calculated eigenvalues do not fully behave, as I expected and I give the blame to that terms including that 'I'. Thanks for any comments in advance.
I
is the imaginary unit sqrt(-1)
.
>>> from sympy import I
>>> complex(I)
1j
For example,
>>> from sympy import poly
>>> from sympy.abc import x
>>> p = poly(x**2 + 1)
>>> p.root(0)
-I
>>> p.root(1)
I