How to restrict InterpolatingFunction to a smaller domain?
you can do:
FunctionInterpolation[if[x], {x, 1, 2}]
which will actually sample the interpolation function and generate a new one.
Alternately you can extract the data and use Interpolation
Interpolation[
Select[ Transpose[{#[[3, 1]], Flatten[#[[4]]]}] ,
1 <= #[[1]] <= 2 &]] &@if
This second method may not exactly match your desired domain boundaries unless they happened to be sample points on the original interpolation.
In both cases the result will not be precisely the same as the original interpolation.
yet another thing you can do, which seems a bit of a hack. Looking at the FullForm
of InterpolatingFunction
you see the first argument is the domain, so if you do:
if[[1]] = {{1, 2}}
you will get a warning if you go out of the new bounds (but get the same result as the original)
Edit: this will use the derivatives from the first interpolation in the second:
data = Select[Transpose[{#[[3, 1]], Flatten[#[[4]]]}],
1 <= #[[1]] <= 2 &] &@if;
Interpolation[{{#[[1]]}, #[[2]], D[if[x], x] /. x -> #[[1]]} & /@ data]
Maybe the following meets your desiderata:
if2[x_ /; 1 <= x <= 2] = if[x];
if2[0.9]
(* if2[0.9] *)
if2[1.1]
(* 1.21 *)