def real_eig(M,eps=1e-9):
'''
This code expects a real hermetian matrix
and should throw a ValueError if not.
This is probably redundant to the scipy eigh function.
Do not use.
'''
if not (type(M)==np.ndarray):
raise ValueError("Expected array; type is %s"%type(M))
if np.any(np.abs(np.imag(M))>eps):
raise ValueError("Matrix has imaginary values >%0.2e; will not extract real eigenvalues"%eps)
M = np.real(M)
w,v = np.linalg.eig(M)
if np.any(abs(np.imag(w))>eps):
raise ValueError('Eigenvalues with imaginary part >%0.2e; matrix has complex eigenvalues'%eps)
w = np.real(w)
order = np.argsort(w)
w = w[order]
v = v[:,order]
return w,v
评论列表
文章目录