Eigenvectors of 3x3 symmetric matrix
A C++ source and header file to compute eigenvectors/values of a 3x3 symmetric matrix. Potentially easier than installing EISPACK, LAPACK, or Gandalf if you only need this single function. Takes about 6000 clock cycles per call on my Pentium 4. Public domain. [1]

20 Comments:
Hi Connelly,
Thanks for the eigensystem code. I need to find the magnitude and direction of the principle axes of a covariance matrix and plot the resulting ellipsoid. This should save me a bunch of time.
Cheers,
Pete
No problem. I used this code to plot level sets of quadric error functions when implementing Garland and Heckbert's mesh simplification paper [1], so like you, I was plotting ellipsoids.
Hi Connelly,
I found an error in the code. When I was testing the next matrix:
0 -0.00018 0.01718
0.00016 5e-05 0.01373
-0.01474 -0.0225 0.43942
The results are:
evalues:
-0.00146067 -0.000130409 0.441061
evectors:
0.520977 0.852918 -0.0333759
0.851398 -0.522042 -0.0509365
0.0608683 0.00187936 0.998144
This results are different in MATLAB. Is it normal?
This should work only for 3x3 *symmetric* matrix. The next matrix doesn't seem to be symmetric to me.
Thanks for the code.
I need to find only an eigenvector corresponding to the smallest eigenvalue. Is there something faster for that?
For more speed, if you need the eigenvector for the eigenvalue of smallest or largest absolute value, you can try power iteration [1] or inverse power iteration [2]. You might be able to get two eigenvectors by using both power iteration and inverse iteration. The third can be obtained by a cross product. Once you have one eigenvector you can also try reducing the dimension of the problem by one (by projecting on to vectors orthogonal to the found eigenvector) and then solving again by any method of your choice. Once you get to two dimensions there is a nice closed form formula for the eigenvectors based on the quadratic formula.
It would be interesting to see how few clock cycles are needed for solving the 3x3 and 4x4 problems for the symmetric and non-symmetric cases. Maybe there's already code out there which solves these problems quickly; does any one know where it is?
For generality, you can change the constant N given in the code to solve for whichever dimension you need. Changing N to a variable might slow down the optimizer; I didn't check. If solving for a non-symmetric matrix, you can steal the code needed from the public domain package JAMA [3].
One might also try solving the characteristic polynomial for eigenvalues and then using linear algebra to solve for the associated eigenvectors. Using one of the aforementioned techniques for the 3x3 case, one could probably speed up the code by an order of magnitude.
Hi, thanks for the code. It worked fine for me.
Thanks you for your code. I will use it (until write my own) to calculate OBBs (object oriented boxes), that are used in computer graphics for interference detection.
I am having a lot of trouble finding the eigen vectors of a non symmetric matrix..Is their any way you would know how to go about it
Thanks!
just what I was looking for.
Cheers,
DK
Seems to have slightly different output than with MATLAB.
For example for input=
1.0000 0.9794 0.6967
0.9794 1.0000 0.7742
0.6967 0.7742 1.0000
in MATLAB I get:
Eigenvectors =
-0.5890 -0.6535 -0.4754
-0.6049 0.7466 -0.2769
-0.5359 -0.1245 0.8351
Eigenvalues =
2.6397
0.0137
0.3466
While with your code I get:
Eigenvectors =
-0.65348666890016993 -0.47540875028028978 0.58901756656885285
0.74663228601038611 -0.27687590315051447 0.60488012344719444
-0.12448053284214880 0.83506062918300739 0.53589023365966881
Eigenvalues=
0.013661896296036690
0.34664732510150514
2.6396907786024602
As you can see, the signs on the right column eigenvector are different to the first column at MATLAB (which are the same eigenvector)...
I suppose there is a bug?
DK
DK - No bug. If A * v = lambda * v, then A * (-v) = lambda * (-v) also, so if v is an eigenvector then -v is also, and eigenvectors aren't uniquely defined up to sign.
Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.
Oes Tsetnoc | Semangat Mengembalikan Jati Diri Bangsa
Hi Connelly,
Thanks for the code. It works fine for 3X3 symmetric matrix. Although, I was just curious to know which algorithm they have applied to calculate the eigenvalues and especially for eigenvectors.
I was trying to implement Row Reduced Echelon form method to calculate the eigenvector, but unfortunately it didn't work as I would have expected.
Thanks again.
Thank you very much for your code
I tried this code for 3X3 symmetric matrix, and I had a couple of problems and I hope that somebody could help me work this out, thanks in advance!
i download this i will need it
Kauf und Verkauf von Gold in den thomas sabo Goldmarkt hat viel an Popularität gewonnen, sind thomas sabo shop Gold-Nuggets und Goldmünzen im Handel erhältlich herkömmlichen thomas sabo jewellery Wege der Kauf und Verkauf bei niedrigen wenn thomas sabo schmuck high.Tips Gold und Silver.Have eine thomassabo online shop klare Vorstellung davon, warum die Schmuck thomas sabo onlineshop verkaufen muss, um verkauft werden und Scout für die sabo schmuck entsprechende buyer.Volume aus Gold oder thomas sabo shop online Silber zu einem Zeitpunkt verkauft werden bestimmen den Verkaufspreis und die Verhandlungsmacht thomas sabo charm club der seller.Purity bestimmt auch den Endpreis der verkauften Artikel.
I've been reading the blog and I love the way like you redact the information, specially when you attached Generic Viagra on the blogroll. 23jj
Post a Comment
<< Home