There is no documented built-in way to convert the InterpolatingFunction
object into explicit Piecewise
form (thanks to @MichaelE2 for the link!). So the only possibility to get an explicit interpolating function is to re-implement the built-intin Interpolation
in the high-level Mathematica language. I have already done this for the built-in "Spline"
method with InterpolationOrder -> 2
(quadricquadratic spline interpolation with splicing points in the middle of adjacent interpolation points). Spline interpolation in general gives much better results than the default "Hermite"
method.
You can use my implementation of quadric spline interpolation in MathemeticaMathematica to produce an explicit Piecewise
function interpolating your data (as opposed to the built-in, it supports arbitrary precision!):
data = Transpose[{Range[Length[#]], #}] &@{2, 5, 9, 15, 22, 33, 50, 70, 100, 145};
spline[\[FormalX]_] = makeSpline[toSplineData[data], \[FormalX]]
Here is a comparison with the original data
and with the built-in Interpolation
:
Table[data[[x, 2]] - spline[x], {x, 10}]
f = Interpolation[data, Method -> "Spline", InterpolationOrder -> 2];
Table[f[x] - spline[x], {x, 10}]
Plot[(f[x] - spline[x])/spline[x], {x, 1, 10}, PlotRange -> All]
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0} {0., 0., 0., 1.77636*10^-15, 0., 0., 0., 0., 0., 0.}