Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: order of eigenvalues
Date: Fri, 1 Feb 2008 19:59:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 44
Message-ID: <fnvtm6$nf1$1@fred.mathworks.com>
References: <fnv66a$cjt$1@fred.mathworks.com> <fnv7g2$h1o$1@fred.mathworks.com> <fnv8sh$puv$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1201895942 24033 172.30.248.37 (1 Feb 2008 19:59:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 1 Feb 2008 19:59:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:448838


"Willem Geert " <wgphaff@gmail.com> wrote in message <fnv8sh$puv
$1@fred.mathworks.com>...
> ...........
> Using the angle between the differenct is also an option, 
> but not based on the cosine; round-off error is too large.
> ...........
----------
  Willem, if you are worried about accuracy in determining when vectors are 
nearly parallel, there is a more accurate alternative as compared with finding 
their scalar product and comparing its absolute value to 1, though it requires 
more computation.  The scalar product is the product of the norms of the 
vectors multiplied by the cosine of the angle between them.  As you 
indicated, there is a loss of accuracy due to the infinite slope that is 
approached by the arccosine function as its argument approaches 1 or -1.  
Instead, we can directly compute the absolute value of the sine of the angle 
between vectors in the following manner.

  The absolute value of the sine of the angle between two real n-dimensional 
(n-element) column vectors v and w is given in matlab by

 norm(t(:))/sqrt(2)/norm(v)/norm(w)

where t is computed as

 t = v*w.'-w*v.';

Of course with unit-length eigenvectors, the division by norm(v) and norm(w) 
can be omitted.  Unfortunately, finding t and norm(t(:)) are order n^2 
computations.

  When this sine quantity is nearly zero, the vectors are nearly parallel, even if 
pointing in opposite directions.  It should also be noted that this same 
quantity approaches zero even when v and w are complex-valued and are 
nearly parallel in the complex sense that one is nearly a complex scalar 
multiple of the other, as can occur with eigenvectors of non-Hermitian 
matrices.

  Note: Just for the record, you can get the actual angle between the real 
vectors, lying in the range 0 to pi, using

 ang = atan2(norm(t(:))/sqrt(2),dot(v,w));

Roger Stafford