2

Given a square matrix A, I need to obtain a diagonal matrix D that contains A's 5 largest magnitude eigenvalues and a matrix V whose columns are the corresponding eigenvectors. In Matlab the code is [V,D] = eigs(A,5). Is there a similar function in ArrayFire C++?

In ArrayFire I use af::eigen(Values,Vectors,A). What is the order of elements in Values? In one test I had the elements of Values sorted in the order of increasing magnitude, however in the other case Values was sorted in the order of decreasing magnitude. Essentially, I need to extract 5 eigenvectors that correspond to the largest magnitude eigenvalues. Do I have to use the sort function to achieve this?

UPDATE Here's a simple example:

// first example
float a[]={1, 2, 5, -2, 1, -5, 3, -2, 1};
array b(3,3,a);
array evalues, evectors;
af::eigen(evalues, evectors, b);
print(evalues);     //`evalues` are not in order   

// second example
float a2[]={1, -3, 3, 3, -5, 3, 6, -6, 4};
array b2(3,3,a2);
array evalues2, evectors2;
af::eigen(evalues2, evectors2, b2);
print(evalues2);     //`evalues2` are in the decreasing order
4

0 回答 0