1
$\begingroup$

I have a function of one variable $f(x): \mathbb{R}\to \mathbb{C}$ which is very difficult to evaluate. Single evaluations may take hours, and I need to use the function at a large variety of points.

Despite its complexity, the graph of the function is very simple; it looks nearly gaussian.

Therefore I would like to just cache individual values of the function and use some kind of interpolation in between for the intermediate values. This interpolated approximation could then be evaluated at any point.

I have not found a nice function for cacheing in mathematica nor is it obvious to me what kind of interpolation would be suited for such a problem.

Maybe someone here has expertise which they could share with me on this issue?

I have already implemented the function as a "function which remembers values it has found" but this is not sufficient as I need speedy evaluation of intermediate points as well.

$\endgroup$
  • 1
    $\begingroup$ Have a look at Interpolation. The smoother your function is, the higher a InterpolationOrder you may use. $\endgroup$ – Henrik Schumacher Feb 20 at 14:01
  • 1
    $\begingroup$ data = Table[{x, f[x]}, {x, xmin, xmax}]; Then use Interpolation $\endgroup$ – Bob Hanlon Feb 20 at 15:05
  • $\begingroup$ Both very helpful thank you :) $\endgroup$ – doublefelix Feb 20 at 15:09
  • $\begingroup$ What is still missing, though, is: the best interpolation algorithm would choose the points x at which it best samples, to get a more accurate interpolation. I guess these would be points with high curvature but I don't really know. Is there such an option in mathematica? Of course I can choose the points myself and then interpolate but the result won't be as precise and unfortunately my application requires a good amount of precision $\endgroup$ – doublefelix Feb 20 at 15:25
  • $\begingroup$ The result of Interpolation is a piecewise function (InterpolatingFunction) and will go exactly through all the points. $\endgroup$ – Gustavo Delfino Feb 20 at 17:34
1
$\begingroup$

Not going to accept this answer since it's my own and I feel weird about that, but in case other people need it here it is.

Just use https://reference.wolfram.com/language/ref/FunctionInterpolation.html .

Mathematica then picks the points which are best to evaluate the function for you. No need to try to intelligently guess them. For an example function, mathematica used 177 points and the difference between the actual function and interpolated polynomial was about 10^-6 at worst.

It only works for a fixed interval. Therefore I had to come up with bounds $[a,b]$ and outside of these bounds, my function was effectively 0 for my purposes anyway.

| improve this answer | |
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.