gnuplot将直线拟合到两点

gnuplot将直线拟合到两点,gnuplot,Gnuplot,考虑具有两列两行的数据文件: 3869. 1602. 3882. 9913. 我想用gnuplot安装一条线路 gnuplot> f(x) = a * x + b gnuplot> fit f(x) './data.txt' u 1:2 via a, b Iteration 0 WSSR : 3.43474e+07 delta(WSSR)/WSSR : 0 delta(WSSR) : 0 lim

考虑具有两列两行的数据文件:

  3869.    1602.  
  3882.    9913.
我想用gnuplot安装一条线路

gnuplot> f(x) = a * x + b
gnuplot> fit f(x) './data.txt' u 1:2 via a, b

Iteration 0
WSSR        : 3.43474e+07       delta(WSSR)/WSSR   : 0
delta(WSSR) : 0                 limit for stopping : 1e-05
lambda   : 2740.4

initial set of free parameter values

a               = 1.7524
b               = -1026.99
/

Iteration 1
WSSR        : 3.43474e+07       delta(WSSR)/WSSR   : -1.49847e-12
delta(WSSR) : -5.14686e-05      limit for stopping : 1e-05
lambda   : 274.04

resultant parameter values 

a               = 1.7524
b               = -1026.99

After 1 iterations the fit converged.
final sum of squares of residuals : 3.43474e+07
rel. change during last iteration : -1.49847e-12


Exactly as many data points as there are parameters.
In this degenerate case, all errors are zero by definition.

Final set of parameters 
======================= 

a               = 1.7524         
b               = -1026.99       
gnuplot>

这会为拟合参数提供错误的值。为什么会这样?我的gnuplot版本是
version4.4patchlevel0

在我看来,曲线拟合函数很难找到真正的参数。这可能与数据点的大小有关,和/或试图将带有两个参数的直线拟合到两个数据点

在任何情况下,在Excel或同等软件中计算a和b的收益率:

a= 577.769
b = -2233787
如果您让gnuplot很好地猜测它们应该是什么,例如
a=500
b=-2233700
并重复该过程,它应该成功地找到正确的解决方案:

Final set of parameters 
======================= 

a               = 577.769        
b               = -2.23379e+06   
当然,如果将两点拟合到一条双参数直线上,则手动计算
a
b
的值要容易得多:

a = (9113-1602) / (3882-3869)
b = 1602 - a * 3869

Gnuplot使用非线性方法来确定函数的参数
f
与某个错误值有关:
停止限制:1e-05

如果您更改该错误值,您的函数将完全适合。可以使用
FIT\u LIMIT
变量指定错误值,如下所示:

FIT_LIMIT = 1e-8

使用此设置,您的点将在12次迭代后完全匹配。(至少在我的机器上^^)

谢谢你的回答。你说“你的数据点的大小”是什么意思?Gnuplot首先猜测参数(a=1.75,b=-1027),如果其中一个参数不适用,然后迭代这些参数以获得真正的解决方案。在这种情况下,由于数据点(1600-9000)的相对大小(即大小),gnuplot做出的第一个猜测特别糟糕,导致fit函数失败。问题是对于
(3869,1.)
(3870,2.)
来说,它也失败了,差异更小。