close

會寫到數值微分主要是因為…之前所提到的牛頓法會需要用到

基本上,如果只是單純要跑牛頓法,可以使用Richardson's Extrapolation得到的公式,這邊就不再細講。

比較讓我感到有興趣的,當然是推廣到N階都可以應用的方法…。

幾經尋找,總算找到所謂的…Finite Difference Method

一般來說,數值微分大概都分為Forward、Backward跟Central三種方式。

個人是採用Central來實作,公式大概是這個樣子…。

$\delta _{h}^{n}\left [ f \right ]\left ( x \right )= \sum_{i=0}^{n}\left ( -1 \right )^{i}\binom{n}{i}f\left ( x+\left ( \frac{n}{2}-i \right )h \right )$

研究了一下,會發現需要使用到Pascal's triangle…。整理思緒來列虛擬碼(一樣是亂寫)…。

==================================================================

N階數值微分    演算法(Algorithm)

宣告  階數(項次) n 、i 、代入值 x 、步長 h 、function 

For i = 0 to n step 1

$function = function +\left ( -1 \right )^{i}\binom{n}{i}f\left ( x+\left ( \frac{n}{2}-i \right )h \right )
$

next

程式結束

==================================================================

先來測試一下  $\frac{\mathrm{d} }{\mathrm{d} x}\left ( sinx \right )\mid _{x=\pi}$

解析解  

再來試試  $\frac{\mathrm{d^3} }{\mathrm{d} x^3}\left ( x^4 \right )\mid _{x=5}$

解析解為 $24x=120\mid _{x=5}$ 

比較起來,都還ok啦。

上一篇提到的牛頓法程式當中,則是採用精度比較高,利用Richardson's Extrapolation改善過後的Central difference formula

${f}'\left ( x \right )=\frac{8\left [ f\left ( x_n+h \right )-f \left ( x_n-h \right )\right ]-f\left ( x_n+2h \right )+f\left ( x_n-2h \right )}{12h}$

來處理的。

嗯,大概就是這樣…,至於Pascal's triangle…,有空再說吧…。

arrow
arrow
    文章標籤
    牛頓法 微分 數值
    全站熱搜

    haruka 發表在 痞客邦 留言(0) 人氣()