# 样条插值

## 线性样条插值

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

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

${\displaystyle 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}}$
${\displaystyle S_{i}(x_{i})=y_{i}+{\frac {y_{i+1}-y_{i}}{x_{i+1}-x_{i}}}(x-x_{i})=y_{i}}$

## 二次样条插值

${\displaystyle 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}}$

${\displaystyle z_{i+1}=-z_{i}+2{\frac {y_{i+1}-y_{i}}{x_{i+1}-x_{i}}}}$

## 三次样条插值

${\displaystyle 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.}$

• 插值特性，${\displaystyle S(x_{i})=f(x_{i})}$
• 样条相互连接，${\displaystyle S_{i-1}(x_{i})=S_{i}(x_{i}),i=1,\ldots ,n-1}$
• 两次连续可导，${\displaystyle S'_{i-1}(x_{i})=S'_{i}(x_{i})}$ 以及 ${\displaystyle S''_{i-1}(x_{i})=S''_{i}(x_{i}),i=1,\ldots ,n-1}$.

${\displaystyle S'(x_{0})=u\,\!}$
${\displaystyle S'(x_{k})=v\,\!}$

${\displaystyle S''(x_{0})=S''(x_{n})=0\,\!}$.

${\displaystyle S(x_{0})=S(x_{n})\,\!}$
${\displaystyle S'(x_{0})=S'(x_{n})\,\!}$
${\displaystyle S''(x_{0})=S''(x_{n})\,\!}$

${\displaystyle S(x_{0})=S(x_{n})\,\!}$
${\displaystyle S'(x_{0})=S'(x_{n})\,\!}$
${\displaystyle S''(x_{0})=f'(x_{0}),\quad S''(x_{n})=f'(x_{n})\,\!}$

### 三次样条的最小性

${\displaystyle J(f)=\int _{a}^{b}|f''(x)|^{2}dx}$

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

${\displaystyle 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)}$

${\displaystyle h_{i}=x_{i+1}-x_{i}\,\!}$.

${\displaystyle \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.}$

## 示例

### 线性样条插值

${\displaystyle (x_{0},f(x_{0}))=(x_{0},y_{0})=\left(-1,\ e^{-1}\right)\,\!}$
${\displaystyle (x_{1},f(x_{1}))=(x_{1},y_{1})=\left(-{\frac {1}{2}},\ e^{-{\frac {1}{4}}}\right)\,\!}$
${\displaystyle (x_{2},f(x_{2}))=(x_{2},y_{2})=\left(0,\ 1\right)\,\!}$
${\displaystyle (x_{3},f(x_{3}))=(x_{3},y_{3})=\left({\frac {1}{2}},\ e^{-{\frac {1}{4}}}\right)\,\!}$
${\displaystyle (x_{4},f(x_{4}))=(x_{4},y_{4})=\left(1,\ e^{-1}\right)\,\!}$

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

${\displaystyle 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.}$