gnuplot中的功率曲线拟合获得冗余值 [英] Power curve fitting in gnuplot for redundant values

查看:93
本文介绍了gnuplot中的功率曲线拟合获得冗余值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下 gnuplot代码将幂曲线拟合到我的数据中。

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)

它对于x轴的非冗余数据很好用。 (无重复)。

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

但是对于以下类型的数据:它仅将曲线拟合到第一个x值的点,即1,( 加星标 )。而不是整个数据集。

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.

数据:

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  


推荐答案

必须为 a b设置适当的起始值,因为非线性拟合通常没有一个唯一的最小值。如果您未指定任何起始值,则会假定 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.

因此,使用以下脚本

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)

您会得到合适的身材:

这篇关于gnuplot中的功率曲线拟合获得冗余值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆