2013-02-06 50 views
2

它是否可能在gnuplot中绘制并拟合具有两个变量的函数?例如,一个物理功能取决于HIGHT h和温度T其中T依赖性应该只被计算而不是绘制(对于fhT实验数据存在):gnuplot:用两个变量绘制并拟合2d函数

f(h,T) = a * h * (1 + alpha * T) + f0 

其中af0是由合适的决定,alpha是已知的。最后,我需要在y轴上有f,在x轴上有h。整个T依赖应该照顾在适合,但我不需要它与splot显示。

以下是我试过的和失败的。我假设因为不能设置两个虚拟变量:

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); 

给出undefined variable: h。有任何想法吗?

+0

你试图删除了'设置dummy'的东西,只是做'配合f(x,y)'data.txt'使用2:4:1:(1)通过a,f0'? – mgilson

回答

3

从文档中的例子:

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 

我希望你的脚本工作,如果你压根儿:

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) 
+0

“:(1)”在“使用”中是什么意思? –

+0

这是每个点应该给予的权重(例如,对于错误)。请参阅gnuplot中的'help fit'。这使每个点的权重相同。 – mgilson

+0

啊,好的。但尽管如此。如果我全部切换到x和y并删除虚拟,它会得到错误'line 5:undefined variable:y'(line 5 is'plot')。我必须先启用多变量图吗?拟合似乎工作得很好(我得到合理的价值),但绘图不会。 –