# Integral evaluation error

I have the following integral that I wish to evaluate using Mathematica:

Assuming[{x > 0, y > 0}, NIntegrate[(x - d)/(2 σ^2)Exp[(I k x^2)/(2 R)- (x - d)^2/(4 σ^2)] NIntegrate[Exp[(I k y^2)/(2 R) - (I k y x)/R], {y, -0.5, 0.5}], {x, -0.01, 0.01}]]

For which Mathematica returns with the error: 'The integrand $e^\left({\frac{-I x y}{10} + \frac{I y^2}{20}}\right)$ has evaluated to non-numerical values for all sampling points in the region with boundaries {{-0.5,0.0}}'

All coefficients have been initialised to values: $d = 1, R = 10, k=1$. Are there any tips that I could try to evaluate this?

• i is not I which is (Sqrt[-1])
– chuy
Commented Jun 5, 2015 at 16:23
• The Assuming[] is useless here; apart from @chuy's prescription, you need to specify numerical values for your parameters to get something out of NIntegrate[]. Commented Jun 5, 2015 at 16:26
• @Guess who it is I already have all of the values specified: $d = 1$, $R = 10$, $k=1$. The only variables not initialised are x and y since these are the integration variables. Also in the script, I have :ii: which suitably yields the imaginary unit, I. The error still persists.
– Sid
Commented Jun 5, 2015 at 16:34
• Okay, have you tried putting it all into a single NIntegrate[]? Like, NIntegrate[(* stuff *), {x, -0.01, 0.01}, {y, -0.5, 0.5}]? Commented Jun 5, 2015 at 16:48
• Ah never mind... the MWE of your problem really is: NIntegrate[ x NIntegrate[x y, {y, 0, 1}], {x, 0, 1}]
– chuy
Commented Jun 5, 2015 at 17:28

Problems of this sort are posted from time to time in Mathematica SE. Multiple instances of Nintegrate are nested one inside another, and an inner integrand contains one of the outer variables of integration. And, from the point of view of the inner NInterate, the outer variable is undefined. (Chuy noted this in a comment above.) The solution is to have one multi-dimensional NIntegrate.

d = 1; R = 10; k = 1; σ = 1;
NIntegrate[(x - d)/(2 σ^2) Exp[(I k x^2)/(2 R) - (x - d)^2/(4 σ^2)]
Exp[(I k y^2)/(2 R) - (I k y x)/R], {y, -0.5, 0.5}, {x, -0.01, 0.01}]
(* -0.00778772 - 0.000032462 I *)


As it happens, replacing the inner NIntegrate by Integrate also works in this case.

NIntegrate[(x - d)/(2 σ^2) Exp[(I k x^2)/(2 R) - (x - d)^2/(4 σ^2)]
Integrate[Exp[(I k y^2)/(2 R) - (I k y x)/R], {y, -0.5, 0.5}], {x, -0.01, 0.01}]


of course, giving the same answer.

As noted by Guess who it is, Assuming[{x > 0, y > 0}, ...] is unnecessary, although harmless. I have deleted it from the answer.
• I'm still confused as to why there's an Assuming[] for the dummy variables… Commented Jun 6, 2015 at 2:20