Suppose K is the 9 by 9 second difference matrix (2's on the diagonal, -1's on the diagonal above and also below). Solve the equation Kx = b = (10, ..., 10). If you graph x1, ..., x9 above the points 1, ..., 9 on the x axis, I think the nine points fall on a parabola.
怎么用python画这个图?
这是答案,用的是matlab:
笑死,我的线代全还给老师了
直接进行一个恶补
import numpy as np
from matplotlib import pyplot as plt
K = np.eye(9) * 2
np.fill_diagonal(K[:-1, 1:], -1)
np.fill_diagonal(K[1:, :-1], -1)
print(K)
# print(K1)
B = np.ones((9, 1)) * 10
print(B)
X = np.linalg.solve(K, B)
print(X)
# X = B / K
# print(X)
plt.plot(range(X.shape[0]), X)
plt.show()
😂😂
import numpy as np
from matplotlib import pyplot as plt
K = np.eye(9) * 2
np.fill_diagonal(K[:-1, 1:], -1)
np.fill_diagonal(K[1:, :-1], -1)
B = np.ones((9, 1)) * 10
X = np.linalg.solve(K, B)
print(X)
plt.plot(range(1, X.shape[0] + 1), X)
plt.xlim([1, 9])
plt.ylim([40, 130])
plt.show()