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.

I study sigularity specification and MaxRecursion in NIntegrate. And find something unusual.

first I define a function

δ[x_, y_: 1/100] := 1/π*y/(x^2 + y^2)

Plot δ[x - 2]

Plot[δ[x - 2], {x, 0, 4}, PlotRange -> All]

gives enter image description here

Now NIntegrate δ[x - 2] from -∞ to +∞,I control the MaxRecursion option, and plot the sample points using the plotrecur function. I will give plotrecur in the end.

Table[{"MaxRecursion" i, 
plotrecur[δ[x - 2], {x, -\[Infinity], \[Infinity]}, 
MaxRecursion -> i]}, {i, 4, 9}]

this gives

enter image description here

the above picture shows that how reducing MaxRecursion step by step will affect sample points used in NIntegrate.

then I exclude 2 as a singularity in the integration interval. through 2 is actually not a singularity, but it is sharp.

Table[{"MaxRecursion" i, 
plotrecur[\[Delta][x - 2], {x, -\[Infinity], 2,\[Infinity]}, 
MaxRecursion -> i]}, {i, 4, 9}]

enter image description here

we can see that the MaxRecursion doesn't affect the sampling until MaxRecursion reduced to 4.

It's hard for me to understand this. I think the only effect after specifying a singularity manually is to let Mathematica trigger a singularityhandler(e.g. IMT or DoubleExponential) at that point. Is this view right? Why will specifying singularity makes MaxRecursion invalid? Can somebody give a explanation


Finally, the plotrecur function here:

plotrecur[integrand_, {x_, low_, singularity___, high_}, 
opt___] := {Length@#[[2, 1]], #[[1]], 
ListPlot[
 Transpose[{Transpose[#[[2, 1]]][[1]], 
   Range[Length@#[[2, 1]]]}]]} &[
Reap[NIntegrate[integrand, {x, low, singularity, high}, opt, 
EvaluationMonitor :> Sow[{x, integrand}]]]]
share|improve this question
    
I confirm this behavior for v. 8.0.4. Similar behavior occurs if one specify exclusions using the Exclusions option. –  Alexey Popkov Aug 23 '13 at 0:29
    
What are you expecting to happen? What you are seeing is that 5 recursions (within each of the sub-intervals {-Infinity, 2} and {2, Infinity}) are sufficient to solve the integral to within PrecisionGoal -> Automatic. –  Andrew Moylan Aug 25 '13 at 7:07
    
@AndrewMoylan Hi,I am sorry. I cannot understand what you mean. 5 recursions is not sufficient. –  matheorem Aug 25 '13 at 7:45
    
Isn't the exact value of the integral 1? With MaxRecursion -> 5, and splitting the integration region first at x == 2, NIntegrate converges to 1. Thus 5 recursions are sufficient. And any MaxRecursion -> n for n > 5 should be expected to be identical. –  Andrew Moylan Aug 25 '13 at 15:39

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.