Eigen

Input: n by n complex hermitian matrix given as a two dimensional array.
Output: n real eigenvalues stored in a one dimensional sorted array,
    n by n matrix of n corresponding eigenvectors stored as columns in a two dimensional array.

Eigen(A) = Eigenvectors of square matrix A by SVD:

Va, Ve = Eigen(A) // Va = eigen values Ve = eigenvectors of A by SVD
{
   P = CharPoly(A) // P = Characteristic polynomial of square matrix A
   R = PolRoots(P) // R = All of the roots of polynomial P, these are the eigenvalues
   f = 1
   for (i = A.n - 1; i >= 1; i--) // Delete roots that are duplicates
      if (r[i] == r[i + 1)
         Delete root i from r
   for (i = 1; i <= r.m; i++)
   {
      U = A
      for (j = 1; j <= A.n; j++)  // Subtract i-th root from
         u[j, j] = u[j, j] - r[i] // all diagonal elements of U
      (U, W, V) = SVD(U)          // Decompose U to (U, W, V)
      for (j = A.n; j >= 1; j--)  // Delete columns of V for W = 0
      {
         if (w[j] != 0)
            Delete column j from matrix V
      }
      for (ci = 1; ci <= V.n; ci++)// Concat Columns of V to Ve
      {
         for (ri = 1; ri <= A.n; ri++)
         {
            Ve[ri, f] = v[ri, ci]
         }
         f++
      }
   }
   for (ci = 1; ci <= A.n; ci++)  // For all columns of Ve
   {
      di = 0
      for (ri = n; ri >= 1; ri--) // Find last non-zero element
         if (Ve[ri, ci] != 0)     // in this column
         {
            di = Ve[ri, ci]
            break
         }
      if (di == MultiCD.cZero)      // if column is all zeros
      {
         Delete column ci from matrix Ve
      }
      else
      {
         for (ri = 1; ri <= A.n; ri++)   // Make last non-zero element
            Ve[ri, ci] = Ve[ri, ci] / di // equal to one
      }
   }
} // Eigen

