#NEWLINE# @ defun #NEWLINE# def eighe( ctx , A , eigvals_only = False , overwrite_a = False ) : #NEWLINE# #INDENT# "\n    This routine solves the (ordinary) eigenvalue problem for a complex\n    hermitian square matrix A. Given A, an unitary matrix Q is calculated which\n    diagonalizes A:\n\n        Q' A Q = diag(E)               and                Q Q' = Q' Q = 1\n\n    Here diag(E) a is diagonal matrix whose diagonal is E.\n    ' denotes the hermitian transpose (i.e. ordinary transposition and\n    complex conjugation).\n\n    The columns of Q are the eigenvectors of A and E contains the eigenvalues:\n\n        A Q[:,i] = E[i] Q[:,i]\n\n\n    input:\n\n      A: complex matrix of format (n,n) which is hermitian\n         (i.e. A=A' or A[i,j]=conj(A[j,i]))\n\n      eigvals_only: if true, calculates only the eigenvalues E.\n                    if false, calculates both eigenvectors and eigenvalues.\n\n      overwrite_a: if true, allows modification of A which may improve\n                   performance. if false, A is not modified.\n\n    output:\n\n      E: vector of format (n). contains the eigenvalues of A in ascending order.\n\n      Q: unitary matrix of format (n,n). contains the eigenvectors\n         of A as columns.\n\n    return value:\n\n           E         if eigvals_only is true\n          (E, Q)     if eigvals_only is false\n\n    example:\n      >>> from mpmath import mp\n      >>> A = mp.matrix([[1, -3 - 1j], [-3 + 1j, -2]])\n      >>> E = mp.eighe(A, eigvals_only = True)\n      >>> print(E)\n      [-4.0]\n      [ 3.0]\n\n      >>> A = mp.matrix([[1, 2 + 5j], [2 - 5j, 3]])\n      >>> E, Q = mp.eighe(A)\n      >>> print(mp.chop(A * Q[:,0] - E[0] * Q[:,0]))\n      [0.0]\n      [0.0]\n\n    see also: eigsy, eigh, eig\n    " #NEWLINE# if ( not overwrite_a ) : #NEWLINE# #INDENT# A = A . copy ( ) #NEWLINE# #UNINDENT# d = ctx . zeros ( A . rows , 1 ) #NEWLINE# e = ctx . zeros ( A . rows , 1 ) #NEWLINE# t = ctx . zeros ( A . rows , 1 ) #NEWLINE# if eigvals_only : #NEWLINE# #INDENT# c_he_tridiag_0 ( ctx , A , d , e , t ) #NEWLINE# tridiag_eigen ( ctx , d , e , False ) #NEWLINE# return d #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# c_he_tridiag_0 ( ctx , A , d , e , t ) #NEWLINE# B = ctx . eye ( A . rows ) #NEWLINE# tridiag_eigen ( ctx , d , e , B ) #NEWLINE# c_he_tridiag_2 ( ctx , A , t , B ) #NEWLINE# return ( d , B )