2

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?).

Andrzej
  • 269
  • 2
  • 6
  • 1
    The domain of ifunc is stored in ifunc[[1,1]] . To change it, you, could say: ifunc[[1,1]]= {new-start,new-end} – Daniel Huber Apr 18 '21 at 16:36
  • @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} – Andrzej Apr 18 '21 at 16:53
  • Related: https://mathematica.stackexchange.com/questions/151845/taking-part-of-an-interpolatingfunction – Michael E2 Apr 18 '21 at 16:55
  • Also: https://mathematica.stackexchange.com/a/81276/4999 – Michael E2 Apr 18 '21 at 17:02
  • The structure of an InterpolatingFunction is explained here: https://mathematica.stackexchange.com/questions/28337/whats-inside-interpolatingfunction1-4 – Daniel Huber Apr 18 '21 at 19:53
  • Thanks to all of you! I knew some of the links above, but was unaware that one can simply modify the inside of InterpolationFunction like a list. It in essence answers my question. I am new here, how can I give credit for an answer given in a comment? Should I just add a full answer below, refer there to helpful comments and accept it? – Andrzej Apr 19 '21 at 08:57

0 Answers0