Based on the question is gnuplot fit influenced by terminal? on stackoverflow, I saw that fit
has troubles when used with named columns (using "A":"B"
). Consider the following example:
A data file test.dat
:
A B 1 2 2 3 3 4
and a test script 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 script with gnuplot test.gp
(version 4.6.5), I get the error
Undefined value during function evaluation "test.gp", line 2: error during fit
This error also appears in the current cvs version, but says "test.gp", line 2: unknown type in real()
.
Works for me in 4.6.5:
"fit" seems to be broken in current cvs, possibly for multiple reasons.
I get this, which is very strange:
i.e. it fails the first time and then works the second time.
Yes, I also observed that the
fit
works when called for the second time in interactive mode. It also works for me if I usef(x) = a*x + b
as fitting function. All in all quite strange.The problem with columnheaders is now fixed in CVS for 4.6, 5.0.rc2, and for the main branch (which as of today is relabeled as 5.1).
So I will close this bug, but there are clearly other problems with the CVS version of "fit" (see Bug #1466). It seems that certain commands cause it to mis-count the number of independent variables.
Last edit: Ethan Merritt 2014-08-21
That fit is badly conditioned for at least two reasons:
1) There are so few data points that it's not actually a fitting problem: it's a solve-this-system-of-equations problem. 'fit' is not really meant for that task, and it will have problems with it.
2) the actual solution in this case would be a=0, b=1, c=1. But parameters being zero is not tolerated well by 'fit' (the numerical derivative breaks down).
That is at least part of the reason why changing the function to be fitted makes a difference.
The real problem, however, appears to be that at least in the 4.6pl5 version, 'fit' wasn't properly adapted to handle column-name "using" specs: it got the count of data points wrong. NDF is actually zero here (three parameters from three datapoints), but 'fit' states it was 1. It's not a major stretch of the imagination that there's random garbage data participating in the fit, because of that.
Yes, the data was probably not choosen very well, maybe too minimal. But also using more data points, e.g. a
test.dat
withleads to the same error.
Current CVS works well for me, also using the not-so-minimal original data set.
Thanks