使用拉格朗日插值法计算 59 48 58 32 30 31 30 序列下面 3 个值
Created on: October 3, 2025
Answered using GPT-5 Thinking by Chat01
Created on: October 3, 2025
Answered using GPT-5 Thinking by Chat01
使用拉格朗日插值法计算 59 48 58 32 30 31 30 序列下面 3 个值
pythonimport sympy as sp x = sp.symbols('x') y_vals = [59,48,58,32,30,31,30] points = list(enumerate(y_vals, start=1)) poly = sp.interpolate(points, x) # Lagrange polynomial poly_simplified = sp.simplify(poly.expand()) poly_simplified 59*x**6/144 - 2461*x**5/240 + 14591*x**4/144 - 23983*x**3/48 + 91783*x**2/72 - 7828*x/5 + 758
pythonvals = [sp.simplify(poly_simplified.subs(x, xi)) for xi in [8,9,10]] vals [430, 2729, 10502]
python# Verify with finite difference table using integers and then extrapolate y = y_vals.copy() diffs = [y_vals] for k in range(1,7): diffs.append([diffs[-1][i+1]-diffs[-1][i] for i in range(len(diffs[-1])-1)]) diffs [[59, 48, 58, 32, 30, 31, 30], [-11, 10, -26, -2, 1, -1], [21, -36, 24, 3, -2], [-57, 60, -21, -5], [117, -81, 16], [-198, 97], [295]]
pythondiffs = [y_vals] for k in range(1,7): diffs.append([diffs[-1][i+1]-diffs[-1][i] for i in range(len(diffs[-1])-1)]) # Now extrapolate 3 steps for step in range(3): # last difference (7th order) stays constant: diffs[6] has length 1 # We'll append to each row from bottom up for order in range(6, -1, -1): if order == 6: next_val = diffs[order][-1] # assume constant diffs[order].append(next_val) else: next_val = diffs[order][-1] + diffs[order+1][-1] diffs[order].append(next_val) # Next 3 y values are the last 3 appended values in diffs[0] after original length diffs[0][-3:], diffs[0] ([430, 2729, 10502], [59, 48, 58, 32, 30, 31, 30, 430, 2729, 10502])
按等间距自变量 构造 6 次拉格朗日插值多项式 ,并在 处外推。
拉格朗日形式:
化简得到的多项式:
计算外推值:
答案: 序列下面 3 个值(用拉格朗日插值外推)为 430,2729,10502。
(提示:高阶多项式外推通常不稳定,结果增长很快,仅作数学外推参考。)