Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: eigenvectors sign problem Date: Sat, 9 Jul 2011 16:08:09 +0000 (UTC) Organization: Georgia Institute of Technology Lines: 73 Message-ID: <iv9ud9$qid$1@newscl01ah.mathworks.com> References: <iot0fc$ii4$1@fred.mathworks.com> <iotg5s$dg9$1@fred.mathworks.com> <iotiqs$3sc$1@speranza.aioe.org> <iou634$fs1$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-01-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1310227689 27213 172.30.248.46 (9 Jul 2011 16:08:09 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sat, 9 Jul 2011 16:08:09 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2002642 Xref: news.mathworks.com comp.soft-sys.matlab:735674 "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