clwainwright / CosmoTransitions

A package for analyzing finite or zero-temperature cosmological phase transitions driven by single or multiple scalar fields.
MIT License
25 stars 19 forks source link

A problem on diagonalization of mass matrix automatically #26

Open phase-tr opened 4 years ago

phase-tr commented 4 years ago

Dear All,

I tried to use np.linalg.eig(m) to diagonalize a 3\times 3 mass matrix depending on fields, and got an error: "numpy.linalg.linalg.LinAlgError: Last 2 dimensions of the array must be square".

It seems to that the shape of 'X' change the mass matrix, and the mass matrix is no longer 3\times 3 How to solve the problem?

Many thanks

clwainwright commented 4 years ago

It's bit hard to tell what the problem would be without a fuller description. Could you provide code that will reproduce the error?

phase-tr commented 4 years ago

Dear Carroll, Thank your for your reply. In the testModel.py, I add the third field.
The main modifications include self.Ndim = 3 def boson_massSq(self, X, T):
X = np.array(X) phi1,phi2,phi3 = X[...,0], X[...,1], X[...,2] m11 = self.l1(3phi1phi1 - v2) m22 = self.l2(3phi2phi2 - v2) m33 = 0.5phi3phi3 m12= self.l1phi1phi2 m13 = self.l1phi1phi3 m23 =self.l2phi2phi3 mm=np.array([[m11,m12,m13],[m12,m22,m23],[m13,m23,m33]]) print("matrix:", mm) valm, vecm= np.linalg.eig(mm) print("eiganvalue:", valm) print("---------") M = np.array([valm[0], valm[1], valm[2]]) M = np.rollaxis(M, 0, len(M.shape)) dof = np.array([1, 1, 1]) c = np.array([1.5, 1.5, 1.5]) return M, dof, c def approxZeroTMin(self): v = v2**.5 return [np.array([v,v,0]), np.array([v,-v,0])]

The output:

matrix: [[ 15907.29585374 9072.69610265 17228.41322886] [ 9072.69610265 4316.00547642 3523.15126973] [ 17228.41322886 3523.15126973 161946.06943183]] eiganvalue: [ 164080.8897684 18922.33933215 -833.85833856]

Tracing phase starting at x = [ 254.44037152 299.71222224 569.13343481] ; t = 0.0 Tracing minimum up traceMinimum t0 = 0 matrix: [[[ 15907.2759916 15907.45762553 15907.63926018 15907.82089554 15908.00253162] [ 9072.96725197 9073.00291077 9073.03856957 9073.07422837 9073.10988717] [ 17228.95708893 17229.02480261 17229.09251628 17229.16022996 17229.22794363]]

[[ 9072.96725197 9073.00291077 9073.03856957 9073.07422837 9073.10988717] [ 4316.34296063 4316.34296063 4316.34296063 4316.34296063 4316.34296063] [ 3523.37081309 3523.37081309 3523.37081309 3523.37081309 3523.37081309]]

[[ 17228.95708893 17229.02480261 17229.09251628 17229.16022996 17229.22794363] [ 3523.37081309 3523.37081309 3523.37081309 3523.37081309 3523.37081309] [ 161956.43331001 161956.43331001 161956.43331001 161956.43331001 161956.43331001]]]

The reported error: raise LinAlgError('Last 2 dimensions of the array must be square') numpy.linalg.linalg.LinAlgError: Last 2 dimensions of the array must be square

phase-tr commented 4 years ago

testModel.py.gz

mamerchandmedi commented 3 years ago

were you able to solve this issue? I am having a similar complicatioon with a many scalar field model.

subhojitphy commented 3 years ago

Dear All,

I used np.linalg.eig(array_name) for the diagonalization of a (3x3) field-dependent mass matrix and encountered the following error: "LinAlgError: Last 2 dimensions of the array must be square", which is similar to the above mentioned issue.

How did you solve this problem? what did you use to get the eigenvalues?

Many thanks in advance.

subhojitphy commented 3 years ago

Solved.