# RegionPlot evaluating NIntegrate before assigning variable values and resulting in non-numerical integrands [duplicate]

This question already has an answer here:

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[\(-HolonomicDifferentialRootReduceDumpy[NIntegrate\LevinRuleDumpx]$$ + \\*SuperscriptBox[\"HolonomicDifferentialRootReduceDumpy\", \"\\[Prime]\",MultilineFunction->None][NIntegrateLevinRuleDumpx], \NIntegrateLevinRuleDumpFastLookupHolonomicDifferentialEquation]\) \ 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?

## marked as duplicate by Michael E2 numerical-integration StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jan 18 at 21:05

• Use _?NumericQ on F[] – Michael E2 Jan 18 at 2:53
• Oops, I should have first asked, what numeric value is assigned to x in your RegionPlot[]? – Michael E2 Jan 18 at 2:54
• @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 – Guilherme Casas Gonçalves Jan 18 at 19:41
• Also related: mathematica.stackexchange.com/questions/183631/… – Michael E2 Jan 18 at 21:15

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}] 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[] /. GraphicsComplex -> List; (* argument of GraphicsComplex*)
Graphics[Apply[GraphicsComplex, {Map[ Most[#] &, arg[]], Rest[arg]}],Axes -> True] final RegionPlot with undocumented option

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