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:
eigenvectors sign problem

Subject: eigenvectors sign problem

From: roman

Date: 22 Apr, 2011 22:46:04

Message: 1 of 15

Hello,
I'm working on a stress field problem and i want to find the eigenvector of a real symmetric matrix. When using eig() i get signs switched randomly, that apparently is common problem using this function. I understand that even if the change is switched the physical meaning of the eigenvector is the same, but I'd need to get the right sign to plot some trajectories, and the function streamslice seems not to like very much when signs are switched. I read in other posts that you can solve this by multiplying a component of the eigenvector by a factor, but I actually did not understand how to put this in practice.
Any help would be appreciated,
Alberto

Subject: eigenvectors sign problem

From: John D'Errico

Date: 23 Apr, 2011 00:01:05

Message: 2 of 15

"roman" wrote in message <iot0fc$ii4$1@fred.mathworks.com>...
> Hello,
> I'm working on a stress field problem and i want to find the eigenvector of a real symmetric matrix. When using eig() i get signs switched randomly, that apparently is common problem using this function. I understand that even if the change is switched the physical meaning of the eigenvector is the same, but I'd need to get the right sign to plot some trajectories, and the function streamslice seems not to like very much when signs are switched. I read in other posts that you can solve this by multiplying a component of the eigenvector by a factor, but I actually did not understand how to put this in practice.
> Any help would be appreciated,
> Alberto

Multiplying an eigenvector by -1 does not change its
status as an eigenvector.

John

Subject: eigenvectors sign problem

From: Matt J

Date: 23 Apr, 2011 03:14:04

Message: 3 of 15

"roman" wrote in message <iot0fc$ii4$1@fred.mathworks.com>...
>
 I understand that even if the change is switched the physical meaning of the eigenvector is the same, but I'd need to get the right sign to plot some trajectories, and the function streamslice seems not to like very much when signs are switched.
=======================

If you define for us what it means for the sign to be "right", we may be able to help you design a test for when it is "wrong".

Subject: eigenvectors sign problem

From: Nasser M. Abbasi

Date: 23 Apr, 2011 03:59:22

Message: 4 of 15

On 4/22/2011 8:14 PM, Matt J wrote:
> "roman" wrote in message<iot0fc$ii4$1@fred.mathworks.com>...
>>
> I understand that even if the change is switched the physical
> meaning of the eigenvector is the same, but I'd need to get the
> right sign to plot some trajectories, and the function streamslice
> seems not to like very much when signs are switched.
> =======================
>
> If you define for us what it means for the sign to be "right",
> we may be able to help you design a test for when it is "wrong".

I just thought of a brilliant idea for the OP to get all the signs
to be the same for those eigenvector.

Here is the algorithm

---------------------

LOOP over all eigenvectors

      IF sign of eigenvector is negative THEN
         multiply it by -1
      END IF

END LOOP

---------------------

At the end of the above algorithm all the eigenvectors will
'point' one way.


--Nasser

Subject: eigenvectors sign problem

From: John D'Errico

Date: 23 Apr, 2011 09:28:04

Message: 5 of 15

"Nasser M. Abbasi" <nma@12000.org> wrote in message <iotiqs$3sc$1@speranza.aioe.org>...
> On 4/22/2011 8:14 PM, Matt J wrote:
> > "roman" wrote in message<iot0fc$ii4$1@fred.mathworks.com>...
> >>
> > I understand that even if the change is switched the physical
> > meaning of the eigenvector is the same, but I'd need to get the
> > right sign to plot some trajectories, and the function streamslice
> > seems not to like very much when signs are switched.
> > =======================
> >
> > If you define for us what it means for the sign to be "right",
> > we may be able to help you design a test for when it is "wrong".
>
> I just thought of a brilliant idea for the OP to get all the signs
> to be the same for those eigenvector.
>
> Here is the algorithm
>
> ---------------------
>
> LOOP over all eigenvectors
>
> IF sign of eigenvector is negative THEN
> multiply it by -1
> END IF

An eigenvector does not have a "sign", although you
CAN arbitrarily multiply an eigenvector by -1 (or any
other non-zero constant) and not change the fact that
it is a valid eigenvector with the same eigenvalue.

Had you suggested that the sign of the first element
of all of the eigenvectors was fixed to be positive, then
you MIGHT have had a valid argument.

Even there you have a problem. Very likely, some of
those eigenvectors might have that first element to be
so close to zero that subtle perturbations to the matrix
would cause that element of the eigenvector to change
sign.

So you might have argued to fix the first non-zero
element as positive, but then you must ensure that
the index of the first non-zero element does not change
with small perturbations to the array. Or, you might have
set the sign of the element with maximum absolute value,
but this too will fail with eigenvectors with two elements
that have nearly the same absolute value...

The point is, by choosing to multiply by -1 based on
the sign of ANY single value in the eigenvector, you will
always make mistakes.

I might point out my eigenshuffle, which DOES attempt
to solve this problem for a parameterized sequence of
eigen-problems.

John

Subject: eigenvectors sign problem

From: TideMan

Date: 23 Apr, 2011 10:50:44

Message: 6 of 15

On Apr 23, 10:46 am, "roman " <alberto_...@hotmail.com> wrote:
> Hello,
> I'm working on a stress field problem and i want to find the eigenvector of a real symmetric matrix. When using eig() i get signs switched randomly, that apparently is common problem using this function. I understand that even if the change is switched the physical meaning of the eigenvector is the same, but I'd need to get the right sign to plot some trajectories, and the function streamslice seems not to like very much when signs are switched. I read in other posts that you can solve this by multiplying a component of the eigenvector by a factor, but I actually did not understand how to put this in practice.
> Any help would be appreciated,
> Alberto

Your arrogance knows no bounds.
There are some of us who have been using Matlab and eig in particular
for more than a decade.
The sign of an eigenvector does not get "switched randomly", nor is it
a "common problem".
If only you knew more about the subject, you would realise that the
"sign" of an eigenvector is irrelevant.
You can scale it by whatever factor you like, it doesn't change its
shape which is what is important.

Subject: eigenvectors sign problem

From: Matt J

Date: 23 Apr, 2011 12:20:20

Message: 7 of 15

TideMan <mulgor@gmail.com> wrote in message <7ccaea30-ab65-4ead-9e23-4d464cda1584@n2g2000prj.googlegroups.com>...
>
> If only you knew more about the subject, you would realise that the
> "sign" of an eigenvector is irrelevant.
> You can scale it by whatever factor you like, it doesn't change its
> shape which is what is important.
======================

No, it is relevant to something task-specific for the OP. We just have to nail down what it is...

Subject: eigenvectors sign problem

From: roman

Date: 23 Apr, 2011 17:21:04

Message: 8 of 15

"Matt J" wrote in message <iotg5s$dg9$1@fred.mathworks.com>...
> "roman" wrote in message <iot0fc$ii4$1@fred.mathworks.com>...
> >
> I understand that even if the change is switched the physical meaning of the eigenvector is the same, but I'd need to get the right sign to plot some trajectories, and the function streamslice seems not to like very much when signs are switched.
> =======================
>
> If you define for us what it means for the sign to be "right", we may be able to help you design a test for when it is "wrong".





Well my eigenvectors define somewhat like a radial pattern in three dimension, and they do it, it is just that some signs are switched. I tried to perform this test:
if the scalar product the eigenvector with the closest is < 0 i multiply it by -1;
This performs quite good in 1 dimension but not in the three dimensions.
I understand that the eigenvector with the switched sign is the same, but as i said in the previous post, i need to plot the trajectories with streamslice() that doesn't work when there is no sign continuity.
Thanks for previous and future suggestions....

Subject: eigenvectors sign problem

From: Matt J

Date: 23 Apr, 2011 21:00:21

Message: 9 of 15

"roman" wrote in message <iov1q0$97a$1@fred.mathworks.com>...
>
> Well my eigenvectors define somewhat like a radial pattern in three dimension, and they do it, it is just that some signs are switched. I tried to perform this test:
> if the scalar product the eigenvector with the closest is < 0 i multiply it by -1;
> This performs quite good in 1 dimension but not in the three dimensions.
> I understand that the eigenvector with the switched sign is the same, but as i said in the previous post, i need to plot the trajectories with streamslice() that doesn't work when there is no sign continuity.
> Thanks for previous and future suggestions....
=========================

But what is the relationship supposed to be between the trajectory and the eigenvectors? Surely, the eigenvectors don't define the points on your trajectory. The eigenvectors are, after all, a discontinuous function of the matrix elements.

Subject: eigenvectors sign problem

From: roman

Date: 24 Apr, 2011 13:41:04

Message: 10 of 15

"Matt J" wrote in message <iovel5$j1j$1@fred.mathworks.com>...
> "roman" wrote in message <iov1q0$97a$1@fred.mathworks.com>...
> >
> > Well my eigenvectors define somewhat like a radial pattern in three dimension, and they do it, it is just that some signs are switched. I tried to perform this test:
> > if the scalar product the eigenvector with the closest is < 0 i multiply it by -1;
> > This performs quite good in 1 dimension but not in the three dimensions.
> > I understand that the eigenvector with the switched sign is the same, but as i said in the previous post, i need to plot the trajectories with streamslice() that doesn't work when there is no sign continuity.
> > Thanks for previous and future suggestions....
> =========================
>
> But what is the relationship supposed to be between the trajectory and the eigenvectors? Surely, the eigenvectors don't define the points on your trajectory. The eigenvectors are, after all, a discontinuous function of the matrix elements.



Well the problem is this: I've got a three dimensional grid (X, Y, Z). Each point has a 3*3 stress tensor that is not diagonal. I use the eig() function to diagonalize the tensor and to get the 3 vectors that form an orthogonal system over which the tensor is diagonal (the eigenvectors). I'd like to follow the path in the 3 dimensions (X,Y,Z) of the greatest principal stress (that is, the eigenvector associated with the greatest eigenvalue). To do this i plot the streamlines using as components the components of my eigenvector. I expect a radial pattern in the three dimensions, and I got it, the only thing is that sometimes, the signs are switched and streamslice produce quite ugly plots: a radial pattern with a lot of discontinuities (that occur exactly where the signs are switched). I thank John for pointing out his eigenshuffle(), but apparently eigenhuffle work for something like a
m*m*n (a matrix m*m over n points), and what I'd need is something that work with a m*m*n*o*p (a matrix m*m over a grid n*o*p (a grid in X, Y,Z)).
Cheers,
Alberto
PS Indeed, the eigenvectors are definetly the point of my trajectories....

Subject: eigenvectors sign problem

From: Roger Stafford

Date: 24 Apr, 2011 19:23:05

Message: 11 of 15

"roman" wrote in message <ip199g$mbd$1@fred.mathworks.com>...
> Well the problem is this: I've got a three dimensional grid (X, Y, Z). Each point has a 3*3 stress tensor that is not diagonal. I use the eig() function to diagonalize the tensor and to get the 3 vectors that form an orthogonal system over which the tensor is diagonal (the eigenvectors). I'd like to follow the path in the 3 dimensions (X,Y,Z) of the greatest principal stress (that is, the eigenvector associated with the greatest eigenvalue). To do this i plot the streamlines using as components the components of my eigenvector. I expect a radial pattern in the three dimensions, and I got it, the only thing is that sometimes, the signs are switched and streamslice produce quite ugly plots: a radial pattern with a lot of discontinuities (that occur exactly where the signs are switched). I thank John for pointing out his eigenshuffle(), but apparently eigenhuffle work for something like
a
> m*m*n (a matrix m*m over n points), and what I'd need is something that work with a m*m*n*o*p (a matrix m*m over a grid n*o*p (a grid in X, Y,Z)).
> Cheers,
> Alberto
> PS Indeed, the eigenvectors are definetly the point of my trajectories....
- - - - - - - -
  It stands to reason you would have trouble using 'streamslice' on a field of tensors. This function and all the other 'stream' functions were presumably designed for vector fields, not tensor fields. To adapt it to your purposes you would have to artificially force the principal eigenvector to have continuity of direction sense along its "stream" lines. In a three-dimensional grid even with closely-spaced points there could be difficulties in securing such a continuity, but it seems as though that is what you would have to do. Prepare the field of principal eigenvectors first, trying to make sure that adjacent grid points always have a less than 180-degree difference in the principal eigenvector direction - that is, that their pair-wise dot product always be positive - reversing the sign of one of the eigenvectors wherever necessary.

  Even that might not always be sufficient when faced with cases where you pass through points at which two eigenvalues cross through a state of equality where there would be an inherent ninety-degree discontinuity shift.

Roger Stafford

Subject: eigenvectors sign problem

From: Francisco Beron-Vera

Date: 29 Jun, 2011 02:47:09

Message: 12 of 15

"roman" wrote in message <iot0fc$ii4$1@fred.mathworks.com>...
> Hello,
> I'm working on a stress field problem and i want to find the eigenvector of a real symmetric matrix. When using eig() i get signs switched randomly, that apparently is common problem using this function. I understand that even if the change is switched the physical meaning of the eigenvector is the same, but I'd need to get the right sign to plot some trajectories, and the function streamslice seems not to like very much when signs are switched. I read in other posts that you can solve this by multiplying a component of the eigenvector by a factor, but I actually did not understand how to put this in practice.
> Any help would be appreciated,
> Alberto

Hi Alberto,

Did you find a solution for your problem?

Francisco

Subject: eigenvectors sign problem

From: Nasser M. Abbasi

Date: 29 Jun, 2011 03:02:00

Message: 13 of 15

On 6/28/2011 7:47 PM, Francisco Beron-Vera wrote:
> "roman" wrote in message<iot0fc$ii4$1@fred.mathworks.com>...
> but I'd need to get the right sign to plot some trajectories, and the function streamslice
> seems not to like very much when signs are switched.

>
> Hi Alberto,
>
> Did you find a solution for your problem?
>
> Francisco

Then, why not simply make the sign all , say, positive?

algrithm might be

LOOP over all eigenvectors n
      IF sign of n is negative
         n = -n
      END IF
END LOOP

Will this work for you?

--Nasser

Subject: eigenvectors sign problem

From: Joshua Dillon

Date: 9 Jul, 2011 16:08:09

Message: 14 of 15

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <iou634$fs1$1@fred.mathworks.com>...
> "Nasser M. Abbasi" <nma@12000.org> wrote in message <iotiqs$3sc$1@speranza.aioe.org>...
> > On 4/22/2011 8:14 PM, Matt J wrote:
> > > "roman" wrote in message<iot0fc$ii4$1@fred.mathworks.com>...
> > >>
> > > I understand that even if the change is switched the physical
> > > meaning of the eigenvector is the same, but I'd need to get the
> > > right sign to plot some trajectories, and the function streamslice
> > > seems not to like very much when signs are switched.
> > > =======================
> > >
> > > If you define for us what it means for the sign to be "right",
> > > we may be able to help you design a test for when it is "wrong".
> >
> > I just thought of a brilliant idea for the OP to get all the signs
> > to be the same for those eigenvector.
> >
> > Here is the algorithm
> >
> > ---------------------
> >
> > LOOP over all eigenvectors
> >
> > IF sign of eigenvector is negative THEN
> > multiply it by -1
> > END IF
>
> An eigenvector does not have a "sign", although you
> CAN arbitrarily multiply an eigenvector by -1 (or any
> other non-zero constant) and not change the fact that
> it is a valid eigenvector with the same eigenvalue.
>
> Had you suggested that the sign of the first element
> of all of the eigenvectors was fixed to be positive, then
> you MIGHT have had a valid argument.
>
> Even there you have a problem. Very likely, some of
> those eigenvectors might have that first element to be
> so close to zero that subtle perturbations to the matrix
> would cause that element of the eigenvector to change
> sign.
>
> So you might have argued to fix the first non-zero
> element as positive, but then you must ensure that
> the index of the first non-zero element does not change
> with small perturbations to the array. Or, you might have
> set the sign of the element with maximum absolute value,
> but this too will fail with eigenvectors with two elements
> that have nearly the same absolute value...
>
> The point is, by choosing to multiply by -1 based on
> the sign of ANY single value in the eigenvector, you will
> always make mistakes.
>
> I might point out my eigenshuffle, which DOES attempt
> to solve this problem for a parameterized sequence of
> eigen-problems.
>
> John

How about the following function?

Cheers,
Josh

function [V D]=myeig(X,varargin)
% Find eigen vector/value and enforce a sign convention by
% making the largest eigen vector element non-negative.
[V D]=eig(X,varargin{:});
[~,I] = max(abs(V),[],1);
I = sub2ind(size(V),I,1:size(V,2));
V = bsxfun(@times,V,sign(V(I)));
end % myeig

Subject: eigenvectors sign problem

From: Francisco Beron-Vera

Date: 11 Jul, 2011 00:38:09

Message: 15 of 15

"roman" wrote in message <iot0fc$ii4$1@fred.mathworks.com>...
> Hello,
> I'm working on a stress field problem and i want to find the eigenvector of a real symmetric matrix. When using eig() i get signs switched randomly, that apparently is common problem using this function. I understand that even if the change is switched the physical meaning of the eigenvector is the same, but I'd need to get the right sign to plot some trajectories, and the function streamslice seems not to like very much when signs are switched. I read in other posts that you can solve this by multiplying a component of the eigenvector by a factor, but I actually did not understand how to put this in practice.
> Any help would be appreciated,
> Alberto

Hi alberto,

Did you find a solution to your problem? That is, a tensor line integration code (ideally in Matlab)?

Francisco

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