Skip to content

Instantly share code, notes, and snippets.

@davidalejandromiranda
Created December 20, 2019 14:41
Show Gist options
  • Select an option

  • Save davidalejandromiranda/f6d1e87abcb4b65e1ebf7439c83ef770 to your computer and use it in GitHub Desktop.

Select an option

Save davidalejandromiranda/f6d1e87abcb4b65e1ebf7439c83ef770 to your computer and use it in GitHub Desktop.
import numpy as np
def M_matrix_element(A,j):
M = np.delete(A, j, 0)
M = np.delete(M, j, 1)
return M
def M_matrix(A):
n = np.shape(A)[0]
return np.array([np.linalg.eig(M_matrix_element(A,j))[0] for j in range(n)]).T
def mho(a,i):
index = [k for k in range(len(a))]
index.remove(index[i])
return np.prod([a[i]-a[k] for k in index])
def mho_red(a, m, i, j):
index = range(len(a)-1)
return np.prod([a[i]-m[k,j] for k in index])
def eig_DPTZ(a, m):
n = len(a)
v = [[np.sqrt(mho_red(a,m,i,j)/mho(a,i)) for i in range(n)] for j in range(n)]
return np.array(v)
# Example of usage
a1 = 1; a2 = 2; a3 = 3
a4 = -1; a5 = 1; a6 = -1
A = [[a1,a4,a5],
[a4,a2,a6],
[a5,a6,a3]]
# Obtaining the eigenvalues
a,V = np.linalg.eig(A)
m = M_matrix(A)
# Calculating eigenvectors elements (without signs)
V2 = eig_DPTZ(a, m)
# Comparing the results
print('Eigenvectors', V)
print('DPTZ eigenvectors elements (magnitude)', V2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment