使用拉格朗日插值法计算 59 48 58 32 30 31 30 序列下面 3 个值

Created on: October 3, 2025

Answered using GPT-5 Thinking by Chat01

Question

使用拉格朗日插值法计算 59 48 58 32 30 31 30 序列下面 3 个值

Python

python
import 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

Python

python
vals = [sp.simplify(poly_simplified.subs(x, xi)) for xi in [8,9,10]] vals [430, 2729, 10502]

Python

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]]

Python

python
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)]) # 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])

Thought

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)])

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])

Thought for 27s

Answer

按等间距自变量 x=1,2,,7x=1,2,\ldots,7 构造 6 次拉格朗日插值多项式 L(x)L(x),并在 x=8,9,10x=8,9,10 处外推。

拉格朗日形式:

L(x)=i=17yijixxjxixj,(xi=i, y=[59,48,58,32,30,31,30])L(x)=\sum_{i=1}^{7} y_i\prod_{j\ne i}\frac{x-x_j}{x_i-x_j},\quad (x_i=i,\ y=[59,48,58,32,30,31,30])

化简得到的多项式:

L(x)=59144x62461240x5+14591144x42398348x3+9178372x278285x+758.\begin{aligned} L(x)=\frac{59}{144}x^6-\frac{2461}{240}x^5+\frac{14591}{144}x^4-\frac{23983}{48}x^3+\frac{91783}{72}x^2-\frac{7828}{5}x+758. \end{aligned}

计算外推值:

L(8)=430,L(9)=2729,L(10)=10502.L(8)=430,\quad L(9)=2729,\quad L(10)=10502.

答案: 序列下面 3 个值(用拉格朗日插值外推)为 430,2729,10502
(提示:高阶多项式外推通常不稳定,结果增长很快,仅作数学外推参考。)

Share this Q&A