4
$int = Interpolation[{{0, 0}, {1, 1}, {2, 2}},   
  InterpolationOrder -> 1]
FunctionRange[{$int[x], x > 0.5}, x, y]

returns Unable to find the range with the available methods.

Of course $int[1.2] or any other value gives a number, so I am wondering if FunctionRange can work at all with interpolation. Any clue?

MarcoB
  • 67,153
  • 18
  • 91
  • 189
Rho Phi
  • 1,420
  • 11
  • 21

2 Answers2

4

With Carl Woll's InterpolationToPiecewise:

(*https://mathematica.stackexchange.com/a/212753*)
InterpolationToPiecewise[if_, x_] := 
  Module[{main, default, grid}, grid = if["Grid"];
    Piecewise[{if@"GetPolynomial"[#, x - #], x < First@#} & /@ 
      grid[[2 ;; -2]], if@"GetPolynomial"[#, x - #] &@grid[[-1]]]] /; 
   if["InterpolationMethod"] == "Hermite";

$int = Interpolation[{{0, 0}, {1, 1}, {2, 2}}, InterpolationOrder -> 1]

FunctionRange[{InterpolationToPiecewise[$int, x], x > 0.5 && LessEqual @@ Insert[First@$int@"Domain", x, 2]}, x, y]

(*  0.5 < y <= 2.  *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • I wonder if the OP is looking for this? Needs["DifferentialEquations\InterpolatingFunctionAnatomy`"];domain = InterpolatingFunctionDomain[$int]` – Craig Carter Jun 29 '23 at 16:51
  • 2
    @CraigCarter InterpolatingFunctionDomain[$int] calls $int["Domain"], so six of one, half-a-dozen of the other, imo. I never use the InterpolatingFunctionAnatomy package anymore. The package is short and can be inspected with NotebookOpen[FindFile["DifferentialEquations`InterpolatingFunctionAnatomy`"]]. It consists of syntactic sugar for if[meth] for some of the methods found with if["Methods"]. It does have usage message that tell what the methods do, but just for the few it covers. – Michael E2 Jun 29 '23 at 18:14
  • Note MinMax[$int["ValuesOnGrid"]] will give the range of the function values at the interpolation nodes. For InterpolationOrder -> 1, that will be equivalent to the entire function range (ignoring the constraint x > 0.5). It will also ignore any local extrema of the polynomial interpolants for higher-order interpolations. Thus it might be considered a quick approximation of the function range, which might be useful in some applications, especially when the grid-spacing is small. – Michael E2 Jun 29 '23 at 18:25
1
Clear["Global`*"]

Changing the data so that the function is not a straight line

$int[x_?NumericQ, order : _Integer?NonNegative : 1] :=
  Interpolation[{{0, 0}, {1, 2}, {2, 1}}, InterpolationOrder -> order][x];

For InterpolationOrder -> 1

#[{$int[x], 0 <= x <= 2}, x] & /@ {NMinValue, NMaxValue}

(* {0., 2.} *)

% // RootApproximant

(* {0, 2} *)

For InterpolationOrder -> 2

#[{$int[x, 2], 0 <= x <= 2}, x] & /@ {NMinValue, NMaxValue}

(* {0., 2.04167} *)

% // RootApproximant

(* {0, 49/24} *)

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198