Sort eigenvalues and eigenvectors
This commit is contained in:
parent
162e884d47
commit
5eb23c1985
@ -6,7 +6,9 @@
|
|||||||
* @bug The eigenvalues fail the test. When comparing them to arma::eigsym
|
* @bug The eigenvalues fail the test. When comparing them to arma::eigsym
|
||||||
* there is one value that is way off when testing with a 6x6 matrix.
|
* there is one value that is way off when testing with a 6x6 matrix.
|
||||||
*/
|
*/
|
||||||
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
#include "jacobi.hpp"
|
#include "jacobi.hpp"
|
||||||
@ -75,9 +77,16 @@ void jacobi_eigensolver(const arma::mat& A,
|
|||||||
|
|
||||||
} while (max_offdiag >= eps && ++iterations < maxiter);
|
} while (max_offdiag >= eps && ++iterations < maxiter);
|
||||||
|
|
||||||
|
|
||||||
|
arma::vec res = arma::diagvec(A_m);
|
||||||
|
arma::uvec sorted_indeces = arma::sort_index(res);
|
||||||
|
eigenvalues.resize(res.n_elem);
|
||||||
|
eigenvectors.resize(res.n_elem, res.n_elem);
|
||||||
// The diagonal elements of A_m are the eigenvalues
|
// The diagonal elements of A_m are the eigenvalues
|
||||||
eigenvalues = arma::diagvec(A_m);
|
for (int i=0; i < res.n_elem; i++) {
|
||||||
eigenvectors = R;
|
eigenvalues[i] = res[sorted_indeces[i]];
|
||||||
|
eigenvectors.insert_cols(i, R.col(sorted_indeces[i]));
|
||||||
|
}
|
||||||
|
|
||||||
converged = max_offdiag < eps;
|
converged = max_offdiag < eps;
|
||||||
A_m.print();
|
A_m.print();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user