How can I reduce the domain of an InterpolatingFunction
?
For example, consider if = FunctionInterpolation[x^2, {x, 0, 3}]
. Is it possible to define if2
as the restriction of if
to {x,1,2}
? Not only should the domain change, but if2
should not contain the information of if
on $[0,1]$ and $[2,3]$. I've noticed the package InterpolatingFunctionAnatomy
but I don't know what methods would be useful here.
Answer
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]
Comments
Post a Comment