I'm trying to calculate the eigenvalues and eigenvector of a matrix in Python. I used numpy and, as an example, did this with a matrix M
:
w,v=eig(M)
idx = w.argsort()[::1]
eigVal= w[idx]
eigVec = v[:,idx]
print(eigVal)
print("an eigen vector is:")
print(eigVec[0])
print()
nnn=M.dot(eigVec[0]) #matrix times supposed eigen vector
for i in range(lenght):
nnn[i]=nnn[i]/eigVal[0]
print("The result of M*vector/eigenvalue is:")
print(nnn)
And got as a result:
[452.78324098 461.88198554 468.47201706 474.43054819]
an eigen vector is:
[ 0.92852341 0.37084248 -0.01780576 0.00175573]
The result of M*vector/eigenvalue is:
[ 9.28755114e-01 3.72671398e-01 -2.29673727e-02 -9.27549232e-05]
As you can see, although similar, the resulting eigenvector after the multiplication is not that close to what numpy originally computed. How can the precision be improved?