2

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
  • have you tried removing the set dummy stuff and just do fit f(x,y) 'data.txt' using 2:4:1:(1) via a,f0? Commented Feb 6, 2013 at 16:49

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

9 Comments

What does the ":(1)" mean in "using"?
It's the weight that each point should be given (e.g. for error). see help fit in gnuplot. This weights each point the same.
Ah, ok. But nevertheless. If I switch all to x and y and remove the dummy, it get the error line 5: undefined variable: y (line 5 is plot). Do I have to enable multi variable plots somewhere first? Fitting seems to works just fine (I get reasonable values), but plotting does not.
@FooBar -- Sorry, I wasn't thinking. You're plotting a function of 2 variables, so you're going to need splot instead of plot. Then instead of x and y, the variables become u and v. I've updated so hopefully it'll work now.
But splot plots a surface plot (3D), but I want to fit f(h,T), but plot only the projection on f(h) (2D). So the projection from the 3D vector (h, T, f(h,T)) on (h, 0, f(h,T)) -> (h, f(h,T)). Such that if I'd look at the 3D f(h,T) plot from the specific angle that shows only the f(h) part.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.