插值思想
求已知的n个点对(x1,y1),(x2,y2),…,(xn,yn)的所有阶差商公式
联立以上差商公式建立如下插值多项式f(x)
其中P(x)是牛顿插值逼近函数,R(x)是误差函数
差商表
xk | f(xk) | 一阶差商 | 二阶差商 | 三阶差商 |
---|---|---|---|---|
x0 | f(x0) | |||
x1 | f(x1) | f[x0,x] | ||
x2 | f(x2) | f[x1,x2] | f[x0,x1,x2] | |
x3 | f(x3) | f[x2,x3] | f[x1,x2,x3] | f[x0,x1,x2,x3] |
… | … | … | … | … |
代码实现
import numpy as np
import matplotlib.pyplot as plt
import random
y_point = []
text_list = []
x_point = random.sample(range(0,12),10)#生成不重复的随机数
for num in range(10):
y_point.append(random.randint(1