I want to "change" the interpolation function of Mathematica [] (in 1 dimension) by replacing the extrapolation with constant values ββwhen the input is out of range.
In other words, if the interpolation domain is [1,20] and f [1] == 7 and f [20] == 12, I want:
f[x] = 7 for x<=1 f[x] = 12 for x>=20 f[x] = Interpolation[...]
However, this fails:
(* interpolation w cutoff *) interpcut[r_] := Module[{s, minpair, maxpair}, (* sort array by x coord *) s = Sort[r, #1[[1]] < #2[[1]] &]; (* find min x value and corresponding y value *) minpair = s[[1]]; (* ditto for max x value *) maxpair = s[[-1]]; (* return the pure function representing cutoff interpolation *) Piecewise[{ {minpair[[2]] &, #1 < minpair[[1]] &}, {maxpair[[2]] &, #1 > maxpair[[1]] &}, {Interpolation[r], True} }]] test = Table[{x,Prime[x]},{x,1,10}] InputForm[interpcut[test]] Piecewise[{{minpair$59[[2]] & , #1 < minpair$59[[1]] & }, {maxpair$59[[2]] & , #1 > maxpair$59[[1]] & }}, InterpolatingFunction[{{1, 10}}, {3, 1, 0, {10}, {4}, 0, 0, 0, 0}, {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, {{2}, {3}, {5}, {7}, {11}, {13}, {17}, {19}, {23}, {29}}, {Automatic}]]
I'm sure something is missing from me. What kind?