其他分享
首页 > 其他分享> > 拉格朗日插值

拉格朗日插值

作者:互联网

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

最初的拉差:

\[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}\)

标签:拉格朗,aligned,limits,插值,dfrac,sum,prod,neq
来源: https://www.cnblogs.com/klii/p/15650458.html