Hi All,
I'm using the QR algorithm to break a matrix down into eigen vectors & eigen values. The code i'm using looks something like this:
QRAlgorithmResult QRAlgorithm(Matrix S) {
Matrix A = S; // Eigen values
Matrix Ev = Matrix(); // Eigen vectors
for (int i = 0; i < num_iteration; ++i) {
QRDecompResult QR = QRDecompose(A)
Ev = Ev * QR.Q
A = QR.R * QR.Q
}
Vector eigenvalues ( a[0], a[4], a[8] )
Vector[] eigenvectors = Vector[] {
Vector(Ev[0], Ev[1], Ev[2]),
Vector(Ev[3], EV[4], EV[5]),
Vector(Ev[6], Ev[7], Ev[8])
}
return QRAlgorithmResult(eigenvectors, eigenvalues)
}
Problem is, the most significant eigen values are always first! So, if i have a matrix where the eigen values represent scale, and the scale i'm looking for is (1, 15, 1); the resulting eigenvalues would be (15, 1, 1). The eigen vectors are in the same order. This is the matrix that results in the above error:
1.00000, 0.00000, 0.00000, 0.00000,
0.00000, 15.00000, 0.00000, 0.00000,
0.00000, 0.00000, 1.00000, 0.00000,
0.00000, 0.00000, 0.00000, 1.00000
So, my question is. How can i re-order the results, so that 15 is where i expect it to be? I've been trying to figure this out for a few days now, but i've got nothing :(