拉格朗日插值 学习笔记
参考资料:OI wiki
多项式中最简单的部分
给出\(n\)个点\((x_i,y_i)\),求过这\(n\)个点的最多\(n-1\)次的多项式\(f(x)\)在\(k\)处的取值.\(n \leq 2 * 10^3\)
法1:瞎搞
使用小学学过的方程组思想解一个2000元2000次方程组.复杂度\(O(Unknown)\)
法2:高斯消元
依然使用小学学过的方程组思想,不过采用高斯消元,每次消去一元,在\(O(n^3)\)的时间内解决问题.
-
消元法的理论基础:
- 两方程互换,解不变;
- 一个方程乘以非零数,解不变;
- 一个方程加上另一方程,解不变.
-
高斯消元法理论基础:
- 在消元法中,只有系数参与运算.
- 可以仅用系数表示方程组.
-
高斯消元法步骤:
- 将增广矩阵化为行最简形;
- 还原线性方程组;
- 将第一个变量用其他变量表示;
- 补充未知量;
- 用列表示通解.
-
高斯消元法实例:(来自OI wiki)
-
\[\left\{\begin{aligned}22x_1+5x_3+6x_4&=9 \notag \\3x_3+x_4&=-4 \notag \\42x_3+2x_4&=-8 \notag5\end{aligned}\right. \]
-
\[\left(\begin{matrix} 2 & 0 & 5 & 6 \\ 0 & 0 & 1 & 1 \\ 0 & 0 & 2 & 2 \end{matrix} \middle| \begin{matrix} 9 \\ -4 \\ -8 \end{matrix} \right) \xrightarrow{} \left(\begin{matrix} 1 & 0 & 0 & 0.5 \\ 0 & 0 & 1 & 1 \\ 0 & 0 & 0 & 0 \end{matrix} \middle| \begin{matrix} 14.5 \\ -4 \\ 0 \end{matrix} \right) \]
-
\[\left\{\begin{aligned} x_1+0.5x_4 &= 14.5 \notag\\ x_3+x_4 &= -4 \notag \\ \end{aligned}\right. \]
-
\[\left\{\begin{aligned} x_1 &= -0.5x_4+14.5\notag \\ x_3 &= -x_4-4\notag \end{aligned}\right. \]
-
\[\left\{\begin{aligned} x_1 &= -0.5x_4+14.5 \notag \\ x_2 &= x_2 \notag \\ x_3 &= -x_4-4 \notag \\ x_4 &= x_4 \notag \end{aligned}\right. \]
-
\[\begin{aligned} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \end{pmatrix} &= \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix} x_2+ \begin{pmatrix} -0.5 \\ 0 \\ -1 \\ 1 \end{pmatrix} x_4 + \begin{pmatrix} 14.5 \\ 0 \\ -4 \\ 0 \end{pmatrix} \notag \\ &= \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix} C_1+ \begin{pmatrix} -0.5 \\ 0 \\ -1 \\ 1 \end{pmatrix} C_2 + \begin{pmatrix} 14.5 \\ 0 \\ -4 \\ 0 \end{pmatrix} \notag \end{aligned} \]
-
复杂度依然无法通过.
法3:拉格朗日插值
显然如果我们构造\(n\)个多项式\(G_i(x)\)分别在\(x_i\)处取值为\(y_i\)而在\(x_j(j \not = i)\)取值均为\(0\),那么\(\sum G_i(x)\)必定满足要求.
考虑如何构造.容易想到利用\(\Pi\)的性质,其中有一项等于0则不管其他项取值为多少,都能保证最终取值为0,再考虑如何让其在\(x_i\)处取值为\(y_i\),显然在让其表示为\(y_iG_i(x)\)的形式,并在\(x_i\)处取值为1即可.考虑利用分式上下相等即取1的性质,使其分母为\(x_i-x_j\)就满足条件.
这样,对于每个\(G_i(x)\):
\[G_i=y_i\prod_{j \not = i}\frac{x-x_i}{x_i-x_j}
\]
这样\(f(x)\)易得:
\[f(x)=\sum_{i=1}^{n}y_i\prod_{j \not = i}\frac{x-x_i}{x_i-x_j}
\]
具体实践中一般需要求逆元.
严谨的证明需要解线性同余方程组.(来自OIwiki)
首先发现:
\[f(x) \equiv f(x_i)\pmod{(x-x_i)}\\
f(x) \equiv y_i\pmod{(x-x_i)}
\]
由此列出方程组
\[\begin{cases}
f(x)\equiv y_1\pmod{(x-x_1)}\\
f(x)\equiv y_n\pmod{(x-x_2)}\\
\cdots\\
f(x)\equiv y_n\pmod{(x-x_n)}
\end{cases}
\]
显然运用中国剩余定理:
- \(n=\Pi{(x-x_i)}\)
- \(m_j=\frac{\prod_{j=1}^n{(x-x_j)}}{x-x_i}=\prod_{j=1,j\not = i}^{n}{(x-x_j)}\)
- \(c_i=m_i(m_i^{-1}\pmod{(x-x_i)})\)
- \(f(x)=\sum_{i=1}^{n}y_i\prod_{j\not=i}{\frac{x-x_j}{x_i-x_j}}\)
证毕.
本文来自博客园,作者:Kinuhata,转载请注明原文链接:https://www.cnblogs.com/KinuhataSaiai/p/15518284.html

浙公网安备 33010602011771号