## Eigenvalues of a 3 by 3 symmetric matrix

Anyway, my trouble comes from finding the eigenvalues of a 3 by 3 symmetric matrix - I'm wondering if there is a good (read: fast) way to do it numerically and if so, what that is. Google hasn't been exactly helpful on this, nor have my books on linear algebra. So, any ideas?

I admit, thats an ugly problem. I looks like the fact that it's symmetric doesnt helps much... you still have a third degree polinomial to solve [I guess you know that]. You are lucky that at least one eigenvalue is real, the other ones may be both real or both complex. Its not hard to find the real one [you use the usual algorithm to solve an equation, i.e. you find a value of lamda for which the polinomial is positive and another one for which it,s negative, so you know that by continuity there must be a solution between the two values, then you keep iterating], but I guess its much harder to find the complex roots.

Â©hâ‚¬ck Ã¸ut Âµy stuÆ’Æ’ Ã¥t ragdollsoft.com

New game in development Rubber Ninjas - Mac Games Downloads

by using interval bisection (a.k.a. interval halving) you guarantee a logarithmic time complexity. in other words, quite efficient.

when you've found one root, divide the polynomial by that root to yield a 2nd degree polynomial. once you've got that there's a simple formula to calculate the two solutions (i assume you know it). just make sure to check the sign of the value within the square root you want to write a special case for when the two roots are complex.

Code:

`function [lambda, v] = powermethod(v0, A, n)`

% Power iteration

% POWERMETHOD(v0, A, n) returns lambda and v which converge towards

% the largest eigenvalue and associated eigenvector of A as n gets big.

% The function iterates through n steps of the algorithm.

v = v0/norm(v0);

for k = 1:n

w = A*v;

v = w/norm(w);

lambda = v'*A*v;

end

Or you could look at Chapter 11 of Numerical Recipes.

EDIT: I just remembered this -- the vecLib framework includes functions from CLAPACK, which means that it can do just about any matrix-related operation that you could possibly want. The only hard part is making sure that you pass in the arguments in the right way, but for a symmetric matrix, this probably won't even be an issue. A quick google suggests that the LAPACK function you want is called ssyevd / dsyevd.

I was just kind of hoping there was something faster than using the formula for third order polynomials... Guess not though, oh well.

If it is symmetric, all three roots are real. Still, the third-grade polynomial is tough to solve.

I believe its a good way to go too.

Â©hâ‚¬ck Ã¸ut Âµy stuÆ’Æ’ Ã¥t ragdollsoft.com

New game in development Rubber Ninjas - Mac Games Downloads

Yeah, not as fast as I'd like, but it's what I'll have to do. Thanks for the help.

btw... what do you need that for?

Â©hâ‚¬ck Ã¸ut Âµy stuÆ’Æ’ Ã¥t ragdollsoft.com

New game in development Rubber Ninjas - Mac Games Downloads

wow ... i thought nobody would ever use eigenvalues in games... yet you proved me wrong...

Â©hâ‚¬ck Ã¸ut Âµy stuÆ’Æ’ Ã¥t ragdollsoft.com

New game in development Rubber Ninjas - Mac Games Downloads

hmm, or maybe not. the mathematical formula for calculating the tensor looks slightly too complicated (may be the reason it is not described in detail in my book). is there any easy algorithm to do the job (based on a mesh)?

Doing things based off of meshes = lots of nasty numerical integration with weird limits but I'm sure some modeling packages can do it. Usually you are better off to pick numbers which is pretty simple if you just stick to the diagonal of the matrix and 0's elsewhere and then rotate that (getting the nasty thing you see).