问题描述
我的问题与显示将5 x 1向量重复应用于具有高斯-随机元素的5 x 5对称矩阵有关。我想证明我对特征值的估计收敛(逐渐趋于零)。
我使用了与此处找到的类似的代码:Getting eigenvalues from 3x3 matrix in Python using Power method,并尝试对其进行更改以适合我的问题。
在下面运行我的代码后,我发现以下结果-[2.460508363078007、1.9278897530810486、1.5179404650567603、1.2006967066279755、0.9530814844968405]-显示了我认为特征值的收敛...
import numpy as np
import numpy.linalg as la
eps = 1e-8 # Precision of eigenvalue
def trans(v): # translates vector (v^T)
v_1 = np.copy(v)
return v_1.reshape((5,5))
def power(A):
eig = []
Ac = np.copy(A)
lamb = 0
for i in range(5):
x = np.random.uniform(0.0,1.0)
while True:
x_1 = Ac.dot(x) # y_n = A*x_(n-1)
x_norm = la.norm(x_1)
x_1 = x_1/x_norm # x_n = y_n/||y_n||
if(abs(lamb - x_norm) <= eps): # If precision is reached,it returns eigenvalue
break
else:
lamb = x_norm
x = x_1
eig.append(lamb)
# Matrix Deflaction: A - Lambda * norm[V]*norm[V]^T
v = x_1/la.norm(x_1)
R = v * trans(v)
R = eig[i]*R
Ac = Ac - R
return eig
def main():
A = np.array(np.random.uniform(0.0,1.0,25)).reshape((5,5))
print(power(A))
if __name__ == '__main__':
main()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)