欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

拉格朗日插值法

最编程 2024-06-30 14:18:59
...

观察公式(1),发现多项式 P ( x ) P(x) P(x)其实可以表示为n+1个同类多项式的和:
P ( x ) = a 0 + a 1 x + a 2 x 2 + ⋯ + a n x n P 0 ( x ) = a 00 + a 10 x + a 20 x 2 + ⋯ + a n 0 x n P 1 ( x ) = a 01 + a 11 x + a 21 x 2 + ⋯ + a n 1 x n … P n ( x ) = a 0 n + a 1 n x + a 2 n x 2 + ⋯ + a n n x n P = P 1 + P 2 + ⋯ + P n = ∑ i = 0 n P i ( x ) P(x)=a_0+a_1x+a_2x^2+\dots+a_nx^n \\ \quad \\ P_0(x)=a_{00}+a_{10}x+a_{20}x^2+\dots+a_{n0}x^n \\ P_1(x)=a_{01}+a_{11}x+a_{21}x^2+\dots+a_{n1}x^n \\ \dots \\ P_n(x)=a_{0n}+a_{1n}x+a_{2n}x^2+\dots+a_{nn}x^n \\ \quad \\ P=P_1+P_2+\dots+P_n=\sum_{i=0}^n P_i(x) P(x)=a0+a1x+a2x2++anxnP0(x)=a00+a10x+a20x2++an0xnP1(x)=a01+a11x+a21x2++an1xnPn(x)=a0n+a1nx+a2nx2++annxnP=P1+P2++Pn=i=0nPi(x)

假定 P i ( x i ) = f ( x i ) , P i ( x j ) = 0 , i ≠ j P_i(x_i)=f(x_i),P_i(x_j)=0,i\ne j Pi(xi)=f(xi),Pi(xj)=0,i=j,则有:
P ( x 0 ) = P 1 ( x 0 ) + P 2 ( x 0 ) + ⋯ + P n ( x 0 ) = f ( x 0 ) P ( x 1 ) = P 1 ( x 1 ) + P 2 ( x 1 ) + ⋯ + P n ( x 1 ) = f ( x 1 ) … P ( x n ) = P 1 ( x n ) + P 2 ( x n ) + ⋯ + P n ( x n ) = f ( x n ) P(x_0)=P_1(x_0)+P_2(x_0)+\dots+P_n(x_0) = f(x_0) \\ P(x_1)=P_1(x_1)+P_2(x_1)+\dots+P_n(x_1) = f(x_1) \\ \dots \\ P(x_n)=P_1(x_n)+P_2(x_n)+\dots+P_n(x_n) = f(x_n) \\ P(x0)=P1(x0)+P2(x0)++Pn(x0)=f(x0)P(x1)=P1(x1)+P2(x1)++Pn(x1)=f(x1)P(xn)=P1(xn)+P2(xn)++Pn(xn)=f(xn)
于是多项式 P ( x ) P(x) P(x)就可以拆分为满足 P i ( x i ) = f ( x i ) , P i ( x j ) = 0 , i ≠ j P_i(x_i)=f(x_i),P_i(x_j)=0,i\ne j Pi(xi)=f(xi),Pi(xj)=0,i=j的n+1个多项式之和,即:
P i ( x ) = f ( x i ) p i ( x ) p i ( x ) = { 1 , x = x i 0 , x ≠ x i P_i(x)=f(x_i)p_i(x) \\ \quad \\ p_i(x)= \begin{cases} 1, & x=x_i \\ 0, & x\ne x_i \\ \end{cases} Pi(x)=f(xi)pi(x)pi(x)={1,0,x=xix=xi
那么问题就转化为了构造n+1个 p i ( x ) p_i(x) pi(x),一种构造方法是:
p i ( x ) = ( x − x 0 ) ( x − x 1 ) … ( x − x i − 1 ) ( x − x i + 1 ) … ( x − x n ) ( x i − x 0 ) ( x i − x 1 ) … ( x i − x i − 1 ) ( x i − x i + 1 ) … ( x i − x n ) = ∏ i ≠ j 0 ≤ j ≤ n x − x j x i − x j p_i(x)=\frac {(x-x_0)(x-x_1)\dots(x-x_{i-1})(x-x_{i+1})\dots(x-x_n)}{(x_i-x_0)(x_i-x_1)\dots(x_i-x_{i-1})(x_i-x_{i+1})\dots(x_i-x_n)} \\ \quad \\ = \prod_{i\ne j}^{0\le j \le n} \frac{x-x_j}{x_i-x_j} pi(x)=(xix0)(xix1)(xixi1)(xixi+1)(xixn)(xx0)(xx1)(xxi1)(xxi+1)(xxn)=i=j0jnxixjxxj
上面这个 p i ( x ) p_i(x) pi(x)就称为拉格朗日插值的基函数

最终,拉格朗日插值的结果就可以写成:
P ( x ) = ∑ i = 0 n P i ( x ) = ∑ i = 0 n f ( x i ) p i ( x ) = ∑ i = 0 n ( f ( x i ) ∏ i ≠ j 0 ≤ j ≤ n x − x j x i − x j ) P(x)=\sum_{i=0}^n P_i(x) \\ \quad \\ = \sum_{i=0}^n f(x_i)p_i(x) \\ \quad \\ = \sum_{i=0}^n (f(x_i)\prod_{i\ne j}^{0\le j \le n} \frac{x-x_j}{x_i-x_j}) P(x)=i=0nPi(x)=i=0nf(xi)pi(x)=i=0n(f(xi)i=j0jnxixjxxj)