# 有限差分法

## 由泰勒展開式的推導

${\displaystyle f(x_{0}+h)=f(x_{0})+{\frac {f'(x_{0})}{1!}}h+{\frac {f^{(2)}(x_{0})}{2!}}h^{2}+\cdots +{\frac {f^{(n)}(x_{0})}{n!}}h^{n}+R_{n}(x),}$

${\displaystyle f(x_{0}+h)=f(x_{0})+f'(x_{0})h+R_{1}(x),}$

${\displaystyle f(a+h)=f(a)+f'(a)h+R_{1}(x),}$

${\displaystyle {f(a+h) \over h}={f(a) \over h}+f'(a)+{R_{1}(x) \over h}}$

${\displaystyle f'(a)={f(a+h)-f(a) \over h}-{R_{1}(x) \over h}}$

${\displaystyle f'(a)\approx {f(a+h)-f(a) \over h}.}$

## 準確度及誤差

${\displaystyle R_{n}(x_{0}+h)={\frac {f^{(n+1)}(\xi )}{(n+1)!}}(h)^{n+1}}$ , 其中${\displaystyle x_{0}<\xi  ,

${\displaystyle f(x_{0}+ih)=f(x_{0})+f'(x_{0})ih+{\frac {f''(\xi )}{2!}}(ih)^{2},}$

${\displaystyle {\frac {f(x_{0}+ih)-f(x_{0})}{ih}}=f'(x_{0})+{\frac {f''(\xi )}{2!}}ih,}$

${\displaystyle {\frac {f(x_{0}+ih)-f(x_{0})}{ih}}=f'(x_{0})+O(h).}$

## 範例：常微分方程

${\displaystyle u'(x)=3u(x)+2.\,}$

${\displaystyle {\frac {u(x+h)-u(x)}{h}}\approx u'(x)}$

${\displaystyle u(x+h)=u(x)+h(3u(x)+2).\,}$

## 範例：熱傳導方程

${\displaystyle U_{t}=U_{xx}\,}$
${\displaystyle U(0,t)=U(1,t)=0\,}$ （邊界條件）
${\displaystyle U(x,0)=U_{0}(x)\,}$ （初始條件）

${\displaystyle u(x_{j},t_{n})=u_{j}^{n}}$

### 顯式方法

${\displaystyle {\frac {u_{j}^{n+1}-u_{j}^{n}}{k}}={\frac {u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}}{h^{2}}}.\,}$

${\displaystyle u_{j}^{n+1}=(1-2r)u_{j}^{n}+ru_{j-1}^{n}+ru_{j+1}^{n}}$

${\displaystyle \Delta u=O(k)+O(h^{2})\,}$

### 隱式方法

${\displaystyle {\frac {u_{j}^{n+1}-u_{j}^{n}}{k}}={\frac {u_{j+1}^{n+1}-2u_{j}^{n+1}+u_{j-1}^{n+1}}{h^{2}}}.\,}$

${\displaystyle (1+2r)u_{j}^{n+1}-ru_{j-1}^{n+1}-ru_{j+1}^{n+1}=u_{j}^{n}}$

${\displaystyle \Delta u=O(k)+O(h^{2})\,}$

### 克兰克－尼科尔森方法

${\displaystyle {\frac {u_{j}^{n+1}-u_{j}^{n}}{k}}={\frac {1}{2}}\left({\frac {u_{j+1}^{n+1}-2u_{j}^{n+1}+u_{j-1}^{n+1}}{h^{2}}}+{\frac {u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}}{h^{2}}}\right).\,}$

${\displaystyle (2+2r)u_{j}^{n+1}-ru_{j-1}^{n+1}-ru_{j+1}^{n+1}=(2-2r)u_{j}^{n}+ru_{j-1}^{n}+ru_{j+1}^{n}}$

${\displaystyle \Delta u=O(k^{2})+O(h^{2}).\,}$

## 參考資料

1. ^ Crank, J. The Mathematics of Diffusion. 2nd Edition, Oxford, 1975, p. 143.