拉格朗日插值

主要是记录重心拉格朗日插值

最初的拉差:

\[f(x) = \sum\limits_{i=1}^n y_i \prod\limits_{j\neq i} \dfrac {x - x_j}{x_i - x_j} \]

变一下柿子:

\[\begin{aligned}f(x) &= \sum\limits_{i=1}^n y_i \dfrac {\prod\limits_{j=1}^n(x-x_j)}{(x - x_i)\prod\limits_{j\neq i}(x_i - x_j)} \\ &=\prod\limits_{j=1}^n(x-x_j) \sum\limits_{i=1}^n \dfrac{y_i}{(x - x_i)\prod\limits_{j\neq i}(x_i - x_j)} \end{aligned} \]

记 \(g(x) = \prod\limits_{i=1}^n x - x_i, h(i) = \prod\limits_{j\neq i}{x_i - x_j}\),则

\[f(x) = g(x)\sum\limits_{i=1}^n \dfrac{y_i}{(x-x_i)h(i)} \]

计算 \(h(i),g(x)\) 即可 \(\mathrm{O(n)}\) 求 \(f(x)\)。

例:\(\texttt{CF1155E Guess the Root}\)

上一篇:扩展欧几里得算法


下一篇:Quantization公式推导