# Multiple NIntegrate (again)

Basically I have the same question as here: https://mathematica.stackexchange.com/questions/37146/multiple-nintegrate but since I don't have enough "reputation" I cannot comment there.

I want to solve the following multiple Integral numerically at given Points R, m:

Qb[R_, m_] := 3/m^2 + 8/(Sqrt[Pi] m)
NIntegrate[Exp[-c^2] (-4 m^2/(R Sqrt[Pi]) Integrate[
Exp[-x^2] x^2, {x, 0, Infinity}] - 2 m^2/(R Sqrt[Pi])
Integrate[Exp[-x^2] x^2 Integrate[If[R < Sqrt[c^2 + x^2 - 2 c x z],
R/Sqrt[c^2 + x^2 - 2 c x z], 1], {z, -1, 1}], {x, 0, Infinity}])
(3 c^2 - 2 c^4), {c, 0, Infinity}]


But I get error messages: NIntegrate::inumr: "The integrand (3\ c^2-2\ c^4)\ E^-c^2\ (-44.7156-50.4562\ !(*SubsuperscriptBox[([Integral]), (0), ([Infinity])](*SuperscriptBox[(E), (-Power[<<2>>])]\\ *SuperscriptBox[(x), (2)]\\ (*SubsuperscriptBox[([Integral]), (-1), (1)]If[Less[<<2>>], Times[<<2>>], 1] [DifferentialD]z) [DifferentialD]x))) has evaluated to non-numerical values for all sampling points in the region with boundaries {{[Infinity],0.}}."

What is the right way to do this with Mathematica?

Edit:

To make the problem slightly simpler you can leave out all constants and get rid of the x-integration:

Qb[R_] :=
NIntegrate[
Exp[-c^2] NIntegrate[
If[R < Sqrt[c^2 - 2 c z], R/Sqrt[c^2 - 2 c z], 1], {z, -1, 1}],
{c, 0, Infinity}];
Qb[3.7]


or as an even simpler example

NIntegrate[NIntegrate[y, {x, 0, 1}], {y, 0, 1}]


In this case it works to replace the inner NIntegrate by Integrate, but if the inner integral is too complicated for analytic evaluation Mathematica cannot handle it.

• What do you mean by "I cannot comment there"? What is the definition of Qb used for? Does R have a value at some point? Lots of questions, you could try to debug your code and identify the problematic bits first. – Yves Klett Feb 17 '14 at 12:31
• I cannot comment the other question because it says "you must have 50 reputation". I just want to insert random values. To check calculations. So say I want to have Qb[3.7,2.8] for example. It's more a general question, what is the right way to numerically evaluate nested integrations? – André Feb 17 '14 at 13:07
• Could you come up with a simple example to show what your problem is? Your description and the code are not very clear. – Yves Klett Feb 17 '14 at 13:12
• The trouble is certainly that the Analyic integrals in the integrand are not being exaluated. The integrand of the "x" intgral depends piecewise on x through the If. Do you perhaps mean for all those integrals to be numeric? – george2079 Feb 17 '14 at 13:30
• You should have posted the simple example in the first place, and really its ok to edit the question and delete the complicated mess and just ask the specific relatively simple question. – george2079 Feb 17 '14 at 14:41

Let's start with the simplest problem. You ask for NIntegrate[NIntegrate[y, {x, 0, 1}], {y, 0, 1}]. This doesn't work because when the internal integral is being evaluated, y doesn't have any values (hence the error). A simple way to fix this is to do the double integral rather than trying to do two single integrals. Hence:

NIntegrate[y, {x, 0, 1}, {y, 0, 1}]
0.5


Your next example can be fixed the same way:

Qb[R_] := NIntegrate[Exp[-c^2] If[R < Sqrt[c^2 - 2 c z], R/Sqrt[c^2 - 2 c z], 1],
{z, -1, 1}, {c, 0, Infinity}];
Qb[3.7]
1.13579