I'm using the apache.commons.math3 library to calculate eigenvectors of a 3x3 matrix, but the EigenDecomposition methods for calculating eigenvectors return wrong results: here's my code:
double[][] matrix = {
{1 ,3 ,2},
{1 ,4 ,3},
{2 ,1 ,0}
};
RealMatrix realMatrix = MatrixUtils.createRealMatrix(matrix);
EigenDecomposition decomposition = new EigenDecomposition(realMatrix);
for(int i = 0; i<3; i++){
RealVector eigenvector = decomposition.getEigenvector(i);
System.out.println(eigenvector.getEntry(0)+" "+eigenvector.getEntry(1)+" "+eigenvector.getEntry(2));
}
The printed results are:
-0.5760517243311052 -0.7536997812678066 -0.31638750072027233
0.22370947445236325 -0.6030287282098593 0.770086088626364
0.293925829450875 1.583437114738283 -2.642858652367182
while the correct ones should be
0.29050, -0.78307, 1
1.82072, 2.38220, 1
What is the problem? Is it a precision error? It seems to me impossible such a wrong result
If v is an eigenvector of a matrix, then a non-zero real multiple of v is also an eigenvector. The vector
(-0.5760517243311052 -0.7536997812678066 -0.31638750072027233)
is a multiple of
(1.82072, 2.38220, 1).
The difference is just that the first one has norm 1, whereas the second one has third component 1. Your library seems to choose the normalization by norm 1, which is better, since it is always possible.