This is a related question to What's inside InterpolatingFunction[{{1., 4.}}, <>]? and Suppress extrapolation of interpolating function in a ContourPlot.
When interpolating a set of points, one might need to change the extrapolation behaviour, especially setting the function value to zero outside the original bounds of the data without reducing the performance time considerably.
It is possible to change the ExtrapolationHandler
when a polynomial interpolation is performed as described in the answer by @Michael E2.
However, the same procedure does not work with spline interpolation (see the minimal code below).
Is there a way to change the default ExtrapolationHandler
in spline interpolation?
Is it possible to change the default ExtrapolationHandler
for all interpolating commands, like FunctionInterpolation
, ListInterpolation
, and BSplineFunction
?
points = Transpose[{Range[0, 10*1.0]/10,RandomReal[{0, 10}, 10+1]}];
(* 10 points on x-axis from 0 to 1 with random numbers between 0 and
10 for the y-axis values *)
polyintpF = Interpolation[points, InterpolationOrder -> 2,
"ExtrapolationHandler" -> {(0.0 &), "WarningMessage" -> False}];
(* polynomial interpolation of order 2 *)
splineintpF = Interpolation[points, Method -> "Spline",
"ExtrapolationHandler" -> {(0.0 &), "WarningMessage" -> False}];
(* spline interpolation *)
polyintpF[2.0] (* gives zero as expected *)
(* extrapolates the function by the 'Automatic ExtrapolationHandler' ! *)
splineintpF[2.0]