ADD file via upload

main
pj5b93fvk 6 months ago
parent 4434b55419
commit 7a4cd3b358

@ -0,0 +1,39 @@
import numpy as np
# 给定数据
t_values = np.array([0, 10, 15, 20, 22.5, 30])
v_values = np.array([0, 227.04, 362.78, 517.35, 602.97, 901.67])
# 计算Newton插值法所需的差商
def divided_diff(t_values, v_values):
# 用给定的数值初始化差商数组
differences = v_values.copy()
# 遍历每个数据点,计算差商
for i in range(1, len(t_values)):
for j in range(len(t_values) - 1, i - 1, -1):
differences[j] = (differences[j] - differences[j - 1]) / (t_values[j] - t_values[j - i])
return differences
# 使用Newton插值法寻找 t=16 时的速度
def newton_interpolation(t_values, v_values, target_t):
differences = divided_diff(t_values, v_values)
p = differences[0]
for i in range(1, len(t_values)):
term = differences[i]
for j in range(i):
term *= (target_t - t_values[j])
p += term
return p
t_target = 16
velocity_at_16 = newton_interpolation(t_values, v_values, t_target)
print(f"使用Newton插值法t=16 秒时的速度为: {velocity_at_16:.2f} m/s")
Loading…
Cancel
Save