This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Problem with eigenvectors (libeigen 2)

Tags: None
(comma "," separated)
User avatar
b0wter
Registered Member
Posts
2
Karma
0
OS
I am currently trying to get something rather simple done but it does not work out.
The goal is convert a mathematica notebook into a small c++ tool. The notebook reads a matrix fiddles around with it and then computes the matrix's eigenvalues and eigenvectors.
Problem is that the eigenvectors in Mathematica and in my c++ program do not match.

After reading the matrix and doing some stuff with it it is the same in both tools:

Code: Select all
11 -4 -3 -4
-4 21 -8 -9
-3 -8 15 -4
-4 -9 -4 17


The eigenvalues are the same:
Code: Select all
Mathematica: 29.4833, 20., 14.5167, 0.
c++:         4.639e-15, 14.52, 20, 29.48


but the eigenvectors are not:

Mathematica
Code: Select all
0.0449944   -1.69666   0.651669   1.
-1.      1.      -5.      5.
-4.44499   1.29666      2.14833      1.
1.      1.      1.      1.

c++:
Code: Select all
0.5  0.8546 -0.1387 -0.02168
0.5 -0.2493  0.1387  0.8177
0.5 -0.413  -0.6934 -0.3141
0.5 -0.1923  0.6934 -0.4819


I do know that the c++ eigenvalues are normalised but it's not just a factor that differs.

The methods I used to compute the eigenvectors are:

Mathematica
Code: Select all
N[Eigenvalues[TMKomplett]]


C++
Code: Select all
Eigen::EigenSolver<MatrixXd> solver(matrix_);
cout << "Matrix eigenvectors: " << endl << solver.eigenvectors() << endl << endl;


So they are both very simple and I am probably just missing something stupid. Does anyone know what?

(Using libeigen 2.0.16-2 and g++ 4.4.6-11)
bgreene
Registered Member
Posts
11
Karma
0
It looks like the Mathematica eigenvectors are by rows and the
Eigen eigenvectors are by columns. If you transpose the eigenvector
matrix from Mathematica, reorder the columns so they are from low to
high eigenvalue (like Eigen), and then scale each column, you will
get the same eigenvector matrix as Eigen.

Bill
User avatar
b0wter
Registered Member
Posts
2
Karma
0
OS
Thanks a lot for the info, it really helped me out.
I thought about the difference between row and column vectors but then I didnt quite realise that the vectors are all scaled separately (stupid me) and I did not take negative factors into account.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]