I want to find eigenvectors of a matrix in Sympy and wrote the following program but it doesn't work. On the other hand, the A.eigenvects() function in Sympy calculates the eigenvalues and eigenvects of the matrix A and I used a similar thing here but when I want to print the results, an empty list is shown. Would you please guide me?
from sympy import *
H=Matrix([ [215.0 ,-104.1 ,5.1 ,-4.3 ,4.7 ,-15.1 ,-7.8],
[-104.1 , 220.0 ,32.6 , 7.1 ,5.4 , 8.3 ,0.8],
[ 5.1 , 32.6 , 0. , -46.8 , 1.0 , -8.1 , 5.1 ],
[ -4.3 , 7.1 ,-46.8 ,125.0 ,-70.7 ,-14.7 ,-61.5],
[ 4.7 , 5.4 , 1.0 ,-70.7 ,450.0 ,89.7 ,-2.5],
[-15.1 , 8.3 ,-8.1 ,-14.7 ,89.7 ,330.0 ,32.7],
[-7.8 ,0.8 ,5.1 ,-61.5 ,-2.5 ,32.7 ,280.0]])
zz=H.eigenvects()
pprint(zz)
The problem stems from the use of Floats and Rationals. eigenvects
recasts Floats to Rationals. The eigenvals
routine fails when roots fails to factor the polynomial. When you call eigenvals
directly, the Floats are also recast but you can select not to recast them; when you do, roots
is able to return values and the eigen values are returned.
>>> H.eigenvals()
{}
>>> H.eigenvals(rational=False)
{513.317044781366: 1, 101.965215714556: 1, 332.004505895816: 1, 268.369453977695: 1, 120.955771704237: 1, -23.7383543150805: 1, 307.126362241411: 1}
It seems like roots
should be returning RootOf instances for this 7th order polynomial rather than returning no roots. It would be good to report this as an issue for SymPy:
roots(p) -> {} instead of RootOf instances when
p = 5000000*x**7 - 8100000000*x**6 + 5146847850000*x**5 - 1623625381660000*x**4 + 261251048199624000*x**3 - 18813344309673222800*x**2 + 248990094307079384205*x + 20562650438939697400552
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With