I´m (ab)using fit to find the nearest root of a function, e.g.
f=1. fit f - 2 "-" us 1:(0) via f 1 2 e
returns f=2
Now i was lazy and tired of using the "-" pseudofile and thought i could as well use "+"
fit f - 2 "+" us 1:(0) via f
but this just hangs gnuplot (recent gp5 build on win7) without warning or errormessage.
(i´m currently using this
$zero << EOD 0 0 1 0 EOD fit f-2 $zero via f
, works very well. only trouble is i have to re-define functions to not contain "x", or change the name of the independent variable each time. would be great to have some "fzero" command like octave/matlab has.)
Heh. Amazing what clever misuses are possible, and how many bugs they uncover.
The following patch avoids a segfault from an uninitialized pointer df_current_plot if you manage to enter the '+' data generation routine from 'fit' rather than from 'plot'. I have no idea whether that results in valid calculation.
Last edit: Ethan Merritt 2014-06-13
Many thanks for the amazingly fast fix!
My method has of course the drawback of returning the closest minimum instead of root should that be nearer. So you have to check for FIT_STDFIT to be zero afterwards.
I´ll check for a clever algorithm for an "fzero" function and set up a feature request for it if i find one.
Last edit: Karl Ratzsch 2014-06-13