1

I am using gnuplot to fit some data, however I notice that sometimes my function fails to fit. I believe this is due to an undefined value which arises due to taking the square root of a negative number. (My understanding is gnuplot fit cannot cope with complex numbers.)

I am using a loop to batch process all my datafiles, and this problem is causing the script to abort.

I don't mind it failing to fit the function - but the script should not abort as this makes the whole point of batch processing everything pointless, as it fails on data file 5 of several hundred.

I have enabled set fit quiet but this doesn't seem to stop the problem.

How can I force gnuplot to continue to try and fit the next datafile even if one fit fails?

For reference, the function I am fitting is the following: (This is not the most algebraically simple form - this form is used to avoid division by small numbers.)

f(x) = (bc) / ( [c2.0] + c[b2.0 - c**2.0]*exp(x/e) ) - where b,c,e are fit parameters

So to clarify - sometimes the fit "converges towards a fit where c is negative" which causes the bottom square root to fail to evaluate - and this breaks out of the for loop which contains the fit command - how can I stop the fit failing from breaking out of the loop?

FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
  • There is a feature-request about handling such errors, see [#382 Catch fit errors ](http://sourceforge.net/p/gnuplot/feature-requests/382/). It should work, if you do the looping outside of gnuplot, in bash or so, and call gnuplot once for each file. That makes the processing slower, but should work. – Christoph Jun 30 '15 at 07:34

0 Answers0