# Eigenvalue Decomposition of Hermitian Matrix in Scala

I'm working on helping my friend create code to perform the Overlap Dirac Operator and have come across one part that I'm not sure what to do.

I need to compute the Eigenvalues and corresponding Eigenvectors for a hermitian matrix (my test is for n=4) so that I can implement a matrix sign function $epsilon(M) = U * epsilon(A) * U^*$ where $U$ is an eigenvector matrix, $U^*$ is the complex transpose of $U$, and $epsilon(A)$ is a matrix with the signs of eigenvalues of $M$ on it's diagonal.

Any resources or help on existing algorithms/libraries to solve this (or at least make close approximations) would be appreciated. My target programming language is Scala.

• Welcome to Computational Science Phillip. I've updated your question with the MathJax mark-up I think you intended, but could you check to make sure I haven't missinterpreted what you meant. – Mark Booth Jan 25 '13 at 0:52
• I think the description of $epsilon(A)$ as vector $lambda * I$ is not correct, since this would inevitably be vector $lambda$. Instead something like a diagonal matrix with those signed entries is probably meant. – hardmath Jan 25 '13 at 3:14
• I think that my description might've just been poor to begin with. I'm new to this material. What I mean is that $epsilon(M) = U*epsilon(A)*U^*$ where $epsilon(A)$ is a matrix with the signs of eigenvalues of $M$ on the diagonal. – Phillip Huff Jan 25 '13 at 3:51
• The subroutine you are looking for should work only for $n=4$ or also for $n>4$? – Stefano M Jan 25 '13 at 9:13
• Why aren't you just computing the eigenvalue decomposition and then set $\epsilon(A)=diag(sign\lambda_i)$ where $\lambda_i$ are the eigenvalues? – Deathbreath Jan 25 '13 at 14:15

Sorry I delayed so long to answer this question, but I wanted to answer this question in case someone else has a problem

I found a solution to this problem by using the jBLAS library (http://mikiobraun.github.io/jblas/)

To calculate the sign function $epsilon(M) = U * epsilon(A) * U^\dagger$, if you have an existing matrix matrixR in jBlas:

val eigenvecs = Eigen.eigenvectors(matrixR)
val lambda = new DoubleMatrix(4,4, math.signum(eigenvecs(1).get(0,0).real),0,0,0,
0,math.signum(eigenvecs(1).get(1,1).real),0,0,
0,0,math.signum(eigenvecs(1).get(2,2).real),0,
0,0,0,math.signum(eigenvecs(1).get(3,3).real)) //can be extended to larger matrices
val epsilon = eigenvecs(0).real.mmul(lambda).mmul(eigenvecs(0).real.transpose) //where epsilon = epsilon(M)