[Numpy-discussion] linalg.eig getting the original matrix back ?

Sebastian Walter sebastian.walter at gmail.com
Fri Jan 15 11:32:04 EST 2010


numpy.linalg.eig guarantees to return right eigenvectors.
evec is not necessarily an orthonormal matrix when there are
eigenvalues with multiplicity >1.
For symmetrical matrices you'll have mutually orthogonal eigenspaces
but each eigenspace might be spanned by
vectors that are not orthogonal to each other.

Your omega has eigenvalue 1 with multiplicity 3.




On Fri, Jan 15, 2010 at 4:31 PM,  <josef.pktd at gmail.com> wrote:
> I had a problem because linal.eig doesn't rebuild the original matrix,
> linalg.eigh does, see script below
>
> Whats the trick with linalg.eig to get the original (or the inverse)
> back ? None of my variations on the formulas worked.
>
> Thanks,
> Josef
>
>
> import numpy as np
> import scipy as sp
> import scipy.linalg
>
> omega =  np.array([[ 6.,  2.,  2.,  0.,  0.,  3.,  0.,  0.],
>                   [ 2.,  6.,  2.,  3.,  0.,  0.,  3.,  0.],
>                   [ 2.,  2.,  6.,  0.,  3.,  0.,  0.,  3.],
>                   [ 0.,  3.,  0.,  6.,  2.,  0.,  3.,  0.],
>                   [ 0.,  0.,  3.,  2.,  6.,  0.,  0.,  3.],
>                   [ 3.,  0.,  0.,  0.,  0.,  6.,  2.,  2.],
>                   [ 0.,  3.,  0.,  3.,  0.,  2.,  6.,  2.],
>                   [ 0.,  0.,  3.,  0.,  3.,  2.,  2.,  6.]])
>
> for fun in [np.linalg.eig, np.linalg.eigh, sp.linalg.eig, sp.linalg.eigh]:
>    print fun.__module__, fun
>    ev, evec = fun(omega)
>    omegainv = np.dot(evec, (1/ev * evec).T)
>    omegainv2 = np.linalg.inv(omega)
>    omegacomp = np.dot(evec, (ev * evec).T)
>    print 'composition',
>    print np.max(np.abs(omegacomp - omega))
>    print 'inverse',
>    print np.max(np.abs(omegainv - omegainv2))
>
> this prints:
>
> numpy.linalg.linalg <function eig at 0x017EDDF0>
> composition 0.405241032278
> inverse 0.405241032278
>
> numpy.linalg.linalg <function eigh at 0x017EDE30>
> composition 3.5527136788e-015
> inverse 7.21644966006e-016
>
> scipy.linalg.decomp <function eig at 0x01DB14F0>
> composition 0.238386662463
> inverse 0.238386662463
>
> scipy.linalg.decomp <function eigh at 0x01DB1530>
> composition 3.99680288865e-015
> inverse 4.99600361081e-016
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list