Custom vector does not work in sympy

I want to find my own matrix vectors in Sympy and wrote the following program, but it does not work. Sympy's A.eigenvects () function, on the other hand, computes the eigenvalues ​​and eigenvalues ​​of matrix A, and I used something similar here, but when I want to print the results, an empty list is displayed. Could you 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) 
+5
source share
3 answers
  >>> 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]]) >>> x = H.charpoly(symbols('lamda')) >>> factor(x) 1.0*(1.0*lamda**7 - 1620.0*lamda**6 + 1029369.57*lamda**5 - 324725076.332*lamda**4 + 52250209639.9248*lamda**3 - 3762668861934.64*lamda**2 + 49798018861415.7*lamda + 4.112530087788e+15) 

the last equation has 7 real roots => (lamda +23.738) *(lamda -101.965) *(lamda -120.956) *(lamda -268.369) *(lamda -307.126) *(lamda -332.005) *(lamda -513.317) = 0

[-23.738, 101.965, 120.956, 268.369, 307.126, 332.005, 513.317]

and it's really weird why sympy keeps saying that this matrix has no eigenvector.

+2
source

The problem is with using Floats and Rationals. eigenvects changes Floats to Rationals. The eigenvals subroutine fails when the roots do not affect the polynomial. When you call eigenvals directly, the floats are also recycled, but you can choose not to redo them; when you do this, roots can return values ​​and return eigenvalues.

 >>> 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 that roots should return instances of RootOf for this 7th order polynomial, and not return any roots. It would be nice to report this as a problem 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

+7
source

It seems like this might be a mistake for me, for some reason you don't like your matrix. An attempt to use eigenvals() also simply returns nothing, however, using the Berkovits algorithm gives the expected result (they are correct):

 >>> H.berkowitz_eigenvals() {βˆ’23.7383543150805:1,101.965215714556:1,120.955771704237:1, 268.369453977695:1,307.126362241411:1,332.004505895816:1,513.317044781366:1} 

As an alternative, finding the roots of a polynomial of characters gives the same result:

 >>> roots(H.charpoly(x),x) {βˆ’23.7383543150805:1,101.965215714556:1,120.955771704237:1, 268.369453977695:1,307.126362241411:1,332.004505895816:1,513.317044781366:1} 

As for the workaround, I have no ideas at this time besides using another library, possibly NumPy / SciPy:

 >>> from numpy import linalg as LA >>> w,v = LA.eig(np.array([ [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]]) >>> w;v array([[ 0.0211232 , -0.0863685 , 0.31060486, 0.64800412, 0.58825511, 0.34578278, -0.1004976 ], [-0.03360278, -0.17141713, 0.28577077, 0.60531169, -0.57444552, -0.41080118, 0.15058085], [-0.01492258, 0.91780802, -0.23783515, 0.29790711, -0.04561479, -0.00789624, 0.09974215], [ 0.19183148, 0.33999268, 0.79845203, -0.30609739, 0.01552874, -0.18077 , -0.2889039 ], [-0.86037599, 0.04835763, 0.171535 , -0.10783263, 0.27161704, -0.27390267, 0.25993089], [-0.45801107, 0.01859027, -0.05846719, 0.07732967, -0.35064091, 0.32022588, -0.74497537], [-0.1066849 , 0.05006013, 0.30810033, -0.11677503, -0.35344244, 0.70807431, 0.50125772]]) 
+2
source

All Articles