- 程式碼
點選檢視程式碼
import numpy as np
n=1000
A=np.zeros((n,n))
b=np.arange(1,n+1)
np.fill_diagonal(A[1:,:-1],1)
np.fill_diagonal(A[:-1,1:],1)
np.fill_diagonal(A[:-1,1:],1)
x=np.linalg.solve(A,b)
print("解為:")
print(x[:5])
print(x[-5:])
print("學號:3015")
import numpy as np
n=1000
A=np.zeros((n,n))
b=np.arange(1,n+1)
np.fill_diagonal(A[1:,:-1],1)
np.fill_diagonal(A[:-1,1:],1)
np.fill_diagonal(A[:-1,1:],1)
x=np.linalg.solve(A,b)
print("解為:")
print(x[:5])
print(x[-5:])
print("學號:3015")