When numerically calculating a double integral using NIntegrate over an infinite domain (with all options at their default), Mathematica 7 calculates my integral with some comments about slow convergence, but Mathematica 9 aborts calculating with a long message which starts with

SystemException["MemoryAllocationFailure" ...

What do I have to do to make the calculation in Mathematica 9 (Linux)?

  • 7
    $\begingroup$ My experience with this site tells me that people will ask you to show them what integral you're trying to do, and what output (if any) you get before crashing.. in both versions. $\endgroup$
    – QuantumDot
    Commented May 14, 2013 at 5:38
  • $\begingroup$ @nail, that doesn't parse if I copy and paste into Mathematica. Can you edit the original question so that the calculation you are trying to do is included? $\endgroup$ Commented May 14, 2013 at 5:52
  • $\begingroup$ Sorry, I forget about this point. The file with calculations is rather long and it may be found here yadi.sk/d/OQzPSZQg4oZly . $\endgroup$
    – nail
    Commented May 14, 2013 at 5:58
  • 1
    $\begingroup$ In which case can you find the minimum amount of code which will reproduce the error? Looking through the code it seems that you should be able to simplify the problem and it is still likely to run into memory problems as you have it set up. $\endgroup$ Commented May 14, 2013 at 6:26
  • 3
    $\begingroup$ Ok, I'll try to minimize the code with problem. $\endgroup$
    – nail
    Commented May 14, 2013 at 7:05

1 Answer 1


I get this error fairly often and my usual course of action is to switch over to Mathematica 8 which does not get this error. A relatively minimal way to get this error in Mathematica 9 is to run the following three commands:

lambda[t_] := ModularLambda[t]
theta[t_] := EllipticTheta[3, 0, Exp[I Pi t]]
N[-Pi Integrate[
   lambda[I x]^4 theta[I x]^4 lambda[I x] (1 - lambda[I x]), {x, 0, 
    Infinity}], 30]

In Mathematica 8 this integral calculates without any problems. The two definitions are needed to replicate this error for some reason. My suspicion is that it has something to do with the complexity of the integrand.

I have been trying a different workaround which has helped in some instances. If I compile the integrand, the MemoryAllocationFailure goes away and is replaced with another error that I can sometimes fix:

Block[{integrandCompiled, integrandDeferred},
 integrandCompiled = 
   N[lambda[I x]^4 theta[I x]^4 lambda[I x] (1 - lambda[I x])]];
 integrandDeferred[x_ /; NumberQ[x]] := integrandCompiled[x];
 -Pi NIntegrate[integrandDeferred[x], {x, .1, 10},
   PrecisionGoal -> 30]

This code gets the right answer but generates error messages. With integration, I usually throw away the result if I get any error because I have seen integration results that are completely wrong when errors occur during the integration.

  • $\begingroup$ In your first example you don't need := (SetDelayed). Then you can use NIntegrate[ lambda[I x]^4 theta[I x]^4 lambda[I x] (1 - lambda[I x]), {x, 0, Infinity}] and it works... $\endgroup$
    – s0rce
    Commented Oct 14, 2013 at 16:20

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