[SciPy-user] Fwd: Problems with scipy.linalg
Michael McNeil Forbes
mforbes at physics.ubc.ca
Mon Mar 24 11:16:48 EDT 2008
Hi Abo,
On 24 Mar 2008, at 2:21 AM, chengbo duan wrote:
> Hi ,Guys
> I was frustrated with the function "eig" .The matrix looks like
> this:
>
> [ 0 ,1 ,exp(1.0j*k) ]
> [ 1 , 0 , 1 ]
> [ exp(-1.0j*k) , 1 , 0 ]
...
> You will find that there is a discontinuty around pi/2.
A couple of comments:
1) If your matrix is Hermitian, you should use eigh rather than eig.
It is much more stable (and returns sorted eigenvalues so you won't
have the same discontinuities).
2) eig() makes no claim about the order of the returned eigenvalues,
so there is no "bug" here. If you need the eigenvalues in a
particular order, then just sort the results (d.sort()) before use.
Then the only discontinuities will be where there are degenerate
eigenvalues.
3) While it would be very nice to have numerical routines return
eigenvalues in such an order that they are "continuous", there is no
way for the algorithm to know how to do this since it only has the
matrix to work with. (You could easily construct simple examples
where the eigenvalues "switch" continuously so that at one point, eig
would have to return the eigenvalues in one order, while at another
it would have to switch the order even though the matrix is the same.)
Michael.
More information about the SciPy-User
mailing list