拉格朗日插值
均差与牛顿插值多项式
埃尔米特插值
分段低次插值
三次样条插值
有些老师如同大山一样压抑着学生。
华中师范大学真是太多好老师了,可惜这辈子,在本科期间是无缘再见了。
潘老师的学习建议
重基础,多练习,勤思考
I hear and I forget, I see and I remember, I do and I understand.
注意掌握各种数值方法的思想和原理,而不是死记硬背
注意数值方法的处理技巧,以及与计算机编程的结合(编程实践)
注重必要的数值计算训练(必要的手算推导能力)
要重视算法的误差分析、收敛性和稳定性
纸上得来终觉浅,绝知此事要躬行。
问题的提出
白话:根据有限数据来推测未知点的值
插值函数:
P ( x i ) = y i ( i = 0 , 1 , ⋯ , n ) (3.1) P(x_i)=y_i\qquad (i=0,1,\cdots,n) \tag{3.1}
P ( x i ) = y i ( i = 0 , 1 , ⋯ , n ) ( 3.1 )
插值多项式:
P ( x ) = a 0 + a 1 x + ⋯ + a n x n (3.2) P(x)=a_0+a_1x+\cdots+a_nx^n\tag{3.2}
P ( x ) = a 0 + a 1 x + ⋯ + a n x n ( 3.2 )
确定曲线(插值函数)使其通过插值点,用它近似表示数据的理想函数。
多项式插值
给定n + 1 n+1 n + 1 个点,求次数不超过n n n 的多项式。 a i a_i a i 为未知数
{ a 0 + a 1 x 0 + ⋯ + a n x 0 n = y 0 a 0 + a 1 x 1 + ⋯ + a n x 1 n = y 1 . . . a 0 + a 1 x n + ⋯ + a n x n n = y n \begin{cases}
a_0+a_1x_0+\cdots+a_nx_0^n=y_0\\
a_0+a_1x_1+\cdots+a_nx^n_1=y_1\\
...\\
a_0+a_1x_n+\cdots+a_nx^n_n=y_n
\end{cases}
⎩ ⎨ ⎧ a 0 + a 1 x 0 + ⋯ + a n x 0 n = y 0 a 0 + a 1 x 1 + ⋯ + a n x 1 n = y 1 ... a 0 + a 1 x n + ⋯ + a n x n n = y n
化成范德蒙矩阵,其行列式值不为零,解唯一。
行列式值与解的关系 待补充
拉格朗日插值
线性插值
只有两个节(数据)点( x k , y k ) , ( x k + 1 , y k + 1 ) (x_k,y_k),(x_{k+1},y_{k+1}) ( x k , y k ) , ( x k + 1 , y k + 1 )
P ( x ) = a 0 + a 1 x = L 1 ( x ) (线性插值) P(x)=a_0+a_1x=L_1(x)\tag{线性插值}
P ( x ) = a 0 + a 1 x = L 1 ( x ) ( 线性插值 )
要求插值函数上的值与节点值严格一致,在图像上显示出来就是一条直线,其斜率为:
k = y k + 1 − y k x k + 1 − x k k=\frac{y_{k+1}-y_{k}}{x_{k+1}-x_{k}}
k = x k + 1 − x k y k + 1 − y k
转化成:
L 1 ( x ) = y k l k ( x ) + y k + 1 l k + 1 ( x ) (3.3) L_1(x)=y_kl_k(x)+y_{k+1}l_{k+1}(x)\tag{3.3}
L 1 ( x ) = y k l k ( x ) + y k + 1 l k + 1 ( x ) ( 3.3 )
其中:
l k ( x ) = x − x k + 1 x k − x k + 1 l k + 1 ( x ) = x − x k x k + 1 − x k l_k(x)=\frac{x-x_{k+1}}{x_k-x_{k+1}}\qquad l_{k+1}(x)=\frac{x-x_{k}}{x_{k+1}-x_{k}}
l k ( x ) = x k − x k + 1 x − x k + 1 l k + 1 ( x ) = x k + 1 − x k x − x k
l k ( x ) , l k + 1 ( x ) l_k(x),l_{k+1}(x) l k ( x ) , l k + 1 ( x ) 为线性插值基函数,在节点上满足:
l k ( x k ) = 1 l k ( x k + 1 ) = 0 l k + 1 ( x k ) = 0 l k + 1 ( x k + 1 ) = 1 l_k(x_k)=1\qquad l_k(x_{k+1})=0 \qquad l_{k+1}(x_k)=0 \qquad l_{k+1}(x_{k+1})=1\qquad
l k ( x k ) = 1 l k ( x k + 1 ) = 0 l k + 1 ( x k ) = 0 l k + 1 ( x k + 1 ) = 1
习题1: (1,0) (2,4)
l 1 = x − 1 2 − 1 = x − 1 l 2 = x − 2 1 − 2 = 2 − x l_1=\frac{x-1}{2-1}=x-1\qquad l_2=\frac{x-2}{1-2}=2-x
l 1 = 2 − 1 x − 1 = x − 1 l 2 = 1 − 2 x − 2 = 2 − x
l 1 ( x ) = 0 + 4 x − 4 = 4 x − 4 l_1(x)=0+4x-4=4x-4
l 1 ( x ) = 0 + 4 x − 4 = 4 x − 4
抛物插值
有三个节点时:
P ( x ) = a 0 + a 1 x + a 2 x 2 = L 2 ( x ) (抛物插值) P(x)=a_0+a_1x+a_2x^2=L_2(x)\tag{抛物插值}
P ( x ) = a 0 + a 1 x + a 2 x 2 = L 2 ( x ) ( 抛物插值 )
进而化简得到基函数:下面节点减去所有其他的点,上面用x替换节点
L 2 ( x ) = y k − 1 l k − 1 ( x ) + y k l k ( x ) + y k + 1 l k + 1 ( x ) (3.4) L_2(x)=y_{k-1}l_{k-1}(x)+y_{k}l_{k}(x)+y_{k+1}l_{k+1}(x) \tag{3.4}
L 2 ( x ) = y k − 1 l k − 1 ( x ) + y k l k ( x ) + y k + 1 l k + 1 ( x ) ( 3.4 )
其中:
l k − 1 ( x ) = ( x − x k ) ( x − x k + 1 ) ( x k − 1 − x k ) ( x k − 1 − x k + 1 ) l_{k-1}(x)=\frac{(x-x_k)(x-x_{k+1})}{(x_{k-1}-x_{k})(x_{k-1}-x_{k+1})}
l k − 1 ( x ) = ( x k − 1 − x k ) ( x k − 1 − x k + 1 ) ( x − x k ) ( x − x k + 1 )
基函数序数与x序数的关系:相等为1,不相等为0。
l k − 1 ( x k − 1 ) = 1 l k − 1 ( x k ) = 0 l k − 1 ( x k + 1 ) = 0 . . . l_{k-1}(x_{k-1})=1\qquad l_{k-1}(x_{k})=0\qquad l_{k-1}(x_{k+1})=0\qquad
...
l k − 1 ( x k − 1 ) = 1 l k − 1 ( x k ) = 0 l k − 1 ( x k + 1 ) = 0 ...
习题2: (0,1) (1,2) (2,3)
l 1 ( x ) = ( x − 1 ) ( x − 2 ) ( 0 − 1 ) ( 0 − 2 ) . . . l_1(x)=\frac{(x-1)( x-2)}{(0-1)(0-2)}...
l 1 ( x ) = ( 0 − 1 ) ( 0 − 2 ) ( x − 1 ) ( x − 2 ) ...
L 2 ( x ) = l 1 ( x ) y 1 + . . . L_2(x)=l_1(x)y_1+...
L 2 ( x ) = l 1 ( x ) y 1 + ...
拉格朗日插值多项式
当节点数n比3大时
L n ( x j ) = ∑ k = 0 n y k l k ( x j ) = y j ( j = 0 , 1 , ⋯ , n ) (3.5) L_n(x_j)=\sum_{k=0}^n y_kl_k(x_j)=y_j\qquad (j=0,1,\cdots,n)\tag{3.5}
L n ( x j ) = k = 0 ∑ n y k l k ( x j ) = y j ( j = 0 , 1 , ⋯ , n ) ( 3.5 )
n次插值基函数性质:
l j ( x k ) = { 1 k = j 0 k ≠ j l_j(x_k)=
\begin{cases}
1 & k=j\\
0 & k≠j\\
\end{cases}
l j ( x k ) = { 1 0 k = j k = j
l k ( x ) = ( x − x 0 ) ⋯ ( x − x k − 1 ) ( x − x k + 1 ) ⋯ ( x − x n ) ( x k − x 0 ) ⋯ ( x k − x k − 1 ) ( x k − x k + 1 ) ⋯ ( x k − x n ) l_{k}(x)=\frac{\left(x-x_{0}\right) \cdots\left(x-x_{k-1}\right)\left(x-x_{k+1}\right) \cdots\left(x-x_{n}\right)}{\left(x_{k}-x_{0}\right) \cdots\left(x_{k}-x_{k-1}\right)\left(x_{k}-x_{k+1}\right) \cdots\left(x_{k}-x_{n}\right)}
l k ( x ) = ( x k − x 0 ) ⋯ ( x k − x k − 1 ) ( x k − x k + 1 ) ⋯ ( x k − x n ) ( x − x 0 ) ⋯ ( x − x k − 1 ) ( x − x k + 1 ) ⋯ ( x − x n )
引入记号:
ω n + 1 ( x ) = ( x − x 0 ) ( x − x 1 ) ⋯ ( x − x n ) \omega_{n+1}(x)=(x-x_{0})(x-x_{1})\cdots (x-x_{n})
ω n + 1 ( x ) = ( x − x 0 ) ( x − x 1 ) ⋯ ( x − x n )
所以:
ω n + 1 ′ ( x k ) = ( x k − x 0 ) ⋯ ( x k − x k − 1 ) ( x k − x k + 1 ) ⋯ ( x k − x n ) \omega^{'}_{n+1}(x_k)=(x_k-x_{0})\cdots (x_k-x_{k-1})(x_k-x_{k+1})\cdots (x_k-x_{n})
ω n + 1 ′ ( x k ) = ( x k − x 0 ) ⋯ ( x k − x k − 1 ) ( x k − x k + 1 ) ⋯ ( x k − x n )
于是公式(3.5)可以化简为:
L n ( x ) = ∑ k = 0 n y k ω n + 1 ( x ) ( x − x k ) ω n + 1 ′ ( x k ) (3.6) L_{n}(x)=\sum_{k=0}^{n} y_{k} \frac{\omega_{n+1}(x)}{\left(x-x_{k}\right) \omega_{n+1}^{\prime}\left(x_{k}\right)} \tag{3.6}
L n ( x ) = k = 0 ∑ n y k ( x − x k ) ω n + 1 ′ ( x k ) ω n + 1 ( x ) ( 3.6 )
老师提供的python文件
Lagrange1.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 import numpy as npimport matplotlib.pyplot as pylabfrom scipy.interpolate import lagrangefrom scipy.interpolate import splinefrom scipy.optimize import leastsqdef xianxingfenduan (xn, yn,x ): temp = -1 for i in range (1 , len (xn)): if x <= xn[i]: temp = i-1 break else : i += 1 if temp == -1 : return -100 result = (x-xn[temp+1 ])*yn[temp]/float ((xn[temp]-xn[temp+1 ])) \ + (x-xn[temp])*yn[temp+1 ]/float ((xn[temp+1 ]-xn[temp])) return result X = [i for i in range (1 ,16 )] Y = [4 ,6.4 ,8 ,8.8 ,9.22 ,9.5 ,9.7 ,9.95 ,10.2 ,10.32 ,10.42 ,10.5 ,10.55 ,10.5 ,10.6 ] x = np.linspace(1 ,15 ,2001 ) L = lagrange(X,Y) y = list (map (lambda x: L(x), x)) s = list (map (lambda x: spline(X,Y,x), x)) f = list (map (lambda x: xianxingfenduan(X,Y,x), x)) def error (p,x,y): return np.polyval(p,x)-y p0 = [1 ,1 ,1 ,1 ,1 ] para =leastsq(error, p0, args=(X,Y)) y_fitted = np.polyval(para[0 ],x) pylab.plot(X, Y, 'ro' ,label='dots' ) pylab.show() pylab.xlim(-1 ,1 ) pylab.ylim(0.8 ,1 ) pylab.plot(X, Y, 'ro' ) pylab.plot(x, y, 'b-' ) pylab.plot(x, s, 'r-' ) pylab.plot(x, f, 'g-' ) pylab.plot(x, y1, 'y-' ) pylab.show()
Lagrange.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 import numpy as npimport matplotlib.pyplot as pylabdef Lagr (X,Y,x ): ans=0.0 for i in range (len (Y)): t=Y[i] for j in range (len (Y)): if i !=j: t*=(x-X[j])/(X[i]-X[j]) ans +=t return ans X = [0 , 1 ,4 ,9 ,16 ,25 ,36 ,49 ,64 ] Y = [0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ] x = 0.3367 L = Lagr(X, Y, x) print (L)import matherr = math.sin(x)-L print (err)x = np.linspace(0 ,64 ,129 ) y = list (map (lambda x: Lagr(X, Y, x), x)) y1 = list (map (lambda x: np.sqrt(x), x)) pylab.plot(X, Y, 'ro' ) pylab.plot(x, y, 'b-' ) pylab.plot(x, y1, 'y-' ) pylab.show()
插值余项与误差估计
罗尔定理
余项定义:
R n ( x ) = f ( x ) − L n ( x ) R_n(x)=f(x)-L_n(x)
R n ( x ) = f ( x ) − L n ( x )
R n ( x ) = f ( x ) − L n ( x ) = f ( n + 1 ) ( ξ ) ( n + 1 ) ! ω n + 1 ( x ) (3.6) R_{n}(x)=f(x)-L_{n}(x)=\frac{f^{(n+1)}(\xi)}{(n+1) !} \omega_{n+1}(x) \tag{3.6}
R n ( x ) = f ( x ) − L n ( x ) = ( n + 1 )! f ( n + 1 ) ( ξ ) ω n + 1 ( x ) ( 3.6 )
牛顿插值
为何要用牛顿插值法:
拉格朗日插值与插值节点的依赖性太大,用牛顿插值法可以逐次进行插值。
将拉格朗日线性插值看作零次插值的修正 ;线性插值看作抛物插值的修正 ;…
差商(微商的离散形式。):
f [ x i , x i + 1 , ⋯ , x i + k ] = f [ x i + 1 , x i + 2 , ⋯ , x i + k ] − f [ x i , x i + 1 , ⋯ , x i + k − 1 ] x i + k − x i f\left[x_{i}, x_{i+1}, \cdots, x_{i+k}\right]=\frac{f\left[x_{i+1}, x_{i+2}, \cdots, x_{i+k}\right]-f\left[x_{i}, x_{i+1}, \cdots, x_{i+k-1}\right]}{x_{i+k}-x_{i}}
f [ x i , x i + 1 , ⋯ , x i + k ] = x i + k − x i f [ x i + 1 , x i + 2 , ⋯ , x i + k ] − f [ x i , x i + 1 , ⋯ , x i + k − 1 ]
差商的性质
k阶差商
f [ x 0 , x 1 , ⋅ ⋅ ⋅ , x k ] = ∑ j = 0 k f ( x j ) ω k + 1 ′ ( x j ) f[x_0, x_1, · · · , x_k] =\sum_{j=0}^k\frac{f(x_j)}{\omega^{'}_{k+1}(x_j)}
f [ x 0 , x 1 ,⋅⋅⋅, x k ] = j = 0 ∑ k ω k + 1 ′ ( x j ) f ( x j )
差商与其所含节点的排列次序无关,即
f [ x i , x i + 1 ] = f [ x i + 1 , x i ] f[x_i , x_{i+1}] = f[x_{i+1}, x_i]
f [ x i , x i + 1 ] = f [ x i + 1 , x i ]
设f ( x ) f(x) f ( x ) 在包含互异节点x 0 , x 1 , ⋅ ⋅ ⋅ , x n x_0, x_1, · · · , x_n x 0 , x 1 ,⋅⋅⋅, x n 的闭区间[ a , b ] [a, b] [ a , b ] 上有n阶导数,则
f [ x 0 , x 1 , ⋅ ⋅ ⋅ , x n ] = f n ( ξ ) n ! ξ ∈ ( a , b ) f[x_0, x_1, · · · , x_n] =\frac{f^{n}(\xi)}{n!}\quad \xi \in(a,b)
f [ x 0 , x 1 ,⋅⋅⋅, x n ] = n ! f n ( ξ ) ξ ∈ ( a , b )
牛顿插值
2021-10-16 12:31:19
不学了!!!我要去收拾东西,晚上再坐上32个小时的火车,去向不可知的远方。楼下母亲快把饭做好了,饿!饿!饿!
回到学校再来过!!!
P n ( 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 ) + ⋯ + f [ x 0 , x 1 , ⋯ , x n ] ( x − x 0 ) ( x − x 1 ) ⋯ ( x − x n − 1 ) R ~ n ( x ) = f [ x , x 0 , x 1 , ⋯ , x n ] ( x − x 0 ) ( x − x 1 ) ⋯ ( x − x n ) \begin{aligned}
P_{n}(x)=& f\left(x_{0}\right)+f\left[x_{0}, x_{1}\right]\left(x-x_{0}\right)+f\left[x_{0}, x_{1}, x_{2}\right]\left(x-x_{0}\right)\left(x-x_{1}\right)+\cdots \\
&+f\left[x_{0}, x_{1}, \cdots, x_{n}\right]\left(x-x_{0}\right)\left(x-x_{1}\right) \cdots\left(x-x_{n-1}\right) \\
\tilde{R}_{n}(x)=& f\left[x, x_{0}, x_{1}, \cdots, x_{n}\right]\left(x-x_{0}\right)\left(x-x_{1}\right) \cdots\left(x-x_{n}\right)
\end{aligned}
P n ( x ) = R ~ n ( 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 ) + ⋯ + f [ x 0 , x 1 , ⋯ , x n ] ( x − x 0 ) ( x − x 1 ) ⋯ ( x − x n − 1 ) f [ x , x 0 , x 1 , ⋯ , x n ] ( x − x 0 ) ( x − x 1 ) ⋯ ( x − x n )
称N n ( x ) N_n(x) N n ( x ) 为n n n 次牛顿插值多项式,R ~ n ( x ) R̃_n (x) R ~ n ( x ) 为牛顿型插值余项。
插值多项式存在且唯一:P n ( x ) ≡ L n ( x ) P_n(x)≡ L_n(x) P n ( x ) ≡ L n ( x )
差分形式
步长 :等距节点x k = x 0 + k h ( k = 0 , 1 , … , n ) x_k=x_0+kh\ (k=0,1,\dots,n) x k = x 0 + kh ( k = 0 , 1 , … , n )
称Δ f k = f k + 1 − f k \Delta f_k=f_{k+1}-f_k Δ f k = f k + 1 − f k 为一阶差分
Δ f k = f k + 1 − f k \Delta f_{k}=f_{k+1}-f_{k}
Δ f k = f k + 1 − f k
f [ x 0 , x 1 , ⋯ , x k ] = Δ k y 0 k ! h k , k = 1 , 2 , ⋯ , n f [ x n , x n − 1 , ⋯ , x n − k ] = ∇ k y n k ! h k , k = 1 , 2 , ⋯ , n \begin{aligned}
&f\left[x_{0}, x_{1}, \cdots, x_{k}\right]=\frac{\Delta^{k} y_{0}}{k ! h^{k}}, \quad k=1,2, \cdots, n \\
&f\left[x_{n}, x_{n-1}, \cdots, x_{n-k}\right]=\frac{\nabla^{k} y_{n}}{k ! h^{k}}, \quad k=1,2, \cdots, n
\end{aligned}
f [ x 0 , x 1 , ⋯ , x k ] = k ! h k Δ k y 0 , k = 1 , 2 , ⋯ , n f [ x n , x n − 1 , ⋯ , x n − k ] = k ! h k ∇ k y n , k = 1 , 2 , ⋯ , n
差分与导数的关系
Δ n y o = h n f ( n ) ( ξ ) ξ ∈ ( x 0 , x n ) \Delta^n y_o=h^nf^{(n)}(\xi)\ \xi \in (x_0,x_n)
Δ n y o = h n f ( n ) ( ξ ) ξ ∈ ( x 0 , x n )
牛顿向前插值多项式
P n ( x 0 + t h ) = f ( x 0 ) + t Δ y 0 + t ( t − 1 ) 2 ! Δ 2 y 0 + ⋯ + t ( t − 1 ) ⋯ ( t − n + 1 ) n ! Δ n y 0 P_{n}\left(x_{0}+t h\right)=f\left(x_{0}\right)+t \Delta y_{0}+\frac{t(t-1)}{2 !} \Delta^{2} y_{0}+\cdots+\frac{t(t-1) \cdots(t-n+1)}{n !} \Delta^{n} y_{0}
P n ( x 0 + t h ) = f ( x 0 ) + t Δ y 0 + 2 ! t ( t − 1 ) Δ 2 y 0 + ⋯ + n ! t ( t − 1 ) ⋯ ( t − n + 1 ) Δ n y 0
其余项为:
R n ( x 0 + t h ) = t ( t − 1 ) ⋯ ( t − n + 1 ) n ! h n + 1 f ( n + 1 ) ( ξ ) ξ ∈ ( x 0 , x n ) R_n(x_0+th)=\frac{t(t-1) \cdots(t-n+1)}{n !}h^{n+1}f^{(n+1)}(\xi)\quad\xi \in (x_0,x_n)
R n ( x 0 + t h ) = n ! t ( t − 1 ) ⋯ ( t − n + 1 ) h n + 1 f ( n + 1 ) ( ξ ) ξ ∈ ( x 0 , x n )