简体   繁体   English

我在 for 循环中进行特征值计算的错误是什么?

[英]What is my mistake in the for loop for eigenvalue calculation?

Want to calculate the eigenvalues from the type as shown in the picture but I have a mistake in the for loop and cannot understand.想从图中所示的类型计算特征值,但我在for循环中有错误,无法理解。 Any help?有什么帮助吗?

from scipy import sparse
from scipy.sparse import spdiags
data = np.array([[0,0,0,0], [1,1,1,1], [1/4, 1/4, 1/4, 1/4]])
diags = np.array([0, 1, -1])
A = spdiags(data, diags, 4, 4).toarray()
A
x = np.arange(1,5);x
xi = 2**x
diags = np.array([0])
Q = spdiags(xi, diags, 4, 4).toarray()
Q
B = Q@A@np.linalg.inv(Q);B

n = A.shape[0]
l = np.repeat(0,n)
for k in range(n):
    l[k] = np.cos((k*np.pi)/n+1)
l

or或者

n = A.shape[0]
l = np.repeat(0,n)
for k in range(0,n):
    l = np.cos((k*np.pi)/n+1)
    print(l)

but I do not know if it is right and I want to store them in an object但我不知道它是否正确,我想将它们存储在 object

don't forget your brackets:不要忘记你的括号:

l = np.cos((k*np.pi)/n+1)

l = np.cos((k*np.pi)/(n+1))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM