Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endless loop on 4x4 matrix when calculating eigenvectors #14780

Open
k-eks opened this issue Jun 7, 2018 · 2 comments
Open

Endless loop on 4x4 matrix when calculating eigenvectors #14780

k-eks opened this issue Jun 7, 2018 · 2 comments

Comments

@k-eks
Copy link

k-eks commented Jun 7, 2018

When i tried to run the code below, it seemed to loop endlessly without a result even after 14 hours of computation. What I tried was to compute the eigenvectors of a 4x4 matrix. I have the same problem wether I run it on a jupyter notebook or in ipython.

I ran the

import numpy as np
import sympy as sp
a=np.array([11,12,21,22])
UA = np.array(sp.symbols('UA_{0} UA_{1} UA_{2} UA_{3}'.format(*a))).reshape(2,2)
UB = np.array(sp.symbols('UB_{0} UB_{1} UB_{2} UB_{3}'.format(*a))).reshape(2,2)
UAB = np.array(sp.symbols('UAB_{0} UAB_{1} UAB_{2} UAB_{3}'.format(*a))).reshape(2,2)
P = sp.Matrix(np.zeros([4,4]))
P[0:2,0:2] = UA
P[2:4,2:4] = UB
P[2:4,0:2] = UAB
P[0:2,2:4] = UAB.T
sp.Matrix(P).eigenvects()
#display(sp.Matrix(P).eigenvects()) # I ran it from within a jupyter notebook
´´´
@jksuom
Copy link
Member

jksuom commented Jun 7, 2018

Computing the eigenvalues takes less than 2 minutes on my system but the expressions are very complicated. The expression of a single eigenvalue has length 59310, much more than what the screen buffer can hold. This is a small piece of one eigenvalue:

UAB_21**2*UB_11/4 - UAB_21*UAB_22*UA_12/4 - UAB_21*UAB_22*UA_21/4 + UAB_22**2*UA_11/4 + UAB_22**2*UB_11/4 - UA_11*UA_22*UB_11/4 - UA_11*UA_22*UB_22/4 - UA_11*UB_11*UB_22/4 + UA_11*UB_12*UB_21/4 + UA_12*UA_21*UB_11/4 + UA_12*UA_21*UB_22/4 - UA_22*UB_11*UB_22/4 + UA_22*UB_12*UB_21/4 + (-UA_11 - UA_22 - UB_11 - UB_22)*(UAB_11**2/16 + UAB_12**2/16 + UAB_21**2/16 + UAB_22**2/16 - UA_11*UA_22/16 - UA_11*UB_11/16 - UA_11*UB_22/16 + UA_12*UA_21/16 - UA_22*UB_11/16 - UA_22*UB_22/16 - UB_11*UB_22/16 + UB_12*UB_21/16 + 3*(-UA_11 - UA_22 - UB_11 - UB_22)**2/256)) - (-UAB_11**2 - UAB_12**2 - UAB_21**2 - UAB_22**2 + UA_11*UA_22 + UA_11*UB_11 + UA_11*UB_22 - UA_12*UA_21 + UA_22*UB_11 + UA_22*UB_22 + UB_11*UB_22 - UB_12*UB_21 - 3*(-UA_11 - UA_22 - UB_11 - UB_22)**2/8)**2/12)**3/27) + (-UAB_11**2 - UAB_12**2

It seems that the memory of my system is not big enough for computing the eigenvectors, and the system slows down dramatically when it starts swapping memory to disk. The computation might succeed on a fast system with very large memory, but I suspect that the result would be too complicated to be really useful.

@k-eks
Copy link
Author

k-eks commented Jun 8, 2018

Aha! Thanks for the information! I have not expected such an increase in complexity as the eigenvector calculations took only moments for a 3x3 matrix. I have outsourced the code to our computational cluster where the code can have all the time it wants. If you are interested, I can tell you the computing time results once it's done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants