问题
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
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);
gives undefined variable: h
. Any ideas?
回答1:
From examples in the documentation:
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
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)
来源:https://stackoverflow.com/questions/14731398/gnuplot-plot-and-fit-2d-function-with-two-variables