问题描述
是否可以在gnuplot中绘制并拟合具有两个变量的函数?例如,取决于 h 和温度 T
的物理函数,其中 T
依赖性应该仅计算而不是作图(对于 f
, h
和 T
存在实验数据):
Is its possible in gnuplot to plot and fit a function that has two variables? For example, a physical function that depends on hight h
and Temperature T
where the T
dependence should only be calculated but not plotted (for f
, h
and T
experimental data exists):
f(h,T) = a * h * (1 + alpha * T) + f0
其中 a
和 f0
由拟合确定,已知 alpha
。最后,我需要在Y轴上使用 f
并在x轴上使用 h
的图。整个 T
依赖关系都应适当解决,但我不需要在 splot
中显示它。
where a
and f0
are to be determined by the fit, alpha
is known. In the end I need a plot with f
on the y-axis and h
on the x-axis. The whole T
dependence should be taken care of in the fit, but I don't need it displayed with splot
.
以下是我尝试并失败的内容。我假设是因为不能设置两个虚拟变量:
The following is what I tried and failed. I assume because one can't set two dummy variables:
set term png;
set output 'test.png';
set dummy h;
set dummy T;
f(h,T) = a * h * (1 + alpha * T) + f0;
fit f(h,T) 'data.txt' using 2:4:1 via a, f0;
plot f(h,T);
给出未定义变量:h
。有想法吗?
推荐答案
从文档中的示例开始:
Examples:
f(x) = a*x**2 + b*x + c
g(x,y) = a*x**2 + b*y**2 + c*x*y
FIT_LIMIT = 1e-6
fit f(x) 'measured.dat' via 'start.par'
fit f(x) 'measured.dat' using 3:($7-5) via 'start.par'
fit f(x) './data/trash.dat' using 1:2:3 via a, b, c
fit g(x,y) 'surface.dat' using 1:2:3:(1) via a, b, c
使用1:2:3:(1)拟合g(x,y)'surface.dat'
我希望您的脚本在您执行以下操作后就可以正常工作:
I would expect your script to work if you simply did:
set term png
set output 'test.png'
f(h,T) = a * h * (1 + alpha * T) + f0
fit f(x,y) 'data.txt' using 2:4:1:(1) via a, f0
set view 90,0 #possibly `set view 0,90` or `set view map`?
splot f(x,y)
这篇关于gnuplot:使用两个变量绘制并拟合二维函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!