Eigendecomposition determination error

I have a very simple question. This is due to a computational tolerance error.

Let me make (see the end) my own representation of matrix A in eigenvector V and diagonal eigenvalues โ€‹โ€‹of D and construct it again by multiplying V ^ -1 * D * V.

The obtained value is far from A, the error is quite large.

I would like to know if I am using the wrong functions to accomplish this task, or at least how to mitigate this error. Thank you in advance

in[1]:import numpy
      from scipy import linalg
      A=matrix([[16,-9,0],[-9,20,-11],[0,-11,11]])
      D,V=linalg.eig(A)
      D=diagflat(D)
      matrix(linalg.inv(V))*matrix(D)*matrix(V)


out[1]:matrix([[ 15.52275377,   9.37603361,   0.79257097],  
       [9.37603361,  21.12538282, -10.23535271],  
       [0.79257097, -10.23535271,  10.35186341]])

      

+3


source to share


1 answer


Isn't that so? A*V = V*D

from the definition, therefore A = V*D*V^(-1)

.

>>> import numpy as np
>>> from scipy import linalg
>>> A = np.matrix([[16,-9,0],[-9,20,-11],[0,-11,11]])
>>> D, V = linalg.eig(A)
>>> D = np.diagflat(D)
>>> 
>>> b = np.matrix(linalg.inv(V))*np.matrix(D)*np.matrix(V)
>>> b
matrix([[ 15.52275377+0.j,   9.37603361+0.j,   0.79257097+0.j],
        [  9.37603361+0.j,  21.12538282+0.j, -10.23535271+0.j],
        [  0.79257097+0.j, -10.23535271+0.j,  10.35186341+0.j]])
>>> np.allclose(A, b)
False

      

but

>>> f = np.matrix(V)*np.matrix(D)*np.matrix(linalg.inv(V))
>>> f
matrix([[  1.60000000e+01+0.j,  -9.00000000e+00+0.j,  -9.54791801e-15+0.j],
        [ -9.00000000e+00+0.j,   2.00000000e+01+0.j,  -1.10000000e+01+0.j],
        [ -1.55431223e-15+0.j,  -1.10000000e+01+0.j,   1.10000000e+01+0.j]])
>>> np.allclose(A, f)
True

      



Also, there are recipes to use np.dot

to avoid all these matrix conversions like

>>> dotm = lambda *args: reduce(np.dot, args)
>>> dotm(V, D, inv(V))
array([[  1.60000000e+01+0.j,  -9.00000000e+00+0.j,  -9.54791801e-15+0.j],
       [ -9.00000000e+00+0.j,   2.00000000e+01+0.j,  -1.10000000e+01+0.j],
       [ -1.55431223e-15+0.j,  -1.10000000e+01+0.j,   1.10000000e+01+0.j]])

      

which I often find cleaner, but YMMV.

+6


source







All Articles