0

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)

Amro
  • 123,847
  • 25
  • 243
  • 454
lukyja
  • 1

3 Answers3

0

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/

smcg
  • 3,195
  • 2
  • 30
  • 40
  • ok, but here si problem of computing time,...so thios is why, I want to use only first k values tom compute.no all – lukyja May 31 '12 at 16:25
  • The library is returning a full array of all the eigenvalues. There is nothing you can do about that. You're going to have to iterate through the array somehow to get your smaller array, and then you can perform your calculations on the subarray. You only have to pass through the full array once to get the subarray, which is going to be fast. And please clean up your typos. – smcg May 31 '12 at 16:35
0

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

jkt
  • 2,538
  • 3
  • 26
  • 28
0

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.

wscourge
  • 10,657
  • 14
  • 59
  • 80
csliu_jia
  • 1
  • 1
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Rot-man Apr 01 '19 at 10:27