I'm trying to calculate a continuous integral within a discrete integral.

Something similar to this (yet more complex):

NSum[NIntegrate[x^2 + y, {x, 0, 1}], {y, 2}]

I receive the following error code:

NIntegrate::inumr: "The integrand x^2+y has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,1}}. "

What is the proper way to tell Mathematica to evaluate this expression?

  • $\begingroup$ You can do NSum[Integrate[x^2 + y, {x, 0, 1}], {y, 2}], but you can't use NIntegrate if there are symbolic terms in the integral inside. In any case, you should consider its form in your real problem $\endgroup$ Commented May 13, 2013 at 23:11
  • $\begingroup$ The actual function I am integrating over does not have an analytical integral that can be found. The integration has to be numeric in this case. No other solution? $\endgroup$
    – Ron
    Commented May 13, 2013 at 23:13
  • 1
    $\begingroup$ This is what you need, even though NSum is HoldAll. $\endgroup$
    – Szabolcs
    Commented May 13, 2013 at 23:14
  • $\begingroup$ What if you interchange summation and integration? $\endgroup$ Commented May 13, 2013 at 23:50
  • $\begingroup$ Thanks Szabolcs - exactly what I was looking for. (Changing order will cause the same issue). $\endgroup$
    – Ron
    Commented May 13, 2013 at 23:57


Browse other questions tagged or ask your own question.