# Interpolating function as a model in Mathematica's procedures for fitting

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?

• Perhaps you can memoize the function model[A,B,C] part and define model[x_, A_, B_, C_] = model[A,B,C][x] – ssch Jun 17 '13 at 16:07
• That's exactly what I did :) Still, I miss such a feature integrated in Mathematica. – Vladimir Jun 25 '13 at 23:02
• 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? – Sjoerd Smit Jun 7 '18 at 8:45