# Double application of NIntegrate produces unexpected error messages [duplicate]

In the course of trying to answer 69601, I encountered unexpected error messages. In highly simplified form,

NIntegrate[NIntegrate[z y, {y, 0, 10}], {z, 0, 10}]


produces repeated messages,

NIntegrate::inumr: The integrand y z has evaluated to non-numerical values for all sampling points in the region with boundaries (0  10). >>


before returning the correct answer, 2500. Thus, the error messages seem to be harmless, apart from consuming time. Nonetheless, I would like understand their source and eliminate them by means other than Quiet. The option Method -> {Automatic, "SymbolicProcessing" -> False} reduces the number of messages to one, which is a step in the right direction. Suggestions?

The issue is that the interior integral tries to evaluate first and has a symbolic z. This fails and returns unevaluated before being passed to the outer integral.

The two solutions that come to mind would be to call NIntegrate as a double integral.

NIntegrate[z*y, {y,0,10},{z,0,10}]
(* 2500. *)


or to define the interior integral as a function that requires numeric inputs.

f[z_?NumericQ]:= NIntegrate[z * y, {y, 0, 10}]
NIntegrate[f[z], {z, 0, 10}]
(* 2500. *)


There may be some way to accomplish this with some option setting or by some non-standard evaluation that I'm not aware of but this seems cleanest.

• I especially like your second solution, which preserves the structure needed to solve the actual problem. Thanks. – bbgodfrey Dec 24 '14 at 22:29