Menu

#530 iterative fitting

None
closed-invalid
nobody
None
5
2022-07-12
2022-02-23
No

I often have datasets that contain a number of curves which can be fitted with a certain function, like a time series of decay curves or something.

It'd be nice if the fit command, like plot, could iterate through such a set, saving the fit results into arrays instead of single numerical variables.

At the moment I have to define the function twice, with arrays and single variables, and loop over the fit using the latter and copy the results into the former. Very cumbersome if you want to try out different formulas.

If something like this

 f(x,i) = a[i] * exp(-x/b[i])
 fit for [i=1:16] f(x,i) filen index i using 1:2 via a, b
 plot for [i=1:16:3] f(x,i) lc i, for [i=1:16:3] fname index i using 1:2 lc i

would work, that'd save a lot of typing.

Discussion

  • Ethan Merritt

    Ethan Merritt - 2022-02-24

    Isn't that the same as

    fab(x,a,b) = a * exp(-x/b)
    f(x) = fab(x,a,b)
    
    do for [i=1:16] {
        fit f(x) filen index i using 1:2 via a,b
        a[i] = a; b[i] = b;
    }
    plot for [i=1:16:3] fab(x,a[i],b[i]) lc i, for [i=1:16:3] fname index i using 1:2 lc i
    

    saving about 1 or 2 lines of typing?
    Maybe I missed something.

     
  • Alexander Stangl

    Is there a reason why not directly like this?

    fab(x,a,b) = a * x+ b
    do for [i=1:16] {
        fit fab(x,a[i],b[i]) filen index i using 1:2 via a[i],b[i]
    }
    plot for [i=1:16] fab(x,a[i],b[i]) lc i, for [i=1:16] filen index i using 1:2 lc i 
    
     
    • Karl Ratzsch

      Karl Ratzsch - 2022-04-07

      I was somehow convinced that doesn't work. Thanks for showing otherwise!

       
  • Ethan Merritt

    Ethan Merritt - 2022-07-12
    • status: open --> closed-invalid
    • Group: -->
     

Log in to post a comment.

MongoDB Logo MongoDB