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]

k[x]evaluates to0. PerhapsIntervalMemberQis not the best choice. I would do something likePiecewise[{{fun[var], LessEqual @@ Riffle[First[fun["Domain"]], var]}}, def]for the body ofmakeNoExtrapFun. – Michael E2 Apr 12 '15 at 15:32If[ ]just because of its fourth argument – Dr. belisarius Apr 12 '15 at 16:09Ifvs.Piecewiseis debatable. The main point is thatIntervalMemberQmakes the function evaluate todefon non-numeric input. For instance, I'm not sure how to get the derivative of the functionk[x]withD; I believe with my definition, bothD[k[x], x]andk'[x]work. – Michael E2 Apr 12 '15 at 16:16