Numpy 提供的特征向量错误。

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

Numpy giving wrong Eigenvectors

问题

from numpy.linalg import eig
import numpy as np

A = np.array([[1, 2], [3, 4]])
eval, evec = eig(A)

print("特征向量:", evec)

输出结果:

特征向量: [[-0.82456484 -0.41597356]
          [ 0.56576746 -0.90937671]]

在Mathematica中:

A = {{1, 2}, {3, 4}};
{eval, evec} = Eigensystem[A];
N[evec]

输出结果:

{{0.457427, 1.}, {-1.45743, 1.}}

我知道Mathematica的结果是正确的,因为它可以正确计算出使用特征向量计算的波函数的图形。

这不仅仅是归一化的问题,因为不能通过缩放因子来获得正确的numpy结果。

有一个使用SymPy的解决方法,但问题是什么,有没有办法在numpy中获得正确的特征向量?

英文:
from numpy.linalg import eig
import numpy as np

A = np.array([[1,2],[3,4]])
eval, evec = eig(A)

print("Eigenvectors:", evec)

gives:

Eigenvectors: [[-0.82456484 -0.41597356]
               [ 0.56576746 -0.90937671]]

while in mathematica:

A = {{1, 2}, {3, 4}};
{eval, evec} = Eigensystem[A];
N[evec]

gives:

{{0.457427, 1.}, {-1.45743, 1.}}

And I know the mathematica one is correct because it gives the correct graph of the wavefuntion calculated using eigenvectors.

And this is not just a matter of normalization because the numpy result cannot be scaled by a factor to get the correct result.

There is a workaround using sympy,but What is the problem and is there a way to get correct eigen vectors in numpy itself?

Update:
Both eigen vectors were correct. And the graph of the wavefunction was incorrect only because of another factor (I didn't transpose the matrix)

答案1

得分: 1

Both computations are correct. Numpy gives normalized eigenvectors of length 1. Divide each column of the numpy eigenvector matrix by the second number in the column to get the vectors computed by Mathematica.

import numpy as np

A = np.array([[1,2],[3,4]])
vals, vects = np.linalg.eig(A)

print(vects)

它输出:

[[-0.82456484 -0.41597356]
 [ 0.56576746 -0.90937671]]

除以最后一行:

print(vects/vects[-1])

结果:

[[-1.45742711  0.45742711]
 [ 1.          1.        ]]
英文:

Both computations are correct. Numpy gives normalized eigenvectors of length 1. Divide each column of the numpy eigenvector matrix by the second number in the column to get the vectors computed by Mathematica.

import numpy as np

A = np.array([[1,2],[3,4]])
vals, vects = np.linalg.eig(A)

print(vects)

It gives:

[[-0.82456484 -0.41597356]
 [ 0.56576746 -0.90937671]]

Divide by the last row:

print(vects/vects[-1])

Result:

[[-1.45742711  0.45742711]
 [ 1.          1.        ]]

huangapple
  • 本文由 发表于 2023年2月26日 19:46:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75571754.html
匿名

发表评论

匿名网友

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

确定