```python import numpy as np def newton_interpolation(x, y): n = len(x) a = np.zeros((n, n)) a[:, 0] = y for j in range(1, n): for i in range(n - j): a[i][j] = (a[i + 1][j - 1] - a[i][j - 1]) / (x[i + j] - x[i]) def newton_polynomial(x_val): result = a[0][0] temp_prod = 1 for i in range(1, n): temp_prod *= (x_val - x[i - 1]) result += temp_prod * a[0][i] return result return newton_polynomial # 示例 x = np.array([0, 1, 2, 3]) y = np.array([1, 2, 3, 4]) newton_poly = newton_interpolation(x, y) print(newton_poly(1.5)) # 输出:2.5 ``` [2024-05-25 18:37:11 | AI写代码神器 | 291点数解答]