从 gnuplot 中获取拟合数据

Mar*_*ing 0 gnuplot octave

我经常使用 Octave 创建数据,我可以根据我的实验室结果绘制这些数据。然后将该数据与 gnuplot 中的某些函数进行拟合:

f1(x) = a * exp(-x*g);
fit f1(x) "c_1.dat" using 1:2:3 via a,g
Run Code Online (Sandbox Code Playgroud)

这将创建一个fit.log

*******************************************************************************
Tue May  8 19:13:39 2012


FIT:    data read from "e_schwach.dat" using 1:2:3
        format = x:z:s
        #datapoints = 16
function used for fitting: schwach(x)
fitted parameters initialized with current variable values



 Iteration 0
 WSSR        : 12198.7           delta(WSSR)/WSSR   : 0
 delta(WSSR) : 0                 limit for stopping : 1e-05
 lambda   : 14.2423

initial set of free parameter values

mu2             = 1
omega2          = 1
Q2              = 1

After 70 iterations the fit converged.
final sum of squares of residuals : 46.0269
rel. change during last iteration : -2.66463e-06

degrees of freedom    (FIT_NDF)                        : 13
rms of residuals      (FIT_STDFIT) = sqrt(WSSR/ndf)    : 1.88163
variance of residuals (reduced chisquare) = WSSR/ndf   : 3.54053

Final set of parameters            Asymptotic Standard Error
=======================            ==========================

mu2             = 0.120774         +/- 0.003851     (3.188%)
omega2          = 0.531482         +/- 0.0006112    (0.115%)
Q2              = 17.6593          +/- 0.7416       (4.199%)


correlation matrix of the fit parameters:

               mu2    omega2 Q2     
mu2             1.000 
omega2         -0.139  1.000 
Q2             -0.915  0.117  1.000 
Run Code Online (Sandbox Code Playgroud)

有什么方法可以将参数及其错误返回到 Octave 中?我的意思是我可以编写一个解析它的 Python 程序,但我希望避免这种情况。

更新

这个问题不再适用于我,因为我现在在实验室工作中使用 Python 和 matplotlib,并且它可以通过单个程序完成所有这些。如果其他人有同样的问题,我将这个问题保持开放。

mgi*_*son 5

我对 gnuplot-Octave 界面了解不多,但是可以让您的(解析)生活更轻松的是您可以:

set fit errorvariables
fit a*x+g via a,g
set print "fit_parameters.txt"
print a,a_err
print g,g_err
set print
Run Code Online (Sandbox Code Playgroud)

现在你的变量和它们各自的错误都在文件“fit_parameters.txt”中,不需要从 python 解析。

从文档中fit

如果 gnuplot 是使用此选项构建的,并且您使用 激活它set fit errorvariables,则每个拟合参数的错误将存储在一个与参数类似的变量中,但_err 附加。因此,误差可以用作进一步计算的输入。