Power curve fitting in gnuplot for redundant values

送分小仙女□ 提交于 2020-01-25 01:24:06

问题


I am trying to fit the power curve into my data with following gnuplot code.

set termoption enhanced
f(x) = a*x**b;
fit f(x) 'data.txt' via a,b
plot 'data.txt' with points title 'data points', \
f(x) with lines title sprintf('power fit curve f(x) = %.2f·x^{%.2f}', a, b)

It works fine for non-redundant data for x axis. (no repeats).

But for following type of data: It is fitting the curve only to points of first x value i.e. 1, (Starred). and not to the whole dataset.

Data:

1   2194*
1   2675*  
1   1911*  
2   966  
2   1122  
2   951  
2   1356  
3   935  
3   934  
4   851  
4   886  
4   849  
4   597  

回答1:


You must set appropriate starting values for a and b, because nonlinear fitting usually does not have one unique minimum. If you don't specify any starting values, 1 is assumed, which goes in the completely wrong direction in your case.

So, with the following script

set termoption enhanced
f(x) = a*x**b
b = -1
a = 2000
fit f(x) 'data.txt' via a,b
plot 'data.txt' with points title 'data points', \
     f(x) with lines title sprintf('power fit curve f(x) = %.2f·x^{%.2f}', a, b)

you get a proper fit:



来源:https://stackoverflow.com/questions/18712839/power-curve-fitting-in-gnuplot-for-redundant-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!