60

I'm curious what's inside the InterpolationFunction object?

For example:

InputForm[Interpolation[{1., 2., 3., 4.}]]
(*
  InterpolatingFunction[
    {{1., 4.}}, 
    {4, 7, 0, {4}, {4}, 0, 0, 0, 0, Automatic}, 
    {{1., 2., 3., 4.}},{Developer`PackedArrayForm, {0, 1, 2, 3, 4}, {1., 2., 3., 4.}}, 
    {Automatic}]
*)

What do those arguments mean?

user21
  • 39,710
  • 8
  • 110
  • 167
xslittlegrass
  • 27,549
  • 9
  • 97
  • 186

1 Answers1

65

From inspection, some investigation and ruebenko's help, what I've found so far is that InterpolatingFunction has the following underlying structure:

InterpolatingFunction[
    domain,                    (* or min/max of grid for each dimension          *)
    List[
        version,               (* 3 in Mathematica 7, 4 from 8 onwards           *)
        bitField,              (* 3 for exact/arbitrary precision
                                  7 for machine numbers, 15 for machine complex,
                                  39 for spline, 4259 for FEM elements. These are 
                                  for version 4, and are different for version 3.*)
        dataDerivatives,       (* Max order of derivatives supplied for input    *)
        domainGridSize,        (* or input sample points in each dimension       *)
        interpolationOrder,    (* actually, order + 1; for each dimension        *)
        nthDerivativeOfIntFun, (* Denotes if the current InterpolatingFunction is 
                                  an nth derivative of an existing Int. Func. and
                                  0 otherwise.                                   *)
        periodicInterpolation, (* 0 for False and {1} for True                   *)
        0, 0,                  (* One of the zeros is a permutation flag for 
                                  time-dependent InterpolatingFunction           *)
        Automatic              (* Extrapolation handler                          *)
    ],

    basicInterpolatingUnit,    (* This is setup such that it agrees with the input
                                   values at the input grid points. You might see 
                                  structures with Developer`PackedArrayForm for 
                                  2D Hermite, BSplineFunction for 2D Spline
                                  NDSolve`FEM`ElementMesh for 3D, or nothing.    *)
    Automatic                  (* Unknown                                        *)
]

You can access most of this internal data using the following arguments to any InterpolatingFunction object:

{"Domain", "Coordinates", "Grid", "ValuesOnGrid", "InterpolationOrder", "DerivativeOrder"}

See the contents of the following package for more information on what exactly the above arguments return:

SystemOpen@FindFile["DifferentialEquations`InterpolatingFunctionAnatomy`"]
rm -rf
  • 88,781
  • 21
  • 293
  • 472
  • 10
    a few more: The fist unknown is the version. The typeInfo is bit field. The first Automatic is an extrapolation handler. One of the zeros before is a permutation flag for time dependent if. –  Jul 10 '13 at 09:34
  • @ruebenko Thanks! Added to the list. Do you have an example of a time dependent IF? I don't think I've seen it. Also, is there a way one can set the extrapolation handler? – rm -rf Jul 10 '13 at 13:46
  • 8
    something like Interpolation[data, InterpolationOrder -> 1, "ExtrapolationHandler" -> {(Indeterminate &), "WarningMessage" -> False}] - but this is experimental. –  Jul 10 '13 at 15:06
  • 2
    @ruebenko Thanks! That will be immensely useful and will save me a lot of unnecessary Piecewise or Ifs. – rm -rf Jul 10 '13 at 15:12
  • 5
    In V10, the version number is now 5 and one can pass the argument "ElementMesh" to IFs that interpolate over an ElementMesh (e.g. when using FEM in NDSolve). Perhaps the bitfield meanings have changed. – Michael E2 Dec 17 '14 at 18:27
  • 3
    Following the List, third argument seems to be the input grid/mesh and the fourth argument seems to be the output interpolating structure. Then comes {Automatic} as the fifth and final argument. (In both V9 and V10 -- I've consulted this page so often that I can't believe I didn't notice before.) – Michael E2 Dec 17 '14 at 18:38
  • 3
    @R.M. One can also find method used to generate IF with InterpolationMethod argument. – mmal Oct 28 '15 at 23:49
  • 2
    @rm-rf The version attribute (part 2,2 of the InterpolatingFunction) comes out as 5 on MM v12. Do you know when it switched from 4 to 5? – Emilio Pisanty Oct 01 '19 at 19:04