gpt4 book ai didi

plot - 将函数拟合到用 gnuplot 中的频率创建的直方图

转载 作者:行者123 更新时间:2023-12-01 22:37:23 25 4
gpt4 key购买 nike

简介

在 gnuplot 中,有一个解决方案可以从名为 hist.dat 的文件创建直方图

1
2
2
2
3

通过使用命令

binwidth=1
set boxwidth binwidth
bin(x,width)=width*floor(x/width) + binwidth/2.0
plot [0:5][0:*] "hist.dat" u (bin($1,binwidth)):(1.0) smooth freq with boxes

生成直方图like this one from other SO page .

问题

如何将我的函数拟合到该直方图?我定义了一个高斯函数并通过以下方式初始化了它的值

f(x) = a*exp(-((x-m)/s)**2)
a=3; m=2.5; s=1

在输出中,函数很好地遵循直方图。

不幸的是,我无法使用命令拟合该直方图

fit f(x) "hist.dat" u (bin($1,binwidth)):(1.0) smooth freq via a,m,s  
^
Need via and either parameter list or file

那么如何在不创建包含分箱值的新文件的情况下适应我的函数?

最佳答案

我面临着类似的问题,我找到了一种不太优雅的解决方案。

binwidth=1
set boxwidth binwidth
bin(x,width)=width*floor(x/width) + binwidth/2.0
set table 'hist.temp'
plot [0:5][0:*] "hist.dat" u (bin($1,binwidth)):(1.0) smooth freq with boxes
unset table

然后您可以根据需要调整文件。我知道可能有一些更好的方法可以做到这一点,但对我来说这是一个快速且有效的解决方案。我希望这对您有帮助。

干杯!

关于plot - 将函数拟合到用 gnuplot 中的频率创建的直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14305994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com