0

I'm implementing the system described within this paper, and I'm getting a little stuck. I only recently encountered tensors/eigenvalues etc so excuse me if this is a little simple!

Given a 2x2 tensor, how can I calculate the major and minor eigenvectors of it?

Bonus points for implementations which are easy to translate into C# ;)

Martin
  • 12,469
  • 13
  • 64
  • 128

1 Answers1

2

(I'm using MATLAB matrix notation; semicolons mean "new row".)

[u;v] is an eigenvector of [a b; c d] with eigenvalue t if [a b; c d] [u;v] = t[u;v]. That means that au+bv=tu and cu+bv=tv; that is, (a-t)u+bv=0 and cu+(d-t)v=0. If this has any nontrivial solutions, it's because those two equations are the same apart from a constant factor; then your eigenvector is [u;v] = [b;t-a]. (Unique only up to a constant factor, of course.)

The eigenvalues are the values of t for which this is possible; that is, for which those two equations are the same apart from a constant factor. That happens iff the matrix [a-t b; c d-t] is singular, which means its determinant is zero, which means (a-t)(d-t)-bc=0, which means t^2 - (a+d)t + (ad-bc) = 0.

So: Solve that equation for the eigenvalues, and then get the eigenvectors the way I described above.

The eigenvalues may be complex (e.g., for a rotation). In that case you'll get complex eigenvectors too, which is correct because you can't have Av=kv with A,v real but k not real.

Two warnings.

  1. Some matrices have two equal eigenvalues. They may or may not have two independent eigenvectors. If the matrix is a constant multiple of the identity matrix -- of the form [k 0; 0 k] -- then it does have two independent eigenvectors, and in fact any two independent vectors will do, because everything is an eigenvector. Otherwise, there is only one eigenvector and any theorems or algorithms that rely on having two are liable to fail. This will happen, e.g., with "shear" matrices of the form [1 k; 0 1].

  2. In dimensions higher than 2, you don't want to do things this way. There are much better (but more complicated) ways of computing eigenvectors and eigenvalues, and the ways in which you can fail to have the "right" number of independent eigenvectors are more extensive.

Gareth McCaughan
  • 19,888
  • 1
  • 41
  • 62
  • Out of the two eigenvalues, which one is the major and which one is the minor? – Martin Mar 17 '11 at 16:05
  • 1
    Looking at the paper, I think they've actually restricted consideration to one particular form of 2x2 matrix -- those of the form R[cos(2t) sin(2t); sin(2t) -cos(2t)] -- and they've kindly told you what the eigenvectors are and labelled them "major" and "minor". (So, actually, you don't need any of the stuff I described above!) Their matrices are all scaled reflections; one eigenvector is parallel to the line of reflection, one perpendicular. Their "major eigenvector" is the one with eigenvalue +R instead of -R; along the reflection line. – Gareth McCaughan Mar 17 '11 at 16:21
  • 1
    In general, I think "major eigenvector" means "eigenvector corresponding to the eigenvalue of largest absolute value"; in this paper's case the eigenvalues have the same absolute value and the "major" one is the positive one. The term "principal" is more common than "major". – Gareth McCaughan Mar 17 '11 at 16:25
  • Oops, they hid the fact they were giving me the vectors behind a wall of maths I didn't understand! – Martin Mar 17 '11 at 16:33
  • I don't think they do limit themselves to purely those types of matrices. Check out where they define the radial basis field. That has a completely different form. – Martin Mar 17 '11 at 17:19
  • I'm not sure it really does. They give the matrix [yy-xx -2xy; -2xy xx-yy]. Well, take y = cos t, x = - sin t; then yy-xx = cos^2 t - sin^2 t = cos 2t and -2xy = 2 cos t sin t = sin 2t. – Gareth McCaughan Mar 17 '11 at 17:24
  • Er, obviously that's not quite right because xx+yy mightn't be 1. So take r = sqrt(xx+yy), y = r cos t, x = - r sin t; then yy-xx = R cos 2t and -2xy = R sin 2t where R = r^2. – Gareth McCaughan Mar 17 '11 at 17:26
  • so is it correct to use Tensor = { R = xx+yy, Theta = 0.5*acos((yy-xx)/(xx+yy)) }? – Martin Mar 17 '11 at 20:58
  • I think so, but I make a lot of mistakes so you should check that that does give the right matrix :-). Er, you would probably do better to use theta = atan2(-x,y). (Or maybe y,-x or something; I forget exactly how C# defines atan2.) – Gareth McCaughan Mar 17 '11 at 22:30
  • Well, I tried implementing this, and it doesn't work in the top left and bottom right quadrants. I'll have a go with atan2 and see what happens. – Martin Mar 17 '11 at 22:41