eigenvectors from eigenvalues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To calculate eigenvectors of a Hermitian matrix using nothing but the eigenvalues | |
# from https://arxiv.org/pdf/1908.03795.pdf | |
import numpy as np | |
# use numpy to calculate the eigen values | |
e_vals = np.linalg.eigvals(mat) | |
eigen_vectors = np.zeros_like(mat) | |
n, _ = mat.shape | |
for i in range(n): | |
for j in range(n): | |
lhs_product = 1 | |
for k in range(n): | |
if k != i: | |
lhs_product *= (e_vals[i] - e_vals[k]) | |
# remove the jth row and column from the matrix | |
Mj = np.delete(np.delete(mat, j, axis=0), j, axis=1) | |
e_vals_j = np.linalg.eigvals(Mj) | |
rhs_product = 1 | |
for k in range(n-1): | |
rhs_product *= (e_vals[i] - e_vals_j[k]) | |
eigen_vectors[i,j] = np.sqrt(rhs_product / lhs_product) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment