1,5,14,30,下一个是什么?
用多项式拟合
x | 1 | 2 | 3 | 4 |
---|---|---|---|---|
y | 1 | 5 | 14 | 30 |
用多项式拟合,4个未知数需要三次方程$$y=ax^3+bx^2+cx+d$$
$$\begin{pmatrix} 1 & 1& 1 &1 \\ 2^3 & 2^2 & 2 & 1\\ 3^3 & 3^2 & 3 &1 \\ 4^3 & 4^2 & 4 &1 \end{pmatrix} \times \begin{pmatrix} a \\ b \\ c \\ d \end{pmatrix} = \begin{pmatrix} 1 \\ 5 \\ 14 \\ 30 \end{pmatrix} $$
解得 $$\begin{pmatrix} a \\ b \\ c \\ d \end{pmatrix} = \begin{pmatrix} \dfrac{1}{3} \\ \dfrac{1}{2} \\ \dfrac{1}{6} \\ 0 \end{pmatrix} $$
所以$$f(5)=(5^3,5^2,5,1)\times \begin{pmatrix} a \\ b \\ c \\ d \end{pmatrix} = 55$$
秒杀法:
令$$M = \begin{pmatrix} 1 & 1& 1 &1 \\ 2^3 & 2^2 & 2 & 1\\ 3^3 & 3^2 & 3 &1 \\ 4^3 & 4^2 & 4 &1 \end{pmatrix} ,A= \begin{pmatrix} a \\ b \\ c \\ d \end{pmatrix} ,B = \begin{pmatrix} 1 \\ 5 \\ 14 \\ 30 \end{pmatrix} ,$$
$$ m=(5^3,5^2,5,1) $$
则 $$MA=B ,A=M^{-1}B, $$
$$ f(5)=m\times A=m(M^{-1}B)=(mM^{-1})B , mM^{-1}$$为固定值$$ (-1,4,-6,4)$$
所以 秒杀技巧为$$(-1,4,-6,4)\cdot (y_1,y_2,y_3,y_4)$$
每个拉格朗日项为开关,只有x为本项时为1,其余时间为0
$$L(x) = \sum_{ }^{} y_i\cdot \dfrac{\prod_{j\ne i}^{}(x-x_j) }{\prod_{j\ne i}^{}(x_i-x_j)} $$
$$ =1\cdot \dfrac{(x-2)(x-3)(x-4)}{(1-2)(1-3)(1-4)} + 5\cdot \dfrac{(x-1)(x-3)(x-4)}{(2-1)(2-3)(2-4)} $$
$$+ 14\cdot \dfrac{(x-1)(x-2)(x-4)}{(3-1)(3-2)(3-4)} + 30\cdot \dfrac{(x-1)(x-2)(x-3)}{(4-1)(4-2)(4-3)} $$
x=5代入即可
秒杀方法:
x=5, 以及1,2,3,4固定,所以先代入x=5得
$$ L(5)= y_1\times (-1)+y_2\times 4+y_3\times (-6)+y_4\times 4 $$
https://www.jianshu.com/p/0516e3c9f43e
https://www.jianshu.com/p/ac64abd1965e
问题
思路
推导
不太好的推导:
好的推导:可以看到,我们是先确定的x0,然后推导了满足x1的插值公式,那么加入这个思路反过来呢?我们先确定的是x1,然后推导得到满足x0的公式,那么结果如下:
结论
表格法
新增数据
例子
x | 1 | 2 | 3 | 4 |
---|---|---|---|---|
y | 1 | 5 | 14 | 30 |
表格
x | y | 一阶差 | 二阶差 | 三阶差 |
---|---|---|---|---|
1 | 1 | |||
2 | 5 | (5-1)/(2-1)=4 | ||
3 | 14 | (14-5)/(3-2)=9 | (9-4)/(3-1)=2.5 | |
4 | 30 | (30-14)/(4-3)=16 | (16-9)/(4-2)=3.5 | (3.5-2.5)/(4-1)=1/3 |
结果:
y=1+4(x-1) +2.5(x-1)(x-2)+1/3(x-1)(x-2)(x-3)
泰勒公式理念与推导1:
任何函数用多项式模拟
$$f(x)\approx a_0+a_1(x-x_0)+a_2(x-x_0)^2+a_3(x-x_0)^3+\cdots$$
易得$$ f(x_0) = a_0 $$
两边求导
$$ f'(x)\approx a_1+2a_2(x-x_0)+3a_3(x-x_0)^2+\cdots $$
易得$$ f'(x_0) = a_1 $$
两边求导
$$f''(x)\approx 2a_2+3\cdot 2a_3(x-x_0)+\cdots$$
易得$$ f''(x_0) = 2a_2 $$
两边求导
$$f'''(x)\approx3\cdot 2a_3+\cdots$$
易得$$ f'''(x_0) = 3\cdot 2 a_3 $$
两边求导
......
所以:
$$f(x)=\dfrac{f(x_0)}{0!} +\dfrac{f'(x_0)}{1!}(x-x_0) +\dfrac{f''(x_0)}{2!}(x-x_0)^2 +\cdots $$
泰勒公式理念与推导2:
需要复制一条曲线,首先初始位置要相同(S0同),其次初速度相同(v0同),其次加速度相同(a0)相同,加速度的加速度相同。。。。
泰勒公式理念与推导3:
牛顿插值法中dx趋向无穷小
麦克劳伦公式
如果上述中a=0,就得到了麦克劳伦公式(简化版)