如何从拟合曲线中获取点数据?

时间:2018-11-29 00:27:38

标签: gnuplot curve-fitting

我通过使用gnuplot拟合一些现有点来绘制曲线。

代码如下:

f1(x)=a1/(x**b1)+c1
fit f1(x) "41a091_input.txt" u 1:2 via a1,b1,c1
plot f1(x) with line lt 1 lw 4 lc rgb "blue" notitle, \
    '41a091_input.txt' using 1:2:3 with yerrorbars lw 2.2 lc rgb "blue" title "∑41a(091)"

数据如下:

21.8124 1.11693 0.00545168
30.8669 1.07328 0.00485237 
44.6701 1.04708 0.00411839
53.6699 1.03787 0.00301346
75.9751 1.02555 0.00304312

我的问题是:

如何从曲线上的任何一点获取数据? 例如x = 50时?

1 个答案:

答案 0 :(得分:1)

好吧,您已经有了拟合函数f1(x),并且已经拟合了参数a1,b1,c1。因此,为了获得x=50处的值,只需键入print f1(50)。 或者,如果您想绘制它:

### start code
reset session

$Data <<EOD
21.8124 1.11693 0.00545168
30.8669 1.07328 0.00485237 
44.6701 1.04708 0.00411839
53.6699 1.03787 0.00301346
75.9751 1.02555 0.00304312
EOD

f1(x)=a1/(x**b1)+c1
fit f1(x) $Data u 1:2 via a1,b1,c1
print sprintf("a1: %g, b1: %g, c1: %g", a1,b1,c1)

XValue = 50
set label 1 at XValue,f1(XValue)+0.01 sprintf("f1(%g): %g",XValue,f1(XValue)) 
set arrow 1 from XValue,graph 0 to XValue,graph 1 nohead ls 0

plot f1(x) with line lt 1 lw 4 lc rgb "blue" notitle,\
 $Data using 1:2:3 with yerrorbars lw 2.2 lc rgb "blue" title "∑41a(091)",\
 [XValue:XValue] f1(XValue) w p lt 6 lc rgb "red" ps 2
### end of code

结果如下: enter image description here