2023年11月5日
#analysis
样条函数即满足一定光滑性的分段多项式。
对区间 ( − ∞ , + ∞ ) {(-\infty,+\infty)} (−∞,+∞) 的一个分割:
Δ : − ∞ < x 1 < x 2 < ⋯ < x n < + ∞ \Delta : -\infty
若分段函数 s ( x ) {s(x)} s(x) 满足条件:
则称 y = s ( x ) {y=s(x)} y=s(x) 为对应于分割 Δ { \Delta } Δ 的 m {m} m 次样条函数, x 1 , x 2 , ⋯ , x n {x_1,x_2, \cdots ,x_n } x1,x2,⋯,xn 为样条节点。
以 x 1 , x 2 , ⋯ , x n {x_1,x_2, \cdots ,x_n } x1,x2,⋯,xn 为样条节点的 m {m} m 次样条函数的全体记为:
s m ( x 1 , x 2 , ⋯ , x n ) s_m(x_1,x_2, \cdots ,x_n) sm(x1,x2,⋯,xn)
s ( x ) = { p 0 ( x ) , x ≤ x 1 p 1 ( x ) , x 1 ≤ x ≤ x 2 ⋮ p j ( x ) , x j ≤ x ≤ x j + 1 ⋮ p n ( x ) , x n ≤ x , p j ( x ) ∈ P m ( j = 0 , 1 , ⋯ , n ) s(x)= \begin{cases} p_0(x)&,x\le x_1\\ p_1(x)&,x_1\le x\le x_2\\ &\vdots \\ p_j(x)&,x_j\le x\le x_{j+1}\\ & \vdots \\ p_n(x)&,x_n\le x \end{cases} \,\,\,\,\,\,\,\,\,,\,\, p_j(x)\in P_m(j=0,1,\cdots,n ) s(x)=⎩ ⎨ ⎧p0(x)p1(x)pj(x)pn(x),x≤x1,x1≤x≤x2⋮,xj≤x≤xj+1⋮,xn≤x,pj(x)∈Pm(j=0,1,⋯,n)
对样条函数而言,若令相邻两段函数的差:
q j ( x ) = p j ( x ) − p j − 1 ( x ) ∈ P m q_j(x)=p_j(x)-p_{j-1}(x)\in P_m qj(x)=pj(x)−pj−1(x)∈Pm
⇒ q j ( i ) ( x ) = p j ( i ) ( x ) − p j − 1 ( i ) ( x ) = 0 , i = 0 , 1 , ⋯ , m − 1 \Rightarrow q_j^{(i)}(x)=p_j^{(i)}(x)-p_{j-1}^{(i)}(x)=0 \,\,,\,\, i=0,1,\cdots,m-1 ⇒qj(i)(x)=pj(i)(x)−pj−1(i)(x)=0,i=0,1,⋯,m−1
⇒ q j ( x ) = c j ( x − x j ) m , 也叫做光滑因子 \Rightarrow q_j(x)=c_j(x-x_j)^m \,\,,\,\, \text{也叫做光滑因子} ⇒qj(x)=cj(x−xj)m,也叫做光滑因子
x j {x_j} xj 是 q j ( x ) {q_j(x)} qj(x) 的 m {m} m 重根。所以如果函数是样条函数,则相邻两段函数满足:
p j ( x ) = p j − 1 ( x ) + c j ( x − x j ) m , j = 0 , 1 , ⋯ , n p_j(x)=p_{j-1}(x)+c_j(x-x_j)^m \,\,,\,\, j=0,1,\cdots,n pj(x)=pj−1(x)+cj(x−xj)m,j=0,1,⋯,n
所以s(x)是m次样条的充要条件是
p 0 ( x ) = a 0 + a 1 x + ⋯ + a m x m p n ( x ) = p 0 ( x ) + ∑ j = 1 n c j ( x − x j ) m \begin{align*} p_0(x)=&a_0+a_1x+ \cdots +a_mx^m \\ \\ p_n(x)=&p_0(x)+ \sum_{j=1}^{ n}c_j(x-x_j)^m \end{align*} p0(x)=pn(x)=a0+a1x+⋯+amxmp0(x)+j=1∑ncj(x−xj)m
为了方便表示分段信息,引进截断多项式:
( x − a ) + m = { ( x − a ) m , x ≥ a 0 , x < a (x-a)_+^m= \begin{cases} (x-a)^m &,x\ge a\\ \\ 0&,x(x−a)+m=⎩ ⎨ ⎧(x−a)m0,x≥a,x<a
显然 ( x − a ) + m {(x-a)_+^m} (x−a)+m 是 ( − ∞ , + ∞ ) {(-\infty,+\infty)} (−∞,+∞) 上 m − 1 {m-1} m−1 次连续可微函数的集合( C m − 1 ( − ∞ , + ∞ ) { \mathbb C^{m-1}(-\infty,+\infty)} Cm−1(−∞,+∞) 类的分段 m {m} m 次多项式)。
使用阶段多项式表示样条函数有:任意 s ( x ) ∈ S m ( x 1 , x 2 , ⋯ , x n ) {s(x)\in S_m(x_1,x_2, \cdots ,x_n)} s(x)∈Sm(x1,x2,⋯,xn), c j ∈ R {{c_j\in \mathbb R} } cj∈R 均可唯一地表示为:
s ( x ) = p m ( x ) + ∑ j = 1 n c j ( x − x j ) + m , − ∞ < x < + ∞ s(x)= p_m(x)+ \sum_{j=1}^{ n} c_j(x-x_j)_+^m \,\,,\,\, -\infty
样条函数的基底:
S m = span { 1 , x , ⋯ , x m , ( x − x 1 ) + m , ( x − x 2 ) + m , ⋯ , ( x − x n ) + m } S_m= \text{span} \lbrace 1,x,\cdots ,x^m,(x-x_1)_+^m,(x-x_2)_+^m,\cdots ,(x-x_n)_+^m \rbrace Sm=span{1,x,⋯,xm,(x−x1)+m,(x−x2)+m,⋯,(x−xn)+m}
dim ( S m ) = m + n + 1 \text{dim} (S_m)=m+n+1 dim(Sm)=m+n+1
[!example]-
验证分片多项式是三次样条函数
s ( x ) = { 1 − 2 x , x < − 3 28 + 25 x + 9 x 2 + x 3 , − 3 ≤ x < − 1 26 + 19 x + 3 x 2 − x 3 , − 1 ≤ x < 0 26 + 19 x + 3 x 2 , 0 ≤ x s(x)= \begin{cases} 1-2x &,x<-3\\ 28+25x+9x^2+x^3&,-3\le x<-1 \\ 26+19x+3x^2-x^3&, -1\le x<0\\ 26+19x+3x^2&,0\le x \end{cases} s(x)=⎩ ⎨ ⎧1−2x28+25x+9x2+x326+19x+3x2−x326+19x+3x2,x<−3,−3≤x<−1,−1≤x<0,0≤x
解:利用光滑因子验证。
( 28 x + 25 x + 9 x 2 + x 3 ) − ( 1 − 2 x ) = ( x + 3 ) 3 (28x+25x+9x^2+x^3)-(1-2x)=(x+3)^3 (28x+25x+9x2+x3)−(1−2x)=(x+3)3
( 26 + 19 x + 3 x 2 − x 3 ) − ( 28 + 25 x + 9 x 2 + x 3 ) = − 2 ( x + 1 ) 3 (26+19x+3x^2-x^3)-(28+25x+9x^2+x^3)=-2(x+1)^3 (26+19x+3x2−x3)−(28+25x+9x2+x3)=−2(x+1)3
( 26 + 19 x + 3 x 2 ) − ( 26 + 19 x + 3 x 2 − x 3 ) = x 3 (26+19x+3x^2)-(26+19x+3x^2-x^3)=x^3 (26+19x+3x2)−(26+19x+3x2−x3)=x3
该函数为三次样条函数。
光滑因子的零点是已知的,即为边界,光滑因子的常数项只需看等式左边最高次多项式的系数就能得到。之后把右边的多项式展开,看是不是和左边的相等就行。
设给定节点 a = x 0 < x 1 < ⋯ < x n = b {a=x_0
f ( x i ) = y i , i = 0 , 1 , ⋯ , n f(x_i)=y_i \,\,,\,\, i=0,1,\cdots,n f(xi)=yi,i=0,1,⋯,n
节点是中间的点!头尾点不是!三次样条问题就是构造 s ( x ) ∈ S 3 ( x 1 , x 2 , ⋯ , x n − 1 ) {s(x)\in S_3(x_1,x_2,\cdots ,x_{n-1})} s(x)∈S3(x1,x2,⋯,xn−1) 满足插值条件
s ( x i ) = y i , i = 0 , 1 , ⋯ , n s(x_i)=y_i \,\,,\,\, i=0,1,\cdots,n s(xi)=yi,i=0,1,⋯,n
且有一定光滑性。
边界条件分类
对 [ a , b ] {[a,b]} [a,b] 进行 n {n} n 等分 时候的情况
s ( x ) = ∑ j = 0 n + 2 c j Ω 3 ( x − x j − 1 h ) , a ≤ x ≤ b , h = b − a n s(x)= \sum_{j=0}^{ n+2}c_j \Omega_3(\frac{x-x_{j-1}}{h}) \,\,,\,\, a\le x\le b \,\,,\,\, h= \frac{b-a}{n} s(x)=j=0∑n+2cjΩ3(hx−xj−1),a≤x≤b,h=nb−a
其中B样条函数
$$
\Omega_3 (y)= \begin{cases}
0 &, |y|\ge2 \\
\frac{1}{2}|y|3-y2+ \frac{2}{3}&,|y|\le1 \ \
对第一种边界条件,有三对角矩阵方程组:
[ 4 1 0 ⋯ 0 1 4 1 ⋯ 0 ⋮ ⋱ ⋱ ⋱ ⋮ 0 ⋯ 1 4 1 0 ⋯ 0 1 4 ] [ c 2 c 3 ⋮ c n − 1 c n ] = [ 6 y 1 − y 0 + h 2 6 y 0 ′ ′ 6 y 2 6 y 3 ⋮ 6 y n − 1 6 y n − 1 − y n + h 2 6 y n ′ ′ ] \begin{bmatrix} 4 & 1 & 0 & \cdots & 0 \\ 1 & 4 & 1 & \cdots & 0 \\ \vdots & \ddots & \ddots & \ddots & \vdots \\ 0 & \cdots & 1 & 4 & 1 \\ 0 & \cdots & 0 & 1 & 4 \end{bmatrix}\begin{bmatrix} c_2 \\c_3\\ \vdots \\c_{n-1}\\c_n \end{bmatrix}= \begin{bmatrix} 6y_1-y_0+ \frac{h^2}{6}y_0''\\ 6y_2\\ 6y_3 \\ \vdots \\6y_{n-1}\\6y_{n-1}-y_n+ \frac{h^2}{6}y_n'' \end{bmatrix} 41⋮0014⋱⋯⋯01⋱10⋯⋯⋱4100⋮14 c2c3⋮cn−1cn = 6y1−y0+6h2y0′′6y26y3⋮6yn−16yn−1−yn+6h2yn′′
{ c 0 = 2 c 1 − c 2 + h 2 y 0 ′ ′ c 1 = y 0 − h 2 6 y 0 ′ ′ c n + 1 = y n − h 2 6 y n ′ ′ c n + 2 = 6 c n − 1 − c n + h 2 y n ′ ′ \begin{cases} c_0=2c_1-c_2+h^2y_0'' \\ \\ c_1=y_0- \frac{h^2}{6}y_0'' \\ \\ c_{n+1}=y_n- \frac{h^2}{6}y_n''\\ \\ c_{n+2}=6c_{n-1}-c_n+ h^2y_n'' \end{cases} ⎩ ⎨ ⎧c0=2c1−c2+h2y0′′c1=y0−6h2y0′′cn+1=yn−6h2yn′′cn+2=6cn−1−cn+h2yn′′
求出所有式子后带入B样条为基底的样条函数就得到了样条插值函数。
[ 4 2 0 ⋯ 0 1 4 1 ⋯ 0 ⋮ ⋱ ⋱ ⋱ ⋮ 0 ⋯ 1 4 1 0 ⋯ 0 2 4 ] [ c 1 c 2 ⋮ c n c n + 1 ] = [ 6 y 0 + 2 h y 0 ′ 6 y 1 6 y 2 ⋮ 6 y n − 1 6 y n − 2 h y n ] \begin{bmatrix} 4 & 2 & 0 & \cdots & 0 \\ 1 & 4 & 1 & \cdots & 0 \\ \vdots & \ddots & \ddots & \ddots & \vdots \\ 0 & \cdots & 1 & 4 & 1 \\ 0 & \cdots & 0 & 2 & 4 \end{bmatrix}\begin{bmatrix} c_1 \\ c_2\\ \vdots \\c_{n}\\c_{n+1} \end{bmatrix}= \begin{bmatrix} 6y_0+ 2hy_0'\\ 6y_1\\ 6y_2 \\ \vdots \\6y_{n-1}\\6y_{n}-2hy_n \end{bmatrix} 41⋮0024⋱⋯⋯01⋱10⋯⋯⋱4200⋮14 c1c2⋮cncn+1 = 6y0+2hy0′6y16y2⋮6yn−16yn−2hyn
{ c 0 = c 2 − 2 h y 0 ′ c n + 2 = c n + 2 h y n ′ \begin{cases} c_0=c_2-2hy_0' \\ \\ c_{n+2}=c_n+2hy_n' \end{cases} ⎩ ⎨ ⎧c0=c2−2hy0′cn+2=cn+2hyn′
[ 4 1 0 ⋯ 1 1 4 1 ⋯ 0 ⋮ ⋱ ⋱ ⋱ ⋮ 0 ⋯ 1 4 1 1 ⋯ 0 1 4 ] [ c 2 c 3 ⋮ c n c n + 1 ] = [ 6 y 1 6 y 2 6 y 3 ⋮ 6 y n − 1 6 y n ] \begin{bmatrix} 4 & 1 & 0 & \cdots & 1 \\ 1 & 4 & 1 & \cdots & 0 \\ \vdots & \ddots & \ddots & \ddots & \vdots \\ 0 & \cdots & 1 & 4 & 1 \\ 1 & \cdots & 0 & 1 & 4 \end{bmatrix}\begin{bmatrix} c_2 \\c_3\\ \vdots \\c_{n}\\c_{n+1} \end{bmatrix}= \begin{bmatrix} 6y_1\\ 6y_2\\ 6y_3 \\ \vdots \\6y_{n-1}\\6y_{n} \end{bmatrix} 41⋮0114⋱⋯⋯01⋱10⋯⋯⋱4110⋮14 c2c3⋮cncn+1 = 6y16y26y3⋮6yn−16yn
{ c n + 2 = c 2 c 1 = c n + 1 c 0 = c n \begin{cases} c_{n+2}=c_2 \\ \\ c_1=c_{n+1} \\ \\ c_0=c_n \end{cases} ⎩ ⎨ ⎧cn+2=c2c1=cn+1c0=cn
[!example]-
x ∣ ∣ x 0 = 1 ∣ x 1 = 2 ∣ x 2 = 3 ∣ = = = = = = = = f ( x ) ∣ ∣ 2 ∣ 4 ∣ 8 ∣ − − − − − − − − f ′ ( x ) ∣ ∣ 1.3863 ∣ ∣ 5.5452 ∣ \begin{array}{cccccc} x&||& x_0=1 &|& x_1=2 &|& x_2=3 &| \\=&=&=&=&=&=&=&= \\ f(x) &||& 2 &|& 4 &|& 8 &| \\ -&-&-&-&-&-&-&- \\ f'(x) &||& 1.3863 &|& &|& 5.5452 &| \end{array} x=f(x)−f′(x)∣∣=∣∣−∣∣x0=1=2−1.3863∣=∣−∣x1=2=4−∣=∣−∣x2=3=8−5.5452∣=∣−∣
求三次样条插值函数。使其满足 s ( x i ) = f ( x i ) , s ′ ( x 0 ) = f ′ ( x 0 ) , s ′ ( x 2 ) = f ′ ( x 2 ) {s(x_i)=f(x_i) \,\,,\,\, s'(x_0)=f'(x_0) \,\,,\,\, s'(x_2)=f'(x_2)} s(xi)=f(xi),s′(x0)=f′(x0),s′(x2)=f′(x2) 。
解:边界条件二,区间上被分成两段, n = 2 {n=2} n=2
[ 4 2 0 1 4 1 0 2 4 ] [ c 1 c 2 c 3 ] = [ 6 y 0 + 2 h y 0 ′ 6 y 1 6 y 2 − 2 h y 2 ′ ] = [ 14.7726 24 36.9096 ] \begin{bmatrix} 4 & 2 & 0 \\ 1 & 4 & 1 \\ 0 & 2 & 4 \end{bmatrix}\begin{bmatrix} c_1\\c_2\\c_3 \end{bmatrix}= \begin{bmatrix} 6y_0+2hy_0'\\6y_1\\6y_2-2hy_2' \end{bmatrix}= \begin{bmatrix} 14.7726\\24\\36.9096 \end{bmatrix} 410242014 c1c2c3 = 6y0+2hy0′6y16y2−2hy2′ = 14.77262436.9096
[ c 1 c 2 c 3 ] = [ 1.84657 3.69317 7.38081 ] \begin{bmatrix} c_1\\c_2\\c_3 \end{bmatrix}= \begin{bmatrix} 1.84657\\3.69317\\7.38081 \end{bmatrix} c1c2c3 = 1.846573.693177.38081 c 0 = c 2 − 2 h y 0 ′ = 0.92057 c_0=c_2-2hy_0'=0.92057 c0=c2−2hy0′=0.92057
c 4 = c 2 + 2 h y 2 ′ = 14.7836 c_4=c_2+2hy_2'=14.7836 c4=c2+2hy2′=14.7836
∴ s ( x ) = 0.92057 Ω 3 ( x − 0 ) + 1.84657 Ω 3 ( x − 1 ) + 3.69317 Ω 3 ( x − 2 ) + 7.38081 Ω 3 ( x − 3 ) + 14.7836 Ω 3 ( x − 4 ) 1 ≤ x ≤ 3 \begin{align*} \therefore s(x)=&0.92057\Omega_3(x-0)+1.84657\Omega_3(x-1)\\ &+3.69317\Omega_3(x-2)+7.38081\Omega_3(x-3)+14.7836\Omega_3(x-4)\\ &1\le x\le 3 \end{align*} ∴s(x)=0.92057Ω3(x−0)+1.84657Ω3(x−1)+3.69317Ω3(x−2)+7.38081Ω3(x−3)+14.7836Ω3(x−4)1≤x≤3
用于 区间长度 h {h} h 不一致的情况
s ( x ) = M i − 1 6 h i ( x i − x ) 3 + M i 6 h i ( x − x i − 1 ) 3 + ( y i − 1 h i − M i − 1 6 h i ) ( x i − x ) + ( y i h i − M i 6 h i ) ( x − x i ) x i − 1 ≤ x ≤ x i , i = 1 , 2 , ⋯ , n \begin{align*} s(x)=& \frac{M_{i-1}}{6h_i}(x_i-x)^3+ \frac{M_i}{6h_i}(x-x_{i-1})^3\\&+(\frac{y_{i-1}}{h_i}- \frac{M_{i-1}}{6}h_i)(x_i-x)+(\frac{y_i}{h_i}- \frac{M_i}{6}h_i)(x-x_i)\\ &x_{i-1}\le x\le x_i \,\,,\,\, i=1,2, \cdots ,n \end{align*} s(x)=6hiMi−1(xi−x)3+6hiMi(x−xi−1)3+(hiyi−1−6Mi−1hi)(xi−x)+(hiyi−6Mihi)(x−xi)xi−1≤x≤xi,i=1,2,⋯,n
关键在求M。三弯矩方程
r i M i − 1 + 2 M i + α i M i + 1 = β i , i = 1 , 2 , ⋯ , n − 1 r_iM_{i-1}+2M_i+ \alpha_iM_{i+1}= \beta_i \,\,,\,\, i=1,2,\cdots ,n-1 riMi−1+2Mi+αiMi+1=βi,i=1,2,⋯,n−1
α i = h i + 1 h i + h i + 1 , r i = 1 − α i \alpha_i= \frac{h_{i+1}}{h_i+h_{i+1}} \,\,,\,\, r_i=1- \alpha_i αi=hi+hi+1hi+1,ri=1−αi
β i = 6 h i + h i + 1 ( y i + 1 − y i h i + 1 − y i − y i − 1 h i ) \beta_i= \frac{6}{h_i+h_{i+1}} \bigg( \frac{y_{i+1}-y_i}{h_{i+1}}- \frac{y_i-y_{i-1}}{h_i} \bigg) βi=hi+hi+16(hi+1yi+1−yi−hiyi−yi−1)
可以求得
α 1 ⋯ α n − 1 , r 1 ⋯ r n − 1 , β 1 ⋯ β n − 1 \alpha_1 \cdots \alpha_{n-1} \,\,,\,\, r_1 \cdots r_{n-1} \,\,,\,\, \beta_1 \cdots \beta_{n-1} α1⋯αn−1,r1⋯rn−1,β1⋯βn−1
α 0 = 0 , β 0 = 2 y 0 ′ ′ , r n = 0 , β n = 2 y n ′ ′ \alpha_0=0 \,\,,\,\, \beta_0=2y_0'' \,\,,\,\, r_n=0 \,\,,\,\, \beta_n=2y_n'' α0=0,β0=2y0′′,rn=0,βn=2yn′′
[ 2 α 0 r 1 2 α 1 ⋱ r n − 1 2 α n − 1 r n 2 ] [ M 0 M 1 ⋮ M n − 1 M n ] = [ β 0 β 1 ⋮ β n − 1 β n ] \begin{bmatrix} 2 & \alpha_0 & & & \\ r_1 & 2 & \alpha_1 & & \\ & & \ddots & & \\ & & r_{n-1} & 2 & \alpha_{n-1} \\ & & & r_n & 2 \end{bmatrix}\begin{bmatrix} M_0\\M_1\\ \vdots \\M_{n-1}\\ M_n \end{bmatrix}= \begin{bmatrix} \beta_0\\ \beta_1\\ \vdots \\ \beta_{n-1}\\ \beta_n \end{bmatrix} 2r1α02α1⋱rn−12rnαn−12 M0M1⋮Mn−1Mn = β0β1⋮βn−1βn
可得 M 0 , M 1 , ⋯ , M n {M_0,M_1, \cdots , M_n} M0,M1,⋯,Mn 。
α 0 = 1 , r n = 1 \alpha_0=1 \,\,,\,\, r_n=1 α0=1,rn=1
β 0 = 6 h 1 ( y 1 − y 0 h 1 − y 0 ′ ) , β n = 6 h n ( y n ′ − y n − y n − 1 h n ) \beta_0= \frac{6}{h_1}(\frac{y_1-y_0}{h_1}-y_0') \,\,,\,\, \beta_n= \frac{6}{h_n} (y_n'-\frac{y_n-y_{n-1}}{h_n}) β0=h16(h1y1−y0−y0′),βn=hn6(yn′−hnyn−yn−1)
代入的矩阵式子和第一种边界条件的式子相同。求得 M 0 {M_0} M0 到 M n {M_n} Mn 。
M 0 = M n , α n = h 1 h 1 + h n , r n = 1 − α n M_0=M_n \,\,,\,\, \alpha_n= \frac{h_1}{h_1+h_n} \,\,,\,\, r_n=1- \alpha_n M0=Mn,αn=h1+hnh1,rn=1−αn
β n = 6 h 1 + h n ( y 1 − y 0 h 1 − y n − y n − 1 h n ) \beta_n = \frac{6}{h_1+h_n}(\frac{y_1-y_0}{h_1}- \frac{y_n-y_{n-1}}{h_n}) βn=h1+hn6(h1y1−y0−hnyn−yn−1)
[ 2 α 1 r 1 r 2 2 α 2 ⋱ r n − 1 2 α n − 1 α n r n 2 ] [ M 1 M 1 ⋮ M n − 1 M n ] = [ β 1 β 1 ⋮ β n − 1 β n ] \begin{bmatrix} 2 & \alpha_1 & & & r_1 \\ r_2 & 2 & \alpha_2 & & \\ & & \ddots & & \\ & & r_{n-1} & 2 & \alpha_{n-1} \\ \alpha_n & & & r_n & 2 \end{bmatrix}\begin{bmatrix} M_1\\M_1\\ \vdots \\M_{n-1}\\ M_n \end{bmatrix}= \begin{bmatrix} \beta_1\\ \beta_1\\ \vdots \\ \beta_{n-1}\\ \beta_n \end{bmatrix} 2r2αnα12α2⋱rn−12rnr1αn−12 M1M1⋮Mn−1Mn = β1β1⋮βn−1βn