gnuplot / misc (2)
not so FAQ
|
その他もろもろ (その2)非線形関数を使った最小自乗フィッティングの方法(その1). gnuplot3.7の強力な機能の一つに,関数のフィッティング(当てはめ)があり サンプルのデータとして,a=2, b=1 の値をこの関数に与えて -10.000000 0.019802 -8.947370 0.024674 -7.894740 0.031582 -6.842110 0.041828 -5.789470 0.057941 -4.736840 0.085333 -3.684210 0.137236 -2.631580 0.252359 -1.578950 0.572561 -0.526316 1.566160 0.526316 1.566160 1.578950 0.572561 2.631580 0.252359 3.684210 0.137236 4.736840 0.085333 5.789470 0.057941 6.842110 0.041828 7.894740 0.031582 8.947370 0.024674 10.000000 0.019802 この数値を,”exp.dat” という名前のファイルに保存しておきます.最初 フィットを行うデータファイルに対しては,using, gnuplot> f(x)=a/(1+b*x*x) gnuplot> fit f(x) "exp.dat" via a,b Iteration 0 WSSR : 1.43879 delta(WSSR)/WSSR : 0 delta(WSSR) : 0 limit for stopping : 1e-05 lambda : 0.201184 ....... Final set of parameters Asymptotic Standard Error ======================= ========================== a = 2 +/- 5.236e-07 (2.618e-05%) b = 0.999998 +/- 7.397e-07 (7.397e-05%) correlation matrix of the fit parameters: a b a 1.000 b 0.837 1.000 途中,フィッティングのログが長々と画面を流れて行きます.同じ内容が, 得られた数値は,変数a,bに入っていますので,関数f(x)をデータと gnuplot> plot f(x) with lines, "exp.dat" using 1:2 w points ![]() 非線形関数を使った最小自乗フィッティングの方法(その2). 次はもう少し具体的な例を用います.次のような実験データがあります.こ # X Y Z 6.295 8.4 0.3 6.795 23.9 0.7 7.826 104.0 3.0 8.830 255.0 8.0 9.841 421.0 13.0 10.860 566.0 18.0 11.864 690.0 22.0 各データ点の重みは,誤差の値をZとすると,1/Z*Zとなります.従って誤 まず,実験値だけをプロットしてその傾向を見ます. gnuplot> set log y gnuplot> plot "exp.dat" using 1:2:3 w yerrorbars ![]() 次に変数a,b,cの初期値を決めます.gnuplotのフィッティングでは, gnuplot> a=6 gnuplot> b=1 gnuplot> c=10 gnuplot> f(x)=c*(x-a)**b gnuplot> fit f(x) "exp.dat" using 1:2:3 via a,b,c 17回の反復の後に計算が収束したメッセージが出,最終的なパラメータの値 After 17 iterations the fit converged. final sum of squares of residuals : 90.8196 rel. change during last iteration : -9.71916e-09 degrees of freedom (ndf) : 4 rms of residuals (stdfit) = sqrt(WSSR/ndf) : 4.76497 variance of residuals (reduced chisquare) = WSSR/ndf : 22.7049 Final set of parameters Asymptotic Standard Error ======================= ========================== a = 5.76731 +/- 0.176 (3.051%) b = 1.89369 +/- 0.2127 (11.23%) c = 25.7956 +/- 9.807 (38.02%) correlation matrix of the fit parameters: a b c a 1.000 b -0.944 1.000 c 0.975 -0.975 1.000 この結果を,先程のプロットに重ねて表示します. gnuplot> plot f(x),"exp.dat" using 1:2:3 w yerrorbars ![]() |