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. 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
don't forget your brackets:
l = np.cos((k*np.pi)/n+1)
l = np.cos((k*np.pi)/(n+1))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.