gpt4 book ai didi

python - 为什么我的 A*A Transpose 和 A Transpose*A 的特征值不匹配?

转载 作者:太空宇宙 更新时间:2023-11-03 19:45:50 26 4
gpt4 key购买 nike

  import numpy as np
import matplotlib.pyplot as plt
import scipy.linalg as la
A = np.array([[-5,-5,-1,0,0,0,500,500,100],
[0,0,0,-5,-5,-1,500,500,100],
[-150,-5,-1,0,0,0,30000,1000,80],
[0,0,0,-150,-5,-1,12000,400,80],
[-150,-150,-1,0,0,0,33000,33000,220],
[0,0,0,-150,-150,-1,12000,12000,80],
[-5,-150,-1,0,0,0,500,15000,100],
[0,0,0,-5,-150,-1,1000,30000,200]])

print("Matrix A is :\n", A)
A_Trans=np.transpose(A)
print("Transpose is:\n",A_Trans)
prod1=np.dot(A,A_Trans)
print(prod1)
u,v = la.eigh(prod1)
print("Eigen values of AAT are \n",np.abs(u))
print("Corresponding eigenvectors of AAT in the columns: \n",np.abs(v))
prod2=np.dot(A_Trans,A)
print(prod2)
w,x = la.eigh(prod2)
print("Eigen values of ATA are \n",np.abs(w))
print("Corresponding eigenvectors of ATA in the columns: \n",np.abs(x))

这是我得到的输出。为了保持帖子的整洁,我省略了一些输出。

Eigen values of AAT are 
[2.85018004e+09 4.52373040e+00 2.19731826e+03 1.84822781e+04
2.46139762e+04 4.52427374e+04 1.01150754e+09 2.18234247e+09]

Eigen values of ATA are
[3.28219743e+09 6.70266037e+08 2.95889936e-01 1.23330275e+00
9.79916827e+03 2.20387805e+04 3.06750605e+04 7.13857850e+04
1.12278371e+06]

我想过使用 svd 函数,但我想亲自尝试一下。然而,它在 MATLAB 中运行得很好,但在 Python 中却不行。另外,当我输入较小的矩阵(例如 2X2)时,它工作得很好。我究竟做错了什么?

最佳答案

这没有给你所有相同的值的原因是 A 是一个 8 x 9 矩阵。这意味着 np.dot(A,A_Trans) 为您提供 8 x 8 矩阵,而 np.dot(A_Trans,A) 为您提供 9 x 9 矩阵(这是因为矩阵乘法规则)。

8x8 矩阵不可能具有与 9x9 矩阵相同的特征值,因为一个矩阵有 8 个特征值,另一个矩阵有 9 个特征值。这甚至反射(reflect)在您的更新中,其中一个列表有 8 个值,另一个有 9。

关于python - 为什么我的 A*A Transpose 和 A Transpose*A 的特征值不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60142363/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com