データファイルとスクリプトファイル(dataline.gnp)を作成して、 グラフを描かせる方法を紹介します.
# X Y 1.3 2.52 2.00 3.85 3.31 7.78 4.03 9.91 5.70 12.73 6.20 12.40 7.00 14.30 8.00 16.95 9.20 18.91 10.00 19.01 6.00 11.51 2.03 4.93 3.55 8.00 1.00 2.92 4.00 8.00 5.00 10.03 9.50 20.54 8.00 15.22 7.00 15.03 9.33 17.89 5.00 12.10
plot[0:11][0:25] 'sample2.dat' using 1:2 with lines title 'simple line',\ '' using 1:2 with points pt 6 title 'data'
plot 'sample2.dat'using 1:2 smooth unique with lines title 'simple line',\ '' using 1:2 with points pt 6 title 'data'
plot 'sample2.dat' using 1:2 with lines smooth sbezier ,\ '' every ::1 using 1:2 with points pt 6 title 'data'
plot 'sample2.dat' using 1:2 smooth csplines with lines title 'csplines',\ '' every ::1 using 1:2 with points pt 6 title 'data'
plot 'sample2.dat' using 1:2 smooth acsplines with lines title 'acsplines',\ '' every ::1 using 1:2 with points pt 6 title 'data'
plot 'sample2.dat' using 1:2 smooth mcsplines with lines title 'mcsplines',\ '' every ::1 using 1:2 with points pt 6 title 'data'
fit コマンドを使えば, "Y=aX+b" や "Y=aX**2 + bX + c"(X**2はXの二乗) や "Y=a exp(bX)"などの関数について, 最小二乗法を用いたフィッティングカーブが得られます.(ここで a,b,cは定数)
今回用いたスクリプトは次のとおりで, データ点(sample2.dat)にフィットするようにf(x) の a と b を 最適化します.
f(x) = a * x + b fit f(x) 'sample2.dat' using 1:2 via a, b plot[0:11][0:25] '' using 1:2 with points pt 6 title 'data',\ f(x) with lines linetype 1 title 'least square'
iter chisq delta/lim lambda a b 0 6.8815820000e+02 0.00e+00 4.45e+00 1.000000e+00 1.000000e+00 1 1.5085099019e+01 -4.46e+06 4.45e-01 1.876607e+00 1.090284e+00 2 1.4586933325e+01 -3.42e+03 4.45e-02 1.922179e+00 9.228549e-01 3 1.4586642200e+01 -2.00e+00 4.45e-03 1.923407e+00 9.144212e-01 4 1.4586642200e+01 -4.89e-07 4.45e-04 1.923408e+00 9.144170e-01 iter chisq delta/lim lambda a b After 4 iterations the fit converged. final sum of squares of residuals : 14.5866 rel. change during last iteration : -4.88678e-12 degrees of freedom (FIT_NDF) : 19 rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 0.876195 variance of residuals (reduced chisquare) = WSSR/ndf : 0.767718 Final set of parameters Asymptotic Standard Error ======================= ========================== a = 1.92341 +/- 0.06972 (3.625%) b = 0.914417 +/- 0.4334 (47.39%) correlation matrix of the fit parameters: a b a 1.000 b -0.897 1.000ここで, "Final set of parameters" は定数 a と b の解析結果(最良値)で, "Asymptotic Standard Error" は求めたa,bの標準誤差となります.