participal Eigenvalues Java (JAMA)

472 Views Asked by At

I just ported my code from MATLAB to Java, and I need the eigen decomposition of a matrix, specifically I only need the first k values not the full decomposition.

However in JAMA, the eigen-decomposition class computes the full eigen decomposition. I tried to modify it, but it throws some errors. Is there another similar library?

In MATLAB, the function in question is eigs(k,A)

3

There are 3 best solutions below

0
On

In the case you cannot find any existing codes, I guess you should refer to this thesis or maybe this paper.

2
On

So it's just returning the array of all the eigenvalues. You want to return an array with just the first k values of the array. There are many ways to do this in Java. One is to convert the array to an ArrayList, get a subList of that list, and convert back to an array.

double[] mySubArray = new double[k];
for (int i=0; i < k; i++) {
        subArray[i] = myFullArray[i];
    }

By the way, this is the library he is referring to: http://math.nist.gov/javanumerics/jama/doc/

1
On

Maybe you can try another package named EigenDecomposition in http://commons.apache.org/proper/commons-math/javadocs/api-3.6/org/apache/commons/math3/linear/EigenDecomposition.html, there are some methods like getImagEigenvalue(int i), you can get the i-th eigenvalue by this.