# Testing Positivity of Interpolating Function

I have an interpolating function and I want to test whether it is positive definite over an interval. Will any of Mathematica's numerical optimisation functions work for this or is there a simpler solution?

I suggest you pull out the coordinates that make up the interpolation function and work with those. Here is an interpolation function and a module to pull out the values and check.

cc = Table[{x, 0.5 + Sin[2 \[Pi] x]}, {x, 0, 1, 0.01}];
f = Interpolation[cc];


The following module will pull the interpolation function apart and look to see if all values are positive between locations x1 and x2

ClearAll[allPositive];
allPositive[f_, {x1_, x2_}] := Module[{xx, yy, n1, n2, pos},
xx = Flatten[f["Grid"]];
yy = f["ValuesOnGrid"];
n1 = Nearest[xx -> "Index", x1][[1]];
n2 = Nearest[xx -> "Index", x2][[1]];
pos = Select[Transpose[{xx, yy}][[n1 ;; n2]], #[[2]] < 0 &];
If[pos === {}, True,
"Negative between " <> ToString[pos[[1, 1]]] <> " and " <>
ToString[pos[[-1, 1]]]]
]


Example of use

allPositive[f, {0.2, 0.4}]


(* True *)

allPositive[f, {0.2, 0.6}]


(* "Negative between 0.59 and 0.6" *)

This assumes that if the interpolants are positive then the function is positive. This may not be true. Jumps in interpolants can cause oscillations on the interpolated function. However, if you are getting this then you may be off track anyway. The advantage of this approach is that you can deal with highly oscillating functions as long at the interpolation is accurate.

Hope that helps.

Apply Minimize as usual.

xsol = x /. First@NDSolve[{x'[t] == x[t], x[0] == 1}, x, {t, -3, 3}]

Minimize[{xsol[t], -3 < t < 3}, t]

(*   {0.0497871, {t -> -3.}}   *)