如何获得特征值和特征向量问题的更多有效数字?

huangapple go评论89阅读模式
英文:

How can I get more significant figures for the eigenvalues and eigenvectors problem?

问题

我尝试在Python中计算矩阵的特征值和特征向量。我使用了numpy,并且以矩阵M为例进行了以下操作:

  1. w, v = eig(M)
  2. idx = w.argsort()[::1]
  3. eigVal = w[idx]
  4. eigVec = v[:, idx]
  5. print(eigVal)
  6. print("特征向量是:")
  7. print(eigVec[0])
  8. print()
  9. nnn = M.dot(eigVec[0]) # 矩阵乘以假定的特征向量
  10. for i in range(lenght):
  11. nnn[i] = nnn[i] / eigVal[0]
  12. print("M*向量/特征值的结果是:")
  13. print(nnn)

得到的结果如下:

  1. [452.78324098 461.88198554 468.47201706 474.43054819]
  2. 特征向量是:
  3. [ 0.92852341 0.37084248 -0.01780576 0.00175573]
  4. M*向量/特征值的结果是:
  5. [ 9.28755114e-01 3.72671398e-01 -2.29673727e-02 -9.27549232e-05]

如您所见,尽管相似,但乘法后得到的特征向量与numpy最初计算的特征向量并不非常接近。如何提高精度呢?

英文:

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:

  1. w,v=eig(M)
  2. idx = w.argsort()[::1]
  3. eigVal= w[idx]
  4. eigVec = v[:,idx]
  5. print(eigVal)
  6. print("an eigen vector is:")
  7. print(eigVec[0])
  8. print()
  9. nnn=M.dot(eigVec[0]) #matrix times supposed eigen vector
  10. for i in range(lenght):
  11. nnn[i]=nnn[i]/eigVal[0]
  12. print("The result of M*vector/eigenvalue is:")
  13. print(nnn)

And got as a result:

  1. [452.78324098 461.88198554 468.47201706 474.43054819]
  2. an eigen vector is:
  3. [ 0.92852341 0.37084248 -0.01780576 0.00175573]
  4. The result of M*vector/eigenvalue is:
  5. [ 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?

答案1

得分: 1

你需要沿着正确的轴取特征向量;

  1. w, v = eig(M)
  2. idx = w.argsort()[::1]
  3. eigVal = w[idx]
  4. eigVec = np.transpose(v[:, idx]) # <-- transpose here
  5. print(eigVal)
  6. print("特征向量是:")
  7. print(eigVec[0])
  8. print()
  9. nnn = M.dot(eigVec[0]) #矩阵乘以假定的特征向量
  10. nnn /= eigVal[0]
  11. print("M*向量/特征值的结果是:")
  12. print(nnn)
英文:

You need to take the eigenvectors along the right axis;

  1. w,v=eig(M)
  2. idx = w.argsort()[::1]
  3. eigVal= w[idx]
  4. eigVec = np.transpose(v[:,idx]) # <-- transpose here
  5. print(eigVal)
  6. print("an eigen vector is:")
  7. print(eigVec[0])
  8. print()
  9. nnn=M.dot(eigVec[0]) #matrix times supposed eigen vector
  10. nnn /= eigVal[0]
  11. print("The result of M*vector/eigenvalue is:")
  12. print(nnn)

huangapple
  • 本文由 发表于 2023年2月10日 07:07:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75405393.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定