From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: angle between eigenvector and X-axis
Date: Thu, 19 Feb 2009 00:41:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 37
Message-ID: <gni9qt$r$>
References: <gmsqbh$gd2$> <gmsuq1$2f3$> <gmtjt1$pmj$> <gnhi7a$jdh$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1235004061 27 (19 Feb 2009 00:41:01 GMT)
NNTP-Posting-Date: Thu, 19 Feb 2009 00:41:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:519291

"Serena Frittoli" <> wrote in message <gnhi7a$jdh$>...
> Thanks to reply
> There is a problem ...
> If I find theta from V(1,1) using acos e from V(2,1) using asin ... I get two different values ...
> I  have another question:
> tha matrix V from comand  [U,S,V] = svd(M) ... what does this matrix mean?
> it is possible that sometime it is [cos -sin;sin cos] and other times it is [cos sin; sin -cos]...
> I'm very confuse!!!
> Thanks

  Let's tackle one problem at a time.  Suppose you have a vector v = [vx,vy] and you wish to know the angle between the positive x-axis and vector v.  Even that question has ambiguities to it.  One interpretation is that it is an angle which lies in the range from 0 to pi regardless of whether v lies counterclockwise or clockwise from the positive x-axis.  This would be the way angles within a triangle would be interpreted.  Another interpretation is that we must rotate strictly counterclockwise from the positive x-axis until first reaching v.  That would produce an angle somewhere between 0 and 2*pi.  Yet a third interpretation is to rotate either counterclockwise or clockwise from the x-axis by no more than pi radians with the counterclockwise direction considered positive and clockwise negative.  This angle would therefore lie between -pi and +pi.

  In matlab these three possible angle interpretations are best found by using 'atan2' in the following respective ways:

 1) angle = atan2(abs(vy),vx);
 2) angle = mod(atan2(vy,vx),2*pi);
 3) angle = atan2(vy,vx);

The method I gave you earlier is in accordance with the third interpretation here.  You will have to decide which kind of angle it is you are seeking.

  You can also use 'asin' or 'acos' to find these, but they suffer a loss of accuracy for certain values.  Also they require a more complicated procedure to produce the correct values in cases 2) and 3), since each function gives results which span no more than a pi width, whereas these cases require a span of 2*pi.

  As to applying this to your eigenvectors, you should be aware that each eigenvector from 'eig' is arbitrary as to its sign.  Either direction can occur and in terms of angles that makes a difference of pi in the angle value.  Also there is nothing in the documentation of 'eig' that specifies that the largest eigenvalue must come first, so there is some doubt about which eigenvector you are finding the angle for.  It makes a difference of pi/2 in the answer.

  Finally there is a large ambiguity which occurs in case both eigenvalues are equal.  In that event the eigenvectors are absolutely arbitrary as long as they are orthogonal and of unit length.  Any angle may occur depending on the vagaries of the programming in 'eig'.  This is no fault of matlab.  It is inherent in the very mathematical definition of eigenvectors.

  As to the 'svd' function, there is a definite relationship between the results given by it and those of 'eig' if you are using Hermitian matrices, as is indeed true in your case.  I refer you to the Wikipedia article at:

In particular read the section on "Relation to eigenvalue decomposition"

  I suspect that these uncertainties are not what you wanted to hear, but that is simply the way things are.  It just means you have to work harder at deciding precisely what it is you want to accomplish.

Roger Stafford