Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6919953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:05:14+00:00 2026-05-27T10:05:14+00:00

I have a Mathematica code where I have to evaluate numerically thousands of integrals

  • 0

I have a Mathematica code where I have to evaluate numerically thousands of integrals similar to this one

NIntegrate[
    (Pi*Cos[(Pi*(-2*x + y))/(1 + y)] + (1 + y)*(-Sin[(2*Pi*x)/(1 + y)] + 
    Sin[(Pi*(-2*x + y))/(1 + y)]))/(E^x*(1 + y)), 
    {x, 0, 100}, {y, 0, 100}
] //AbsoluteTiming

The integrand is a nice absolutely integrable function without singularities, which decays exponentially in one direction and as 1/y^3 in the other direction.

The NIntegrate command was working fine in Mathematica 7, but in the newest version 8.0.4 it slows down by two orders of magnitude. I assume in the new version it tries to better control the error, but at the expense of this tremendous increase in time. Are there some settings I could use so that the computation proceeds with the same speed as in Mathematica 7?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:05:14+00:00Added an answer on May 27, 2026 at 10:05 am

    ruebenko‘s answer and the comments from user1091201 and Leonid together combine to give the right answers.

    The Edit 1 answer by ruebenko is the right first answer for general situations like this, that is, add the option Method -> {"SymbolicPreprocessing", "OscillatorySelection" -> False}:

    expr = (Pi*
          Cos[(Pi*(-2*x + y))/(1 + y)] + (1 + y)*(-Sin[(2*Pi*x)/(1 + y)] +
             Sin[(Pi*(-2*x + y))/(1 + y)]))/(E^x*(1 + y));
    
    NIntegrate[expr, {x, 0, 100}, {y, 0, 100}, 
      Method -> {"SymbolicPreprocessing", 
        "OscillatorySelection" -> False}] // AbsoluteTiming
    

    And user1091201‘s comment suggesting Method -> "GaussKronrodRule" is close to the fastest possible answer for this specific problem.

    I’ll describe what is happening in NIntegrate in this specific example and along the way give some tips on handling apparently similar situations in general.

    Method Selection

    In this example, NIntegrate examines expr, comes to the conclusion that multidimensional “LevinRule” is the best method for this integrand, and applies it. However, for this particular example, “LevinRule” is slower than “MultidimensionalRule” (though “LevinRule” gets a more satisfactory error estimate). “LevinRule” is also slower than any of several Gauss-type one-dimensional rules iterated over the two dimensions, such as “GaussKronrodRule” which user1091201 found.

    NIntegrate makes its decision after performing some symbolic analysis of the integrand. There are several types of symbolic pre-processing applied; the setting Method -> {"SymbolicPreprocessing", "OscillatorySelection" -> False} disables one type of symbolic pre-processing.

    Essentially, with “OscillatorySelection” enabled, NIntegrate selects “LevinRule”. With “OscillatorySelection” disabled, NIntegrate selects “MultidimensionalRule”, which is faster for this integral, although we may distrust the result based the message NIntegrate::slwcon which indicates unusually slow convergence was observed.

    This is the part where Mathematica 8 differs from Mathematica 7: Mathematica 8 adds “LevinRule” and associated method selection heuristics into “OscillatorySelection”.

    Aside from causing NIntegrate to select a different method, disabling “OscillatorySelection” also saves the time spent doing the actual symbolic processing, which can be significant in some cases.

    Setting Method -> "GaussKronrodRule" overrides and skips the symbolic processing associated with method selection, and instead uses the 2-D cartesian product rule Method -> {"CartesianRule", Method -> {"GaussKronrodRule", "GaussKronrodRule"}}. This happens to be a very fast method for this integral.

    Other Symbolic Processing

    Both ruebenko‘s Method -> {"SymbolicPreprocessing", "OscillatorySelection" -> False} and user1091201‘s Method -> "GaussKronrodRule" do not disable other forms of symbolic processing, and this is generally a good thing. See this part of the NIntegrate advanced documentation for a list of types of symbolic preprocessing that may be applied. In particular, “SymbolicPiecewiseSubdivision” is very valuable for integrands that are non-analytic at several points due to the presence of piecewise functions.

    To disable all symbolic processing and get only default methods with default method options, use Method -> {Automatic, "SymbolicProcessing" -> 0}. For one-dimensional integrals this currently amounts to Method -> {"GlobalAdaptive", Method -> "GaussKronrodRule"} with certain default settings for all parameters of those methods (number of interpolation points in the rule, type of singularity handling for the global-adaptive strategy, etc). For multi-dimensional integrals, it currently amounts to Method -> {"GlobalAdaptive", Method -> "MultidimensionalRule"}, again with certain default parameter values. For high-dimensional integrals, a monte-carlo method will be used.

    I don’t recommend switching straight to Method -> {Automatic, "SymbolicProcessing" -> 0} as a first optimization step for NIntegrate, but it can be useful in some cases.

    Fastest method

    There is just about always some way to speed up a numerical integration at least a bit, sometimes a lot, since there are so many parameters that are chosen heuristically that you may benefit from tweaking. (Look at the different options and parameters that the “LevinRule” method or the “GlobalAdaptive” strategy has, including all their sub-methods etc.)

    That said, here is the fastest method I found for this particular integral:

    NIntegrate[(Pi*
          Cos[(Pi*(-2*x + y))/(1 + y)] + (1 + y)*(-Sin[(2*Pi*x)/(1 + y)] +
             Sin[(Pi*(-2*x + y))/(1 + y)]))/(E^x*(1 + y)), {x, 0, 
       100}, {y, 0, 100}, 
      Method -> {"GlobalAdaptive", Method -> "GaussKronrodRule", 
        "SingularityDepth" -> Infinity}] // AbsoluteTiming
    

    (The setting "SingularityDepth" -> Infinity disables singularity handling transformations.)

    Integration range

    By the way, is your desired integration range really {x, 0, 100}, {y, 0, 100}, or is {x, 0, Infinity}, {y, 0, Infinity} the true desired integration range for your application?

    If you really require {x, 0, Infinity}, {y, 0, Infinity}, I suggest using that instead. For infinite-length integration ranges, NIntegrate compactifies the integrand to a finite range, effectively samples it in a geometrically-spaced way. This is usually much more efficient than linear (evenly) spaced samples that are used for finite integration ranges.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in Mathematica: nxBin = Table[{-5 sX + (i - 0.5)*step,
Run the following code In Mathematica: r=6197/3122; p[k_,w_]:=Sqrt[w^2/r^2-k^2];q[k_,w_]:=Sqrt[w^2-k^2]; a[k_,w_,p_,q_]:=(k^2-q^2)^2 Sin[p]Cos[q]+4k^2 p q Cos[p]Sin[q] a[k_,w_]:=a[k,w,p[k,w],q[k,w]];
If you have Mathematica code in foo.m, Mathematica can be invoked with -noprompt and
I have a 15-day trial of Mathematica and need to evaluate it, and see
I have code similar to: if conditionA(x, y, z) then doA() else if conditionB(x,
I have tried the mathematica code for making the chaos game for DNA sequences
I have a WCF service to communicate with a Mathematica Kernel to evaluate arbitrary
I have the following code from mathematica and trying to do it with matlab
i wanted to ask this: I have in mathematica : step := {{0, 1},
i have this problem from mathematica,which refers to ising model.Here is a piece of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.