Is it possible to use interpolating function with parameters as a model for NonLinearModelFit (and other integrated methods for fitting)?

Similar question was already posted earlier - How do I find the best parameter to fit my data if the model is a interpolating function?. However, answer is not covering whole fitting procedure and it is based on "do it yourself" method, since the question was only about the value of best fit parameter.

Difference is that I am asking how to use (if possible) Mathemaca's methods for fitting. NonLinearModelFit finds not only best values of parameters, but also $\chi^2$, confidence regions, correlation matrix and many more things that I use. I could calculate them on my own, but I want to use some of integrated methods.

If one defines a model in the form model[x, A, B, C], which gives a real number for a set of parameter values A, B, C and a value of x, then Mathematica knows how to play with it. Instead I have a model defined as model[A, B, C], which gives, for any set of numeric values A, B and C, a pure function or a function of x on some range. Now how to explain that to Mathematica and to use NonLinearModelFit? One thing I could do is to redefine pure function model[A, B, C] to model[x, A, B, C], but that would require calculating the whole slope model[A, B, C] while taking its value at only one point x, and then repeating this procedure for every point x. This takes too long if one has big set of data points (with errors) to fit.

Is there a better idea?

  • 1
    $\begingroup$ Perhaps you can memoize the function model[A,B,C] part and define model[x_, A_, B_, C_] = model[A,B,C][x] $\endgroup$
    – ssch
    Jun 17, 2013 at 16:07
  • $\begingroup$ That's exactly what I did :) Still, I miss such a feature integrated in Mathematica. $\endgroup$
    – Vladimir
    Jun 25, 2013 at 23:02
  • 1
    $\begingroup$ Maybe you could use Once or some other form of memoization to make sure that each model function model[A, B, C] only gets evaluated once and every subsequent call is just retrieved from a lookup table? $\endgroup$ Jun 7, 2018 at 8:45


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.