I have a complex 2D array (HH) of which I want to do the inverse and I only want its first term, iterated in 3 for loop, . For M, C, K (2D arrays) of reasonable size it doesn't take long, but if I increase their size the wait becomes infinite. One loop inside the third loop to calculate HH[0,0] takes around 0.19 sec, imagine to iterate 2x20x500 times it takes a bunch of time. How can I speed up the process?
Since I can't upload M, C and K I replace them with this: inv((np.random.rand(1000,1000)+np.random.rand(1000,1000)*1j)
import numpy as np
import numpy.linalg.inv as inv
num_harms = 2 # or 3
num_modes = 20
freq = np.linspace(1.0,4.0,500) #range force freq
w = 2*np.pi*freq
H11_1 = np.zeros((num_harms,num_modes,len(w)),dtype = 'complex_') # dim(num_harms,num_modes,step_freq)
for h in range(0,num_harms):
for j in range(0,num_modes):
for iw in range(0,len(w)):
# HH = inv((-((h+1)*w[iw])**2)*M[j]+(1j*(h+1)*w[iw]*C[j])+K[j])
HH = inv((np.random.rand(1000,1000)+np.random.rand(1000,1000)*1j)
H11_1[h,j,iw] = HH[0,0]
I also tried this to make it little faster:
H11_1 = np.zeros((num_harms,num_modes,len(w)),dtype = 'complex_') # dim(num_harms,num_modes,step_freq)
for h in range(0,num_harms):
for j in range(0,num_modes):
for iw in range(0,len(w)):
H = ((-((h+1)*w[iw])**2)*M[j]+(1j*(h+1)*w[iw]*C[j])+K[j])
H_1 = (np.linalg.det(A))
H11_1[h,j,iw] = H_1
But it appears this warning:
RuntimeWarning: overflow encountered in det
r = _umath_linalg.det(a, signature=signature)
I debug it to see H_1 value and it is: (-inf-infj)