Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
angle between eigenvector and X-axis

Subject: angle between eigenvector and X-axis

From: Serena Frittoli

Date: 10 Feb, 2009 21:08:01

Message: 1 of 6

Hi all,
I have to solve this problem:

I have a matrix M (101x2)
I find a matrix S=M'*M
I calculate the eigenvectors from the square matrix S (2x2) using
[V,D]=eig(S)
V(2x2)

The problem is:
 ... each row of M is rotated by the angle formed between the eigenvector and the X-axis so that the points lie around the X-axis ...

I think to calculate the rotated matrix (T) in this way
T=V*M';
I use M' because M is (101x2)
Is it correct?

How could I know the value of the angle?
Anyone can Help me?

Thanks
Serena

Subject: angle between eigenvector and X-axis

From: Roger Stafford

Date: 10 Feb, 2009 22:24:02

Message: 2 of 6

"Serena Frittoli" <xere4@hotmail.com> wrote in message <gmsqbh$gd2$1@fred.mathworks.com>...
> Hi all,
> I have to solve this problem:
>
> I have a matrix M (101x2)
> I find a matrix S=M'*M
> I calculate the eigenvectors from the square matrix S (2x2) using
> [V,D]=eig(S)
> V(2x2)
>
> The problem is:
> ... each row of M is rotated by the angle formed between the eigenvector and the X-axis so that the points lie around the X-axis ...
>
> I think to calculate the rotated matrix (T) in this way
> T=V*M';
> I use M' because M is (101x2)
> Is it correct?
>
> How could I know the value of the angle?
> Anyone can Help me?
>
> Thanks
> Serena

  I am uncertain about your meaning here. In the solution to the eigenvector problem you have

 S*V = V*D,

or

 D = V'*S*V = V'*M'*M*V = (M*V)'*(M*V)

This means that the unitary 2 x 2 matrix, V, transforms the coordinates of M in the transformation

 T = M*V

so that in the new coordinate system the sum of the squares of the coordinates along one column of T are maximized and along the other column they are minimized, namely to the corresponding two eigenvalues. However V may not be a valid rotation. Its determinant may be -1 instead of +1, in which case you would need to reverse the signs of one of the columns (eigenvectors) of V.

  As for determining the angle of rotation, the first column of V will be [cos(theta);sin(theta)] of the rotation by theta, so you can find theta with

 theta = atan2(V(1,1),V(2,1));

  Note that if both eigenvectors are reversed in sign, V remains a rotation but the angle changes by pi (180 degrees.) Therefore theta's values are only unique over a range of pi, say from -pi/2 to +pi/2 or from 0 to pi. That uncertainly is inherent in the problem.

  Does this come anywhere near to answering your question, Serena?

Roger Stafford

Subject: angle between eigenvector and X-axis

From: Roger Stafford

Date: 11 Feb, 2009 04:24:01

Message: 3 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gmsuq1$2f3$1@fred.mathworks.com>...
> .......
> theta = atan2(V(1,1),V(2,1));
> ......

  My apologies, I mistakenly got that formula for finding theta reversed. It should have been this:

 theta = atan2(V(2,1),V(1,1));

  Also I should point out that this is the rotation angle if the points in M are regarded as having been rotated counterclockwise to new positions through the angle theta. If you consider that the points remain fixed and it is a counterclockwise rotation of the coordinate system through the angle theta, then it would be

 theta = atan2(V(1,2),V(1,1));

Roger Stafford

Subject: angle between eigenvector and X-axis

From: Serena Frittoli

Date: 18 Feb, 2009 17:58:02

Message: 4 of 6

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

Subject: angle between eigenvector and X-axis

From: Roger Stafford

Date: 19 Feb, 2009 00:41:01

Message: 5 of 6

"Serena Frittoli" <xere4@hotmail.com> wrote in message <gnhi7a$jdh$1@fred.mathworks.com>...
> 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:

 http://en.wikipedia.org/wiki/Singular_value_decomposition

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

Subject: angle between eigenvector and X-axis

From: NZTideMan

Date: 19 Feb, 2009 01:20:31

Message: 6 of 6

On Feb 19, 1:41=A0pm, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> "Serena Frittoli" <xe...@hotmail.com> wrote in message <gnhi7a$jd...@fred=
.mathworks.com>...
> > 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 g=
et two different values ...
>
> > I =A0have another question:
> > tha matrix V from comand =A0[U,S,V] =3D svd(M) ... what does this matri=
x mean?
> > it is possible that sometime it is [cos -sin;sin cos] and other times i=
t is [cos sin; sin -cos]...
>
> > I'm very confuse!!!
> > Thanks
>
> =A0 Let's tackle one problem at a time. =A0Suppose you have a vector v =
=3D [vx,vy] and you wish to know the angle between the positive x-axis and =
vector v. =A0Even that question has ambiguities to it. =A0One interpretatio=
n 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. =A0=
This would be the way angles within a triangle would be interpreted. =A0Ano=
ther interpretation is that we must rotate strictly counterclockwise from t=
he positive x-axis until first reaching v. =A0That would produce an angle s=
omewhere between 0 and 2*pi. =A0Yet a third interpretation is to rotate eit=
her counterclockwise or clockwise from the x-axis by no more than pi radian=
s with the counterclockwise direction considered positive and clockwise neg=
ative. =A0This angle would therefore lie between -pi and +pi.
>
> =A0 In matlab these three possible angle interpretations are best found b=
y using 'atan2' in the following respective ways:
>
> =A01) angle =3D atan2(abs(vy),vx);
> =A02) angle =3D mod(atan2(vy,vx),2*pi);
> =A03) angle =3D atan2(vy,vx);
>
> The method I gave you earlier is in accordance with the third interpretat=
ion here. =A0You will have to decide which kind of angle it is you are seek=
ing.
>
> =A0 You can also use 'asin' or 'acos' to find these, but they suffer a lo=
ss of accuracy for certain values. =A0Also they require a more complicated =
procedure to produce the correct values in cases 2) and 3), since each func=
tion gives results which span no more than a pi width, whereas these cases =
require a span of 2*pi.
>
> =A0 As to applying this to your eigenvectors, you should be aware that ea=
ch eigenvector from 'eig' is arbitrary as to its sign. =A0Either direction =
can occur and in terms of angles that makes a difference of pi in the angle=
 value. =A0Also there is nothing in the documentation of 'eig' that specifi=
es that the largest eigenvalue must come first, so there is some doubt abou=
t which eigenvector you are finding the angle for. =A0It makes a difference=
 of pi/2 in the answer.
>
> =A0 Finally there is a large ambiguity which occurs in case both eigenval=
ues are equal. =A0In that event the eigenvectors are absolutely arbitrary a=
s long as they are orthogonal and of unit length. =A0Any angle may occur de=
pending on the vagaries of the programming in 'eig'. =A0This is no fault of=
 matlab. =A0It is inherent in the very mathematical definition of eigenvect=
ors.
>
> =A0 As to the 'svd' function, there is a definite relationship between th=
e results given by it and those of 'eig' if you are using Hermitian matrice=
s, as is indeed true in your case. =A0I refer you to the Wikipedia article =
at:
>
> =A0http://en.wikipedia.org/wiki/Singular_value_decomposition
>
> In particular read the section on "Relation to eigenvalue decomposition"
>
> =A0 I suspect that these uncertainties are not what you wanted to hear, b=
ut that is simply the way things are. =A0It just means you have to work har=
der at deciding precisely what it is you want to accomplish.
>
> Roger Stafford

And there's another option:
4. angle=3Dmod(atan2(ux,vy)*180/pi,360);
to give bearing (i.e., degrees clockwise from True North)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us