Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The Documentation tells us that there are two ways to disable symbolic processing of the integrand by the NIntegrate function when it is known that it just slows down the computation. One way is documented and heavily used on the Documentation page "NIntegrate Integration Strategies" and some other Documentation pages:

Method -> {Automatic, "SymbolicProcessing" -> 0}

Another approach is to define the integrand as a "black-box" function and this way is recommended in the "Possible Issues" section of the NIntegrate documentation page.

Let us compare:

f[x_] := Nest[Sin[# + Sin[2 #]] &, x, 20]
NIntegrate[f[x], {x, 0, 1}, 
  Method -> {Automatic, "SymbolicProcessing" -> 0}] // Timing

(* => {2.797, 0.947747} *)

g[x_?NumericQ] := Nest[Sin[# + Sin[2 #]] &, x, 20]
NIntegrate[g[x], {x, 0, 1}] // Timing

(* => {0.032, 0.947747} *)

One can see the two-order speedup of the "black-box" over the Method option. What is the reason? Are there cases when the Method option have advantages over the "black-box" approach? In which cases it is recommended to use one or another?

share|improve this question
add comment

1 Answer

The first case still symbolically expands nest, substituting each numerical value into that nasty big expression, while the second expands it numerically for each x val.

Try this

f[x_] := (Print[x]; Nest[Sin[# + Sin[2 #]] &, x, 2])

You will see it is only called once with the symbolic argument. "SymbolicProcessing" only turns off attenpts at symbolic integration

share|improve this answer
1  
"SymbolicProcessing" doesn't affect whether or not symbolic integration is tried (AFAICT, with NIntegrate, it never is). Rather, preprocessing is aimed at making certain classes of integral easier to deal with numerically. For example, it checks for and tries to remove oscillatory behaviour, splits integrands piecewise and selects a method for each section, transforms integrals over infinite intervals into ones over the unit (hyper)cube, etc. –  Oleksandr R. Aug 29 '12 at 10:14
    
thanks, I puzzled over that after posting the answer. –  george2079 Aug 29 '12 at 15:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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