Menu

#1427 pseudofile "+" crashes fit

closed-fixed
nobody
fit (6)
5
2015-03-23
2014-06-13
No

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.)

Discussion

  • Ethan Merritt

    Ethan Merritt - 2014-06-13

    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.

    --- gnuplot/src/datafile.c      2014-05-27 21:25:26.156019516 -0700
    +++ gnuplot-fix/src/datafile.c  2014-06-12 21:35:09.490070334 -0700
    @@ -5083,7 +5083,7 @@ df_generate_pseudodata()
            t = t_min + df_pseudorecord * t_step;
            if (!parametric)
                t = AXIS_DE_LOG_VALUE(x_axis, t);
    -       if (df_current_plot->sample_var)
    +       if (df_current_plot && df_current_plot->sample_var)
                Gcomplex(&(df_current_plot->sample_var->udv_value), t, 0.0);
            sprintf(line,"%g",t);
            ++df_pseudorecord;
    
     

    Last edit: Ethan Merritt 2014-06-13
  • Ethan Merritt

    Ethan Merritt - 2014-06-13
    • status: open --> closed-fixed
     
  • Karl Ratzsch

    Karl Ratzsch - 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

Log in to post a comment.