最小二乗法 / N 次函数近似 / Wolfram, Fit[]

Wolfram の場合は Fit[] 函数で近似多項式が求まる。
構文: Fit[{{x1, y1}, {x2, y2}, ......, {xn, yn}}, {x^0, x^1, ......, x^n }, x]
返値: 多項式

xList = {1,2,3,4,5,6,7,8,9,10};
yList = {3,5,4,2,6,7,9,7,6,4};
order = 5;
xyList = Transpose[{xList, yList}]; (* {{x1, y1}, {x2, y2}, ...} に変換する *)
scatPlt = ListPlot[xyList];  (* 点列の散布図 *)
n = Table[x^n, {n, 0, order}]; 
polyEq = Fit[xyList, n, x] (* 近似多項式を求める *) 
polyPlt = Plot[polyEq, {x, 0, 11}]; (* 近似多項式のグラフ *)  
Show[polyPlt, scatPlt] (* 点列の散布図と近似多項式のグラフとを一緒に描く *)   

実行結果:
f:id:ti-nspire:20180402152734p:plain:w500