I am trying to compute eigenvectors and eigenvalues for the below matrix. I am able to get results but all eigenvectors are positive
Example:
12.48 -1.88 -6.7
-1.88 26.7 4.32
-6.7 4.32 21.2
[1] Real Eigenvalue = 8.8362 =S3
[1] Real Eigenvector:
0.8753
-0.0247
0.4830
[2] Real Eigenvalue = 20.9867 =S2
[2] Real Eigenvector:
0.3873
0.6337
-0.6696
[3] Real Eigenvalue = 30.5570 =S1
[3] Real Eigenvector:
0.2895
-0.7731
-0.5643
Below is my methods and and output when I was testing.
/**
* Computes the Principal eigenvalues of a given matrix
*
* @param matrix matrix in which eigenvalues are computed
* @return Principal eigenvalues list in an ascending order
*/
public List<Double> getPrincipalEigenValues(DoubleMatrix matrix) {
List<Double> EigenValuesList = new ArrayList<Double>();// initialize a list to store eigenvalues
ComplexDoubleMatrix eigenvalues = Eigen.eigenvalues(matrix);// compute eigenvalues
for (ComplexDouble eigenvalue : eigenvalues.toArray()) {
Double eigenValue = Double.parseDouble(String.format("%.2f ", eigenvalue.abs()));
EigenValuesList.add(eigenValue);
}
return EigenValuesList;
}
/**
* Computes the Principal eigenvectors of a given matrix
*
* @param matrix matrix in which eigenvectors are computed
* @return Principal eigenvectors list in the same order as the eigenvalues
*/
public List<Double> getPrincipalEigenVectors(DoubleMatrix matrix) {
List<Double> list = new ArrayList<Double>();// initialize a list to store veigenvectors
ComplexDoubleMatrix eigenv = Eigen.eigenvectors(matrix)[0];// compute veigenvectors
for (ComplexDouble eigenvalue : eigenv.toArray()) {
Double eigenValue = Double.parseDouble(String.format("%.4f ", eigenvalue.abs()));
list.add(eigenValue);
}
return list;
}
Main method:
public static void main(String[] args) {
DoubleMatrix matrix = new DoubleMatrix(new double[][]{
{12.4800, -1.8800, -6.7000},
{-1.8800, 26.7000, 4.3200},
{-6.7000, 4.3200, 21.2000}}
);
StressResult compute =new StressResult();
System.out.println("Principal EigenValues"+compute.getPrincipalEigenValues(matrix));
// System.out.println("#");
// System.out.println("Principal EigenVectors"+compute.getPrincipalEigenVectors(matrix));
System.out.println("Principal EigenVectors"+compute.getPrincipalEigenVectors(matrix));
}
Output:
Principal EigenValues[8.84, 20.99, 30.56]
#
Principal EigenVectors[0.8753, 0.0247, 0.483, 0.3873, 0.6337, 0.6696, 0.2895, 0.7731, 0.5643]
May you please help me guys. I need to get the same results as indicated on the above example.