Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)?

share|improve this question

closed as off-topic by Michael E2, Bob Hanlon, blochwave, MarcoB, Yves Klett Jul 19 '15 at 7:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Michael E2, Bob Hanlon, blochwave, MarcoB, Yves Klett
If this question can be reworded to fit the rules in the help center, please edit the question.

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. – QuantumDot May 14 '13 at 5:38
@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? – Jonathan Shock May 14 '13 at 5:52
Sorry, I forget about this point. The file with calculations is rather long and it may be found here . – nail May 14 '13 at 5:58
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. – Jonathan Shock May 14 '13 at 6:26
Ok, I'll try to minimize the code with problem. – nail May 14 '13 at 7:05

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.

share|improve this answer
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... – s0rce Oct 14 '13 at 16:20

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