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?

  • 1
    $\begingroup$ i is not I which is (Sqrt[-1]) $\endgroup$
    – chuy
    Jun 5, 2015 at 16:23
  • $\begingroup$ 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[]. $\endgroup$ Jun 5, 2015 at 16:26
  • $\begingroup$ @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. $\endgroup$
    – Sid
    Jun 5, 2015 at 16:34
  • 1
    $\begingroup$ Okay, have you tried putting it all into a single NIntegrate[]? Like, NIntegrate[(* stuff *), {x, -0.01, 0.01}, {y, -0.5, 0.5}]? $\endgroup$ Jun 5, 2015 at 16:48
  • 1
    $\begingroup$ Ah never mind... the MWE of your problem really is: NIntegrate[ x NIntegrate[x y, {y, 0, 1}], {x, 0, 1}] $\endgroup$
    – chuy
    Jun 5, 2015 at 17:28

1 Answer 1


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.

  • $\begingroup$ I'm still confused as to why there's an Assuming[] for the dummy variables… $\endgroup$ Jun 6, 2015 at 2:20
  • $\begingroup$ @Guesswhoitis. There need not be. I was not paying attention. Thanks. $\endgroup$
    – bbgodfrey
    Jun 6, 2015 at 2:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.