代数插值
已知$n+1$个点,构造插值多项式:
$$P_n(x)=a_0+a_1x+a_2x^2+\cdots+a_nx^n$$
将点代入,构造如下方程组:
$$\begin{cases} a_0+a_1x_0+a_2x_0^2+\cdots+a_nx_0^n=f(x_0)\\ a_0+a_1x_1+a_2x_1^2+\cdots+a_nx_1^n=f(x_1)\\ ~\vdots \\ a_0+a_1x_n+a_2x_n^2+\cdots+a_nx_n^n=f(x_n) \end{cases}$$
例如:已知四个点$(1,1),(2,3),(3,2),(4,5)$
$$\begin{cases} a_0+a_1+a_2+a_3=1\\ a_0+2a_1+4a_2+16a_3=3\\ a_0+3a_1+9a_2+27a_3=2\\ a_0+4a_1+16a_2+64a_3=5 \end{cases} \Rightarrow \begin{cases} a_0=-11 \\ a_1=19.333\\ a_2=-8.5 \\ a_3=1.1667 \end{cases}$$
$所以P_3(x)=-11+19.333x-8.5x^2+1.1667x^3 $
效果图如下:
泰勒插值
泰勒公式:
$$f(x)=f(x_0)+f^{'}(x_0)(x-x_0)+\frac{f^{''}(x_0)}{2!}(x-x_0)^2+\cdots+\frac{f^{(n)}(x_0)}{n!}(x-x_0)^n+R_n(x)$$
我们不仅知道了一点$(x_0,f(x_0))$,还知道了在$x_0$处的$n$阶导数。
例如:
$$\begin{array} & f(x)=sinx & f^{'}(x)=cosx & f^{''}(x)=-sinx & f^{'''}(x)=-cosx & \cdots \\ f(0)=0 & f^{'}(0)=1 & f^{''}(0)=0 & f^{'''}(0)=-1 & \cdots\\ \end{array}$$
$$f(x)=0+(x-0)+\frac{0}{2!}(x-0)^2+\frac{-1}{3!}(x-0)^3+\cdots=x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+\cdots$$
效果图如下:
拉格朗日插值
已知$n+1$个点,构造插值多项式:
$$L(x)=\ell_0(x)y_0+\ell_1(x)y_1+\ell_2(x)y_2+\cdots+\ell_n(x)y_n$$
其中:
$$\begin{align*} \ell_0(x)&=\frac{(x-x_1)(x-x_2)\cdots (x-x_n)}{(x_0-x_1)(x_0-x_2)\cdots (x_0-x_n)} =\prod \limits_{i=0,i\neq 0}^n \frac{x-x_i}{x_0-x_i} \\ \ell_1(x)&=\frac{(x-x_0)(x-x_2)\cdots (x-x_n)}{(x_1-x_0)(x_1-x_2)\cdots (x_1-x_n)} =\prod \limits_{i=0,i\neq 1}^n \frac{x-x_i}{x_1-x_i} \\ &\cdots \\ \ell_k(x)&=\prod \limits_{i=0,i\neq k}^n \frac{x-x_i}{x_k-x_i} \end{align*}$$
$$L(x)=\sum \limits_{k=0}^n\ell_k(x)y_k$$
注:在插值区间内的精度远高于区间外的精度。
例如:已知四个点$(1,1),(2,3),(3,2),(4,5)$
$$\begin{align} \ell_0(x)=\frac{(x-2)(x-3)(x-4)}{(1-2)(1-3)(1-4)}=\frac{x^3-9x^2+26x-24}{-6}\\ \ell_1(x)=\frac{(x-1)(x-3)(x-4)}{(2-1)(2-3)(2-4)}=\frac{x^3-8x^2+19x-12}{2}\\ \ell_2(x)=\frac{(x-1)(x-2)(x-4)}{(3-1)(3-2)(3-4)}=\frac{x^3-7x^2+14x-8}{-2}\\ \ell_3(x)=\frac{(x-1)(x-2)(x-3)}{(4-1)(4-2)(4-3)}=\frac{x^3-6x^2+11x-6}{6} \end{align}$$
$$L(x)=\ell_0y_0+\ell_1y_1+\ell_2y_2+\ell_3y_3=\frac{7x^3-51x^2+116x-66}{6}=1.1667x^3-8.5x^2+19.333x-11$$
效果图如下:
缺点如下图(已知一些相对较平稳的点,则他们的插值函数可能会出现一个大的偏差):
牛顿插值
差商:
$$\begin{align*} f(x)在点x_i的零阶差商为&f(x_i) \\ f(x)在点x_i,x_j的一阶差商为f[x_i,x_j]=&\frac{f(x_i)-f(x_j)}{x_i-x_j} \\ f(x)在点x_i,x_j,x_k的二阶差商为f[x_i,x_j,x_k]=&\frac{f[x_i,x_j]-f[x_j,x_k]}{x_i-x_k} \\ f(x)在点x_0,x_1,x_2\cdots,x_k的k阶差商为f[x_0,x_1,x_2\cdots,x_k]=&\frac{f[x_0,x_1,x_2\cdots,x_{k-1}]-f[x_1,x_2\cdots,x_k]}{x_0-x_k} \end{align*}$$
差商表:
$$\begin{array}{cccccccc} & x_i & y_i & 一阶差商 & 二阶差商 & \cdots & k阶差商 & \cdots & n阶差商 \\ & x_0 & f(x_0) \\ & x_1 & f(x_1) & f[x_0,x_1] \\ & x_2 & f(x_2) & f[x_1,x_2] & f[x_0,x_1,x_2] \\ & \vdots & \vdots & \vdots & \vdots &\ddots \\ & x_k & f(x_k) & f[x_{k-1},x_k] & f[x_{k-2},x_{k-1},x_k] &\cdots & f[x_0,x_1,\cdots,x_k] \\ & \vdots & \vdots & \vdots & \vdots & &\vdots & \ddots \\ & x_n & f(x_n) & f[x_{n-1},x_n] & f[x_{n-2},x_{n-1},x_n] & \cdots & f[x_{n-k},x_{n-k+1},\cdots,x_n] & \cdots & f[x_0,x_1,\cdots,x_n] \end{array}$$
公式推导:
$$\begin{align*} f(x)&=f(x_0)+f[x,x_0](x-x_0) \\ f[x,x_0]&=f[x_0,x_1]+f[x,x_0,x_1](x-x_1) \\ f[x,x_0,x_1]&=f[x_0,x_1,x_2]+f[x,x_0,x_1,x_2](x-x_2) \\ &\cdots \\ f[x,x_0,x_1,\cdots,x_n]&=f[x_0,x_1,\cdots,x_n]+f[x,x_0,x_1,\cdots,x_n](x-x_n) \\ \end{align*}$$
$$\therefore f(x)=f(x_0)+f[x_0,x_1](x-x_0)+f[x_0,x_1,x_2](x-x_0)(x-x_1)+\cdots +f[x_0,x_1,\cdots,x_n](x-x_0)(x-x_1)\cdots (x-x_{n-1})+R_n$$
$$R_n=f[x,x_0,x_1,\cdots,x_n](x-x_0)(x-x_1)\cdots (x-x_n)$$