I want to interpolate a function in mathematica.
The function depends on a parameter a, in fact it is the inverse of a function F which also depends on a, so I build my approximation as follows,
approx = Interpolation[Table[{F[0.1 n, a], 0.1 n}, {n, -100, 100}]]
now I can simply call approx[x] to evaluate the inverse function at a point.
Instead I would like to do something like this: Define a function which takes a parameter,
G[x_,a_] = "construct the interpolating function,
and return the value of the function at x"
Then write G[x,a] to evaluate the function. Otherwise I would have to repeat the interpolation for all the parameters I am interested in and have lots of variables lying around. I have tried putting the Interpolation[] call inside a module but that just constructs the interpolation every time I call G[x,a]! How would I avoid this?
Thanks for reading.
Try something along these lines:
You will only evaluate
Gthe first time you call it for each particular value ofa.