I am trying to find the regions where the integral of a function a function is larger than a certain quantity using RegionPlot. For simplicity's sake, let's say the intergal I am looking to plot is is

F[x_, y_, s_] := NIntegrate[Exp[(x - y)^2/(2*s^2)], {x, -3, 3}];

If I then attempt to plot this using RegionPlot using this code

RegionPlot[F[x, y, s] > 100, {y, -3, 3}, {s, 0.1, 2}]

I get the following error message

NIntegrate: The integrand E^((x-y)^2/(2 s^2)) has evaluated to non-numerical values for all sampling points in the region with boundaries {{-3,3}}.

followed by throwing an exception

Throw: "Uncaught\!\(Throw[\(-Holonomic`DifferentialRootReduceDump`y[NIntegrate`\LevinRuleDump`x]\) + \\*SuperscriptBox[\"Holonomic`DifferentialRootReduceDump`y\", \"\\[Prime]\",MultilineFunction->None][NIntegrate`LevinRuleDump`x], \NIntegrate`LevinRuleDump`FastLookupHolonomicDifferentialEquation]\) \ returned to top level."

So it seems that RegionPlot is actually trying to evaluate F before assigning values to y and s and this is causing NIntegrate to crash. How do I avoid this?

  • 1
    $\begingroup$ Use _?NumericQ on F[] $\endgroup$
    – Michael E2
    Jan 18, 2019 at 2:53
  • $\begingroup$ Oops, I should have first asked, what numeric value is assigned to x in your RegionPlot[]? $\endgroup$
    – Michael E2
    Jan 18, 2019 at 2:54
  • $\begingroup$ @MichaelE2 That was a mistake, I shouldn't have defined it with x in this example and I wasn't initializing it with anything, but removing x didn't affect the result. Apparently what was missing was the undocumented NumericalFunction option pointed out in the answer below $\endgroup$ Jan 18, 2019 at 19:41
  • $\begingroup$ Also related: mathematica.stackexchange.com/questions/183631/… $\endgroup$
    – Michael E2
    Jan 18, 2019 at 21:15

1 Answer 1


If you define F without x-argument

F[ y_?NumericQ, s_?NumericQ] :=NIntegrate[Exp[(x - y)^2/(2*s^2)], {x, -3, 3}];

ContourPlot evaluates the region boundary F[ y, s] ==100

ContourPlot[Evaluate[F[ y, s]] == 100, {y, -3, 3}, {s, 0.1, 2}, FrameLabel -> {y, s}]

enter image description here

No idea why RegionPlot fails. As a workaround use Plot3D and RegionFunction

 pic = Plot3D[0 , {y, -3, 3}, {s, 0.1, 2},RegionFunction ->  Function[{y, s, z}, F[y, s] > 100],Mesh -> False]

Now change Graphics3D-> Graphics

arg = pic[[1]] /. GraphicsComplex -> List; (* argument of GraphicsComplex*)
Graphics[Apply[GraphicsComplex, {Map[ Most[#] &, arg[[1]]], Rest[arg]}],Axes -> True]

enter image description here

final RegionPlot with undocumented option

RegionPlot[F[y, s] > 100, {y, -3, 3}, {s, 0.1, 2}, "NumericalFunction" -> False]

enter image description here

That's it!


Not the answer you're looking for? Browse other questions tagged or ask your own question.