When dealing with a slow function (e.g., a numerical integration) it is sometimes useful to tabulate it and create an interpolation function to work with instead. I found that one can deal with a possible extrapolation issues with "ExtrapolationHandler", e.g.,

FInterpolation[f_] := 
 Interpolation[{#, f[#]} & /@ Range[0., 10., 0.1], 
  "ExtrapolationHandler" -> {f[#] &, "WarningMessage" -> False}]

will return an InterpolationFunction object that will use function f outside of the interpolation domain. But as far as I can see there is no similar functionality when using FunctionInterpolation instead. Naively I'd expect that as the latter returns an InterpolationFunction object as well, it should be possible to use

ifunc = FunctionInterpolation[f[x], {x, 0., 10.}]

and then modify the "ExtrapolationHandler" inside ifunc. Can one do that somehow?

My workaround was to use

FInterpolationExt[func_, domain_] := Module[{ifunc},
  ifunc = FunctionInterpolation[func[x], {x, domain[[1]], domain[[2]]}];
    If[domain[[1]] <= # <= domain[[2]], ifunc[#], func[#] ] & ]

which however does not return a simple InterpolationFunction (and perhaps is not optimal?).

  • 1
    $\begingroup$ The domain of ifunc is stored in ifunc[[1,1]] . To change it, you, could say: ifunc[[1,1]]= {new-start,new-end} $\endgroup$ Commented Apr 18, 2021 at 16:36
  • $\begingroup$ @DanielHuber Thanks, didn't know you can do that! So, by analogy to change the ExtrapolationHandler I can use: ifunc[[2, 10]] = f[#] & -- is there a way of adding "WarningMessage" -> False as well? It does not work this way: ifunc[[2, 10]] = {f[#] &, "WarningMessage" -> False} $\endgroup$
    – Andrzej
    Commented Apr 18, 2021 at 16:53
  • $\begingroup$ Related: mathematica.stackexchange.com/questions/151845/… $\endgroup$
    – Michael E2
    Commented Apr 18, 2021 at 16:55
  • $\begingroup$ Also: mathematica.stackexchange.com/a/81276/4999 $\endgroup$
    – Michael E2
    Commented Apr 18, 2021 at 17:02
  • $\begingroup$ Check out the interpolation-tag wiki $\endgroup$
    – Chris K
    Commented Apr 18, 2021 at 17:38


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.