【发布时间】:2020-02-10 09:18:07
【问题描述】:
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 这样的较小矩阵时,它工作正常。我究竟做错了什么?
【问题讨论】:
-
在问题中包含输出。
-
@WarrenWeckesser 我刚刚更新了帖子。
-
给定
A的形状是(8,9),prod1的形状应该是(8,8)和prod2应该是(9,9)吧? -
@paul-shuvo,你是对的!
-
你在 Matlab 中使用的是同一个变量吗?