Reputation: 43
I wanted to find the Eigen value of a matrix size (280*280). I done it in MATLAB by using
[V D] = eig(matrix);
but I wanted to convert my code in python by using
d, v = np.eigh(matrix)
It will provide almost same output but in python the first and the last column are of opposite sign (i.e if positive in MATLAB then negative in python) and I know that MATLAB output is correct
Upvotes: 1
Views: 198
Reputation: 2699
What you are doing is equivalent only if your matrix is hermitian.
you should use in python:
d, v = np.eig(matrix)
A simple test you can do to make sure that what you compute is ok is to check that your eigenvalues and eigenvectors are correct by using :
d, v = np.linalg.eig(matrix)
norm_1=np.max(np.max(abs(np.matmul(np.matmul(v,np.diag(d)),np.linalg.inv(v))-matrix)))
print norm_1
the result of np.max(np.sum(abs(np.matmul(np.matmul(v,np.diag(d)),np.linalg.inv(v))-matrix)))
is a simple case of a Matrix norms induced by vector norms.
If your computation is ok the result should be around machine rounding error.
Upvotes: 1