例题7.2
import numpy as np
from scipy.interpolate import lagrange
x0 = np.arange(1, 7)
y0 = np.array([16, 18, 21, 17, 15, 12])
p = lagrange(x0, y0)
print("从高到低插值多项式的系数为:\n", np.round(p, 4)) # 与上面的结果相同,但过程更直接
prediction = np.polyval(p, [1.5, 2.6])
print("预测值为:\n", prediction)