Chap 3: Interpolation and Polynomial Approximation⚓︎
约 3389 个字 预计阅读时间 17 分钟
Interpolation and the Lagrange Polynomial⚓︎
例子
给定 \(\sin \dfrac{\pi}{6} = \dfrac{1}{2}, \sin \dfrac{\pi}{4} = \dfrac{1}{\sqrt{2}}, \sin \dfrac{\pi}{3} = \dfrac{\sqrt{3}}{2}\)。使用关于 \(\sin x\) 的线形和二次拉格朗日多项式,计算 \(\sin 50 \degree\) 并评估误差。
(已知 \(\sin 50 \degree = 0.7660444...\))
-
先使用 \(x_0, x_1\) 和 \(x_1, x_2\) 计算线形插值。
- 使用 \(x_0 = \dfrac{\pi}{6}, x_1 = \dfrac{\pi}{4}\)
- \(P_1(x) = \dfrac{x - \frac{\pi}{4}}{\frac{\pi}{6} - \frac{\pi}{4}} \times \dfrac{1}{2} + \dfrac{x - \frac{\pi}{6}}{\frac{\pi}{4} - \frac{\pi}{6}} \times \dfrac{1}{\sqrt{2}}\)
- \(50 \degree = \dfrac{5\pi}{18}\)
- \(\sin 50 \degree \approx P_1(\dfrac{5 \pi}{18}) \approx 0.77614\)
- \(f(x) = \sin x, f^{(2)} = - sin \xi_x, \xi_x \in (\dfrac{\pi}{6}), \dfrac{\pi}{3}\),且 \(\dfrac{1}{2} < \sin \xi_x < \dfrac{\sqrt{3}}{2}\)
- \(R_1 (x) = \dfrac{f^{(2)(\xi_x)}}{2!}(x - \dfrac{\pi}{6})(x - \dfrac{\pi}{4})\),得到 \(-0.01319 < R_1(\dfrac{5\pi}{18}) < -0.00762\),因此外推误差 \(\approx -0.01001\)
- 使用 \(x_1 = \dfrac{\pi}{4}, x_2 = \dfrac{\pi}{3}\)
- 计算得到 \(\sin 50 \degree \approx 0.76008, 0.00538 < \widetilde{R_1}(\dfrac{5\pi}{18}) < 0.00660\)
- 因此插值误差 \(\approx 0.00596\)
- 使用 \(x_0 = \dfrac{\pi}{6}, x_1 = \dfrac{\pi}{4}\)
-
再使用 \(x_0, x_1, x_2\) 计算二次插值。
- \(P_2(x) = \frac{(x - \frac{\pi}{4})(x - \frac{\pi}{3})}{(\frac{\pi}{6} - \frac{\pi}{4})(\frac{\pi}{6} - \frac{\pi}{2})} \times \dfrac{1}{2} + \frac{(x - \frac{\pi}{6})(x - \frac{\pi}{3})}{(\frac{\pi}{4} - \frac{\pi}{6})(\frac{\pi}{4} - \frac{\pi}{3})} \times \dfrac{1}{\sqrt{2}} + \frac{(x - \frac{\pi}{6})(x - \frac{\pi}{4})}{(\frac{\pi}{3} - \frac{\pi}{6})(\frac{\pi}{3} - \frac{\pi}{4})} \times \dfrac{\sqrt{3}}{2}\)
- \sin 50 \degree \approx P_2(\dfrac{5\pi}{18}) \approx 0.76543
- \(R_2(x) = \dfrac{- \cos \xi_x}{3!}(x - \dfrac{\pi}{6})(x - \dfrac{\pi}{4})(x - \dfrac{\pi}{3}),\ \dfrac{1}{2} < \cos \xi_x < \dfrac{\sqrt{3}}{2}\)
- \(0.00044 < R_2(\dfrac{5 \pi}{18}) < 0.00077\),所以二次插值的误差 \(\approx 0.00061\)
更高次的插值法通常会带来更好的结果,但并不总是如此。
这里还没整理小人的对话。
Neville's Method⚓︎
定义
令 \(f\) 是关于 \(x_0, x_1, \dots, x_n\) 的函数,并假设 \(m_1, \dots, m_k\) 是 \(k\) 个不同的整数且满足 \(\forall i, 0 \le m_i \le n\)。拉格朗日多项式在 \(k\) 个点 \(x_{m_1}, \dots, x_{m_k}\) 上与 \(f(x)\) 具有相同值时,记作 \(P_{m_1, \dots, m_k}(x)\)。
定理
令 \(f\) 是关于 \(x_0, x_1, \dots, x_k\) 的函数,并令 \(x_i, x_j\) 为其中两个不相等的数,那么:
描述了在 \(k+1\) 个点 \(x_0, x_1, \dots, x_k\) 上向 \(f\) 插值的第 \(k\) 个拉格朗日多项式。
证明
- 对任意 \(0 \le r \le k\) 且 \(r \ne i \text{ and } j\),两个在分子上插值多项式等于 \(f(x_r)\),因此 \(P(x_r) = f(x_r)\)
- 第一个在分子上的多项式等于 \(f(x_i)\),且第二项为 0,所以 \(P(x_i) = f(x_i)\)。同理,\(P(x_j) = f(x_j)\)
- 因此,在 \(k+1\) 个点 \(x_0, x_1, \dots, x_k\) 上向 \(f\) 插值的第 \(k\) 个拉格朗日多项式是唯一的
Neville 法:
Divided Difference⚓︎
- 1 阶差商:\(f[x_i, x_j] = \dfrac{f(x_i) - f(x_j)}{x_i - x_j} (i \ne j, x_i \ne x_j)\)
- 2 阶差商:\(f[x_i, x_j, x_k] = \dfrac{f[x_i, x_j] - f[x_j, x_k]}{x_i - x_k} (i \ne k)\)
-
\(k+1\) 阶差商:
\[ \begin{align} f[x_0, \dots, x_{k+1}] & = \dfrac{f[\textcolor{cornflowerblue}{x_0}, x_1, \dots, x_k] - f[x_1, \dots, x_k, \textcolor{cornflowerblue}{x_{k+1}}]}{\textcolor{cornflowerblue}{x_0 - x_{k+1}}} \notag \\ & = \dfrac{f[x_0, \dots, x_{k-1}, \textcolor{cornflowerblue}{x_k}] - f[x_0, \dots, x_{k-1}, \textcolor{cornflowerblue}{x_{k+1}}]}{\textcolor{cornflowerblue}{x_k - x_{k+1}}} \notag \end{align} \]
事实上,\(f[x_0, \dots, x_k] = \sum\limits_{i=0}^k \dfrac{f(x_i)}{\omega_{k+1}' (x_i)}\),其中 \(\omega_{k+1}(x) = \prod\limits_{i=0}^k (x - x_i), \omega_{k+1}'(x_i) = \prod\limits_{\substack{j = 0 \\ j \ne i}}^k (x_i - x_j)\)。这个公式的要点在于:\(f[x_0, \dots, x_k]\) 的值和 \(x_0, \dots, x_k\) 的顺序无关。
Newton's Interpolation⚓︎
目标:得到 \(N_n(x) = a_0 + a_1(x - x_0) + a_2(x - x_0)(x - x_1) + \dots + a_n(x - x_0) \dots (x - x_{n-1})\)
计算 \((1) + (x - x_0) \times (2) + \dots + (x - x_0) \dots (x - x_{n-1}) \times (n-1)\),得到:
其中红色部分就是我们要求的 \(N_n(x)\) ,而绿色部分是 \(R_n(x)\)。另外,\(a_i = f[x_0, \dots, x_i]\)
注
- 因为第 n 个插值多项式是唯一的,所以 \(N_n(x) \equiv P_n(x)\)
-
它们必须有相同的截断误差,即:
\[ \begin{align} & f[x, x_0, \dots, x_n] \omega_{k+1} (x) = \dfrac{f^{(n+1)}(\xi_x)}{(n+1)!} \omega_{k+1}(x) \notag \\ & \Rightarrow f[x_0, \dots, x_k] = \dfrac{f^{(k)}(\xi)}{k!}, \xi \in (x_{\text{min}}, x_{\text{max}}) \notag \end{align} \] -
该过程和 Neville 法类似:
\[ \begin{matrix} f(x_0) & & & & & \notag \\ f(x_1) & f[x_0, x_1] & & & & \notag \\ f(x_2) & f[x_1, x_2] & f[x_0, x_1, x_2] & & & \notag \\ \dots & \dots & \dots & & & \notag \\ f(x_{n-1}) & \dots & \dots & & & \notag \\ f(x_n) & f[x_{n-1}, x_n] & f[x_{n-2}, x_{n-1}, x_n] & & f[x_0, \dots, x_n] \notag \\ f(x_{n+1}) & f[x_n, x_{n+1}] & f[x_{n-1}, x_n x_{n+1}] & \dots & f[x_1, \dots, x_{n+1}] & f[x_0, \dots, x_{n+1}] \notag \end{matrix} \]
Formulae with Equal Spacing⚓︎
如果这些点是等间距的,即 \(x_i = x_0 + ih\ (i = 0, \dots, n)\),那么:
- 前向差(forward difference):\(\Delta f_i = f_{i+1} - f_i, \Delta^k f_i = \Delta(\Delta^{k-1} f_i) = \Delta^{k-1} f_{i+1} - \Delta^{k-1} f_i\)
- 后向差(backward difference)::\(\nabla f_i = f_i - f_{i-1}, \nabla^k f_i = \nabla(\Delta^{k-1} f_i) = \nabla^{k-1} f_i - \nabla^{k-1} f_{i-1}\)
- 中心差(centered difference):\(\delta^k f_i = \delta^{k-1} f_{i+\frac{1}{2}} - \delta^{k-1} f_{i - \frac{1}{2}}\),其中 \(f_{i \pm \frac{1}{2}} = f(x_i \pm \dfrac{h}{2})\)
Some Important Properties⚓︎
- 线性:\(\Delta(a \cdot f(x) + b \cdot g(x)) = a \Delta f + b \Delta g\)
- 如果 \(f(x)\) 是一个 \(m\) 阶多项式,那么 \(\Delta^k f(x)\ (0 \le k \le m)\) 是一个 \(m - k\) 阶多项式且 \(\Delta^k f(x) = 0\ (k > m)\)
-
差值还能从以下函数中得到:
- \(\Delta^n f_k = \sum\limits_{j=0}^n (-1)^j \left( \begin{array}{cccc}n \\ j\end{array}\right) f_{n+k-j}\)
- \(\nabla^n f_k = \sum\limits_{j=0}^n (-1)^{n-j} \left( \begin{array}{cccc}n \\ j\end{array}\right) f_{k+j-n}\)
-
反之亦然:\(f_{n+k} = \sum\limits_{j=0}^n \left( \begin{array}{cccc}n \\ j\end{array}\right) \Delta^j f_k\)
- \(f[x_0, \dots, x_k] = \dfrac{\Delta^k f_0}{k! h^k}, f[x_n, x_{n-1}, \dots, x_{n-k}] = \dfrac{\nabla^k f_n}{k!h^k}\)。从 \(R_n\) 可以得到:\(f^{(k)}(\xi) = \dfrac{\Delta^k f_0}{h^k}\)
总结
- 牛顿前向差公式:令 \(x = x_0 + th\),那么 \(N_n(x) = N_n(x_0 + th) = \sum\limits_{k=0}^n \left( \begin{array}{cccc}t \\ k\end{array}\right) \Delta^k f(x_0), R_n(x) = \dfrac{f^{(n+1)} (\xi)}{(n+1)!} t(t-1) \dots (t-n)h^{n+1}, \xi \in (x_0, x_n)\)
- 牛顿后向差公式:颠倒点的顺序,即计算 \(N_n(x) = f(x_n) + f[x_n, x_{n-1}](x - x_n) + dots + f[x_n, \dots, x_0](x - x_n) \dots (x - x_1)\)。令 \(x = x_n + th\),那么 \(N_n(x) = N_n(x_n + th) = \sum\limits_{k=0}^n (-1)^k \left( \begin{array}{cccc}-t \\ k\end{array}\right) \nabla^k f(x_n)\)
Hermite Interpolation⚓︎
目标:找到一个密切多项式 (osculating polynomial) \(P(x)\),使得 \(\forall i = 0, 1, \dots, n, P(x_i) = f(x_i), P'(x_i) = f'(x_i), \dots, P^{(m_i)}(x_i) = f^{(m_i)}(x_i)\)。
注
- 给定 \(N\) 个条件(即有 \(N\) 个方程
) ,\(N - 1\) 阶多项式就能确定下来 -
与 \(f\) 以及所有在一个点 \(x_0\) 上的 \(\le m_0\) 阶的导数吻合的密切多项式就是一个泰勒多项式:
\[ P(x) = f(x_0) + f'(x_0)(x - x_0) + \dots + \dfrac{f^{(m_0)}(x_0)}{m_0!}(x - x_0)^{m_0} \]且余项 \(R(x) = f(x) - \varphi(x) = \dfrac{f^{(m_0 + 1)}(\xi)}{(m_0 + 1)!}(x - x_0)^{(m_0 + 1)}\)
-
当 \(\forall i = 0, 1, \dots, n,\ m_i = 1\) 时,此时的多项式为埃尔米特多项式(Hermite polynomials)
例子
假设 \(x_0 \ne x_1 \ne x_2\)。给定 \(f(x_0), f(x_1), f(x_2)\) 和 \(f'(x_1)\),寻找多项式 \(P(x)\),满足 \(P(x_i) = f(x_i),\ i = 0, 1, 2\),且 \(P'(x_1) = f'(x_1)\)。并分析误差。
首先,\(P(x)\) 的阶必须 \(\le 3\)
与拉格朗日多项式类似,我们要待定一个埃尔米特多项式:\(P_3(x) = \sum\limits_{i=0}^2 f(x_i) h_i(x) + f'(x_1) \hat{h_1}(x)\),其中 \(h_i(x_j) = \delta_{ij}, h_i'(x_1) = 0, \hat{h_1}(x_i) = 0, \hat{h_1}'(x_1) = 1\)
- \(h_0(x)\):有根 \(x_1, x_2\),且 \(h_0'(x_1) = 0 \quad \Rightarrow \quad x_1\) 是一个重根
- \(\begin{cases}h_0(x) = C_0(x - x_1)^2(x - x_2) \\ h_0(x_0) = 1 \Rightarrow C_0\end{cases} \quad \Rightarrow \quad h_0(x) = \dfrac{(x - x_1)^2(x - x_2)}{(x_0 - x_1)^2(x_0 - x_2)}\)
- \(h_2(x)\):与 \(h_0(x)\) 类似
- \(h_1(x)\):有根 \(x_0, x_2 \Rightarrow h_1(x) = (Ax + B)(x - x_0)(x - x_2)\)。\(A, B\) 可通过 \(h_1(x_1) = 0\) 和 \(h_1'(x_1) = 0\) 求解
- \(\hat{h_1}(x)\)::有根 \(x_0, x_1, x_2 \Rightarrow \hat{h_1}(x) = C_1(x - x_0)(x - x_1)(x - x_2)\)。\(h_1(x_1) = 1 \Rightarrow C_1\) 能被求解
一般情况下,给定 \(x_0, \dots, x_n; y_0, \dots, y_n\) 以及 \(y_0', \dots, y_n'\),埃尔米特多项式 \(H_{2n+1}(x)\) 满足对于所有的 \(i\),\(H_{2n+1}(x_i) = y_i\) 且 \(H_{2n+1}'(x_i) = y_i'\)
求解过程
令 \(H_{2n+1}(x) = \sum\limits_{i=0}^n y_i h_i(x) + \sum\limits_{i=0}^n y_i' \hat{h_i}(x)\),其中 \(h_i(x_j) = \delta_{ij}, h_i'(x_j) = 0, \hat{h_i}(x_j) = 0, \hat{h_i}'(x_j) = \delta_{ij}\)
- \(h_i(x)\):
- \(x_0, \dots, \hat{x_i}, \dots, x_n\) 是重数为 2 的根 \(\Rightarrow\ h_i(x) = (A_i x + B_i) L_{n, i}^2(x)\)
- \(A_i, B_i\) 能通过 \(h_i(x_i) = 1, h_i'(x_i) = 0\) 求解
- \(h_i(x) = [1 - 2L_{n, i}'(x_i)(x - x_i)L_{n, i}^2(x)]\)
- \(\hat{x_i}(x)\):
- 除了 \(x_i\) 外,所有的根 \(x_0, \dots, x_n\) 的重数均为 2,得到:
- \(\begin{cases}\hat{h_i}(x) = C_i(x - x_i) L_{n, i}^2(x) \\ \hat{h_i}'(x_i) = 1 \Rightarrow C_i = 1\end{cases} \quad \Rightarrow \quad \hat{h_i}(x) = (x - x_i) L_{n, i}^2(x)\)
如果 \(a = x_0 < x_1 < \dots < x_n = b, f \in C^{2n}[a, b]\),那么 \(R_n(x) = \dfrac{f^{(2n+2)}(\xi_x)}{(2n+2)!}\Big[\prod\limits_{i=0}^n (x - x_i) \Big]^2\)
思考
给定 \(x_i = i + 1, i = 0, 1, 2, 3, 4, 5\),哪一个是 \(\hat{h_2}(x)\)?
待补充
待补充
Cubic Spline Interpolation⚓︎
例子
考虑关于函数 \(f(x) = \dfrac{1}{1 + x^2}\) 在点 \(x_i = -5 + \dfrac{10}{n}i \in [-5, 5] \ (i = 0, \dots, n)\) 的拉格朗日多项式 \(P_n(x)\)
缺少对图片的阐述
\(P_n(x) \not \rightarrow f(x)\)
一些尝试
思路:在每个子区间 \([x_i, x_{i+1}]\) 上,通过线性多项式近似表示 \(f(x)\),即:
令 \(h = \max |x_{i+1} - x_i|\),那么 \(P_1^h(x) \xrightarrow{\text{uniform}}, h \rightarrow 0\)
缺点:不够平滑
思路:给定 \(x_0, \dots, x_n;\ y_0, \dots, y_n;\ y_0', \dots, y_n'\),在区间 \([x_i, x_{i+1}]\) 的两个端点上构造一个关于 \(y, y'\) 的 3 阶埃尔米特多项式
缺点:计算导数不太容易
这里介绍一种更好的方法:三次样条插值(cubic spline interpolation)。
定义
给定一个定义在 \([a, b]\) 上的函数 \(f\),以及一组节点 \(a = x_0 < x_1 \dots < x_n = b\),关于 \(f\) 的三次样条插值器(cubic spline interpolant) \(S\) 是一个满足下面条件的函数:
- \(S(x)\) 是一个三次多项式,记作 \(S_i(x)\),在子区间 \([x_i, x_{i+1}]\) 上(\(i = 0, 1, \dots, n - 1\))
- \(S(x_i) = f(x_i),\ i = 0, 1, \dots, n\)
- \(S_{i+1}(x_{i+1}) = S_i(x_{i+1}),\ i = 0, 1, \dots, n - 2\)
- \(S_{i+1}'(x_{i+1}) = S_i'(x_{i+1}),\ i = 0, 1, \dots, n - 2\)
- \(S_{i+1}''(x_{i+1}) = S_i''(x_{i+1}),\ i = 0, 1, \dots, n - 2\)

Method of Bending Moment⚓︎
令 \(h_j = x_j - x_{j-1}\) 且 对于 \(x \in [x_{j-1}, x_j],\ S(x) = S_j(x)\),那么 \(S_j''(x)\) 是一个 1 阶多项式,并能通过 \(f\) 上的 2 个节点值确定下来。
假设 \(S_j''(x_{j-1}) = M_{j-1}, S_j''(x_j) = M_j\),那么 \(\forall x \in [x_{j-1}, x_j]\),\(S_j''(x) = M_{j-1} \dfrac{x_j - x}{h_j} + M_j \dfrac{x - x_{j-1}}{h_j}\)
对 \(S_j''\) 积分两次,我们得到了:
- \(S_j'(x) = -M_{j-1} \dfrac{(x_j - x)^2}{2h_j} + M_{j-1} \dfrac{(x - x_{j-1})^2}{2h_j} + A_j\)
- \(S_j(x) = M_{j-1} \dfrac{(x_j - x)^3}{6h_j} + M_{j-1} \dfrac{(x - x_{j-1})^3}{6h_j} + A_jx + B_j\)
其中 \(A_j, B_j\) 能通过方程 \(S_j(x_{j-1}) = y_{j-1}, S_j(x_j) = y_j\) 求解。可以得到:
- \(A_j = \dfrac{y_j - y_{j-1}}{h_j} - \dfrac{M_j - M_{j-1}}{6}h_j\)
- \(A_j x + B_j = (y_{j-1} - \dfrac{M_{j-1}}{6} h_j^2) \dfrac{x_j - x}{h_j} + (y_j - \dfrac{M_j}{6}h_j^2)\dfrac{x - x_{j-1}}{h_j}\)
现在我们来求解 \(M_j\):因为 \(S'\) 在 \(x_j\) 上是连续的,所以:
- \([x_{j-1}, x_j]\): \(S_j'(x) = -M_{j-1} \dfrac{(x_j - x)^2}{2h_j} + M_j \dfrac{(x - x_{j-1})^2}{2h_j} + f[x_{j-1}, x_j] - \dfrac{M_j - M_{j-1}}{6}h_j\)
- \([x_j, x_{j+1}]\): \(S_{j+1}'(x) = -M_j \dfrac{(x_{j+1} - x)^2}{2h_{j+1}} + M_{j+1} \dfrac{(x - x_j)^2}{2h_{j+1}} + f[x_j, x_{j+1}] - \dfrac{M_{j+1} - M_j}{6}h_{j+1}\)
根据 \(S_j'(x_j) = S_{j+1}'(x_j)\),我们可以结合 \(M_{j-1}, M_j, M_{j+1}\) 的系数——定义 \(\lambda_j = \dfrac{h_{j+1}}{h_j + h_{j+1}}, \mu_j = 1 - \lambda_j, g_j = \dfrac{6}{h_j + h_{j+1}} (f[x_j, x_{j+1}] - f[x_{j-1}, x_j])\),可以得到:\(\mu_j M_{j-1} + 2M_j + \lambda_j M_{j+1} = g_j\ (1 \le j \le n - 1)\)。也就是说,我们有 \(n+1\) 个未知数,但只有一个方程;另外我们还需要 2 个额外的边界条件。

- 固定边界(clamped boundary):\(S'(a) = y_0', S'(b) = y_n'\)
- \([a, x_1]\): \(S_1'(x) = -M_0 \dfrac{(x_1 - x)^2}{2h_1} + M_1 \dfrac{(x - a)^2}{2h_1} + f[x_0, x_1] - \dfrac{M_1 - M_0}{6}h_1\)
- 在 \([x_{n-1}, b]\) 上 \(S_n'\) 也是类似的:\(\begin{cases}2M_0 + M_1 = \dfrac{6}{h_1} (f[x_0, x_1] - y_0') = g_0 \\ M_{n-1} + 2M_n = \dfrac{6}{h_n} (y_n' - f[x_{n-1}, x_n]) = g_n\end{cases}\)
- 自由边界(free boundary):\(S''(a) = y_0'' = M_0, S''(b) = y_n'' = M_n\),且 \(M_0 = M_n = 0\) 时
- 那么 \(\lambda_0 = 0, g_0 = 2y_0'';\ \mu_n = 0, g_n = 2y_n''\)
- 此时的样条称为自然样条(natural spline)
-
周期边界(periodic boundary):如果 \(f\) 是周期函数,即 \(y_n = y_0\) 且 \(S'(a^+) = S'(b^-) \Rightarrow M_0 = M_n\)
注
- 只要系数矩阵是严格对角占优的,那么三次样条能通过边界被唯一确定
- 如果 \(f \in C[a, b]\) 且 \(\dfrac{\max h_i}{\min h_i} \le C < \infty\),那么当 \(h_i \rightarrow 0\) 时,\(S(x) \xrightarrow{\text{uniform}} f(x)\)。也就是说,在保证不增加样条阶数的情况下,可通过增加节点个数来提升近似精度
算法概述:三次样条插值法
- 计算 \(\mu_j, \lamnda_j, g_j\)
- 求解 \(M_j\)
- 找到包含 \(x\) 的子区间,即找到相应的 \(j\)
- 通过 \(S_j(x)\) 得到 \(f(x)\) 的近似值
评论区