问题描述
我测试了一个定理,即A = Q * Lambda * Q_inverse,其中Q是具有特征向量的矩阵,而Lambda是具有对角特征值的对角矩阵.
I test the theorem that A = Q * Lambda * Q_inverse where Q the Matrix with the Eigenvectors and Lambda the Diagonal matrix having the Eigenvalues in the Diagonal.
我的代码如下:
import numpy as np
from numpy import linalg as lg
Eigenvalues, Eigenvectors = lg.eigh(np.array([
[1, 3],
[2, 5]
]))
Lambda = np.diag(Eigenvalues)
Eigenvectors @ Lambda @ lg.inv(Eigenvectors)
哪个返回:
array([[ 1., 2.],
[ 2., 5.]])
返回的矩阵不应该与被分解的原始矩阵相同吗?
Shouldn't the returned Matrix be the same as the Original one that was decomposed?
推荐答案
您正在使用linalg.eigh函数,该函数用于对称/Hermitian矩阵,您的矩阵不是对称的.
You are using the function linalg.eigh which is for symmetric/Hermitian matricies, your matrix is not symmetric.
https://docs .scipy.org/doc/numpy-1.14.0/reference/generation/numpy.linalg.eigh.html
您需要使用linalg.eig,您将获得正确的结果:
You need to use linalg.eig and you will get the correct result:
https://docs.scipy.org /doc/numpy/reference/generated/numpy.linalg.eig.html
import numpy as np
from numpy import linalg as lg
Eigenvalues, Eigenvectors = lg.eig(np.array([
[1, 3],
[2, 5]
]))
Lambda = np.diag(Eigenvalues)
Eigenvectors @ Lambda @ lg.inv(Eigenvectors)
返回
[[ 1. 3.]
[ 2. 5.]]
符合预期.
这篇关于本征分解让我纳闷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!