3
votes

i have a gnuplot script file to fit measurement data, using this structure:

set terminal png

...some format templates...

f(x) = a + b*x + c*x**2

fit f(x) "datafile.txt" using "X":"Y" via a, b, c

...some plotting commands etc...

with this, gnuplot shows some strange behaviour:

  • when i run the script as-is, it gives me the following error:

    Undefined value during function evaluation
    "myscriptfile.gnuplot", line 5: error during fit
    
  • when i move the set terminal png line after the fit line, it runs without a hassle.

  • normally, i'm loading this at the beginning of a master script containing format templates and further data processing routines. doing this also gives me the aforementioned error message, even with the moved set terminal command.

since this is just the first part of processing my data i really need it to work from the master script... i already tried setting initial guesses, FIT_LIMIT and loading it from a gnuplot environment. i'm using gnuplot 4.6.5.

does anyone know how to solve this or how fit gets influenced by other commands? or is this some kind of bug?

edit: uploaded a stripped down version of scripts and data files to here. with the reduced data files the computed fits don't concur with the measured points, but with the complete data they do.

1
You are right, fitting shouldn't depend on the terminal. However its impossible to check whats going on without having a complete example for testing. So please make minimal example which shows your problem (only a few lines of your data file, and only the essential script parts). - Christoph
i uploaded a (not) working example, see edit at the bottom. - kwantenmechaniker
Ok, thanks. That looks quite strange. First I could reproduce this, later not... I'll have a second look later this evening to see whats going on. - Christoph
thanks. btw, if i omit the "load file" part and paste the contents directly into the master file, it works... more and more this sounds like a bug. - kwantenmechaniker

1 Answers

1
votes

I'm not sure, what the real error is, but it seems to be related to your use of using "PHEAT":"RHOT", although that should be fine.

I could reproduce your error with the following minimal setup:

A data file test.dat:

A B
1 2
2 3 
3 4

and a file test.gp:

f(x) = a*x**2 + b*x + c
fit f(x) 'test.dat' using "A":"B" via a,b,c

If I call this file with gnuplot test.gp I get the same error as you. It doesn't appear if I use using 1:2. If I paste the code in an interactive terminal, the error also appears, but only once. If I repeat only the fit command again, it works fine. I'll report this as a bug.

In the script you posted, I was also able to fix this by using using 9:8 instead of using "PHEAT":"RHOT". Additionally you must remove the first line of the data file, which can be done on-the-fly with tail, so that you can leave the using statements of the plot unchanged. So you can use:

fit rhotside(x) "< tail -n +2 testdata.txt" using 9:8 via rhot0, rhot1, rhot2
fit rcoldside(x) "< tail -n +2 testdata2.txt" using 9:8 via rcold0, rcold1, rcold2