# 样条插值

## 定义

$x_0 < x_1 < ... < x_{n-1} < x_n, \,\!$

$S(x) := \left\{\begin{matrix} S_0(x) & x \in [x_0, x_1] \\ S_1(x) & x \in [x_1, x_2] \\ \vdots & \vdots \\ S_{n-1}(x) & x \in [x_{n-1}, x_n] \end{matrix}\right.$

## 线性样条插值

$S_i(x) = y_i + \frac{y_{i+1}-y_i}{x_{i+1}-x_i}(x-x_i)$

$S_i(x_{i+1}) = S_{i+1}(x_{i+1}) \qquad \mbox{ , } i=1,\ldots n -1$

$S_{i-1}(x_i) = y_{i-1} + \frac{y_{i}-y_{i-1}}{x_{i}-x_{i-1}}(x-x_{i-1}) = y_i$
$S_{i}(x_i) = y_i + \frac{y_{i+1}-y_i}{x_{i+1}-x_i}(x-x_i) = y_i$

## 二次样条插值

$S_i(x) = y_i + z_i(x-x_i) + \frac{z_{i+1}-z_i}{2(x_{i+1}-x_i)}(x-x_i)^2$

$z_{i+1} = -z_i + 2 \frac{y_{i+1}-y_i}{x_{i+1}-x_i}$

## 三次样条插值

$S(x)=\left\{\begin{matrix} S_0(x),\ x\in[x_0,x_1] \\ S_1(x),\ x\in[x_1,x_2]\\ \cdots \\ S_{n-1}(x),\ x\in[x_{n-1},x_n]\end{matrix}\right.$

• 插值特性，S(xi)=f(xi)
• 样条相互连接，Si-1(xi) = Si(xi), i=1,...,n-1
• 两次连续可导，S'i-1(xi) = S'i(xi)以及S''i-1(xi) = S''i(xi), i=1,...,n-1.

$S'(x_0) = u \,\!$
$S'(x_k) = v \,\!$

$S''(x_0) = S''(x_n) = 0 \,\!$.

$S(x_0) = S(x_n) \,\!$
$S'(x_0) = S'(x_n) \,\!$
$S''(x_0) = S''(x_n) \,\!$

$S(x_0) = S(x_n) \,\!$
$S'(x_0) = S'(x_n) \,\!$
$S''(x_0) = f'(x_0),\quad S''(x_n)=f'(x_n) \,\!$

### 三次样条的最小性

$J(f)=\int_a^b |f''(x)|^2 dx$

### 使用自然三次样条的插值

$S_i(x) = \frac{z_{i+1} (x-x_i)^3 + z_i (x_{i+1}-x)^3}{6h_i} + \left(\frac{y_{i+1}}{h_i} - \frac{h_i}{6} z_{i+1}\right)(x-x_i) + \left(\frac{y_{i}}{h_i} - \frac{h_i}{6} z_i\right)(x_{i+1}-x)$

$h_i = x_{i+1} - x_i \,\!$.

$\left\{\begin{matrix} z_0 = 0 \\ h_{i-1} z_{i-1} + 2(h_{i-1} + h_i) z_i + h_i z_{i+1} = 6 \left( \frac{y_{i+1}-y_i}{h_i} - \frac{y_i-y_{i-1}}{h_{i-1}} \right) \\ z_n = 0 \end{matrix}\right.$

## 示例

### 线性样条插值

$(x_0,f(x_0)) = (x_0,y_0) = \left(-1,\ e^{-1}\right) \,\!$
$(x_1,f(x_1)) = (x_1,y_1) = \left(-\frac{1}{2},\ e^{-\frac{1}{4}}\right) \,\!$
$(x_2,f(x_2)) = (x_2,y_2) = \left(0,\ 1\right) \,\!$
$(x_3,f(x_3)) = (x_3,y_3) = \left(\frac{1}{2},\ e^{-\frac{1}{4}}\right) \,\!$
$(x_4,f(x_4)) = (x_4,y_4) = \left(1,\ e^{-1}\right) \,\!$

$f(x) = e^{-x^2}$

$S(x) = \left\{\begin{matrix} e^{-1} + 2(e^{-\frac{1}{4}} - e^{-1})(x+1) & x \in [-1, -\frac{1}{2}] \\ e^{-\frac{1}{4}} + 2(1-e^{-\frac{1}{4}})(x+\frac{1}{2}) & x \in [-\frac{1}{2},0] \\ 1 + 2(e^{-\frac{1}{4}}-1)x & x \in [0,\frac{1}{2}] \\ e^{-\frac{1}{4}} + 2(e^{-1} - e^{-\frac{1}{4}})(x-\frac{1}{2}) & x \in [\frac{1}{2},1] \\ \end{matrix}\right.$