Meneer-Beer
Meneer-Beer

Reputation: 113

Finding eigenvalues and eigenvectors in sympy returns empty brackets

I am trying to find the eigenvalues and eigenvectors of a 4x4 matrix R. For this I use the commands R.eigenvals() and R.eigenvects() from sympy, however, python returns empty brackets. I know the eigenvalues are 1 and e^(+-2ix). Am I doing something wrong?

import pprint    
from sympy import *    

R=Matrix([[(cos(x))**2, -cos(x)*sin(x), -cos(x)*sin(x), (sin(x))**2],[cos(x)*sin(x), (cos(x))**2, -(sin(x))**2, -cos(x)*sin(x)],      [cos(x)*sin(x), -(sin(x))**2, (cos(x))**2, -cos(x)*sin(x)],           [(sin(x))**2, sin(x)*cos(x), sin(x)*cos(x), (cos(x))**2]])    

pprint (R)    
pprint (R.eigenvals())    
pprint (R.eigenvects())

Upvotes: 1

Views: 1106

Answers (1)

Stelios
Stelios

Reputation: 5531

This seems to be a bug. As a workaround, one could try to find the eigenvalues "manually" by explicitly computing and solving the characteristic polynomial.

lam = sp.symbols('lambda')
cp = sp.det(R - lam * sp.eye(4))
eigs = sp.solveset(cp, lam)
eigs
{1, 
-sqrt(2)*sqrt(cos(4*x) - 1)/2 + cos(2*x),
sqrt(2)*sqrt(cos(4*x) - 1)/2 + cos(2*x)}

Note that the eigenvalues are provided in terms of real-valued trigonometric factors, since the latter are the factors of the characteristic polynomial. However, since cos(4*x)-1 cannnot be positive, the last two eigenvalues are in fact complex.

Motivated by this observation, one can attempt for a cleaner eigenvalue expression by re-writing the trigonometric factors of the characteristic polynomial as complex exponentials. Indeed,

eigs_v2 = sp.solveset(cp.rewrite(sp.exp).simplify(), lam)
eigs_v2

{1, exp(-2*I*x), exp(2*I*x)}

Upvotes: 2

Related Questions