Why can't I change the value of MaxRecursion in NIntegrate when integrating BesselJ?
As has been noted by ruebenko in the comments, there does seem to be a bug in the handling of infinite-range Bessel function integrals when MinRecursion
and MaxRecursion
are both set to non-default values. For instance, even the simple
NIntegrate[BesselJ[0, x], {x, 0, ∞}, MinRecursion -> 10, MaxRecursion -> 15]
chokes with a NIntegrate::minmax
error.
In any event, for the slightly more complicated
$$\int_0^\infty J_0(50u)\tanh\,u\,\mathrm du$$
what you can do is to explicitly use a method for infinite-range oscillatory integrals, and crank up WorkingPrecision
while you're at it. For example, using Longman's method:
NIntegrate[BesselJ[0, 50 q] Tanh[q], {q, 0, ∞},
Method -> "ExtrapolatingOscillatory", WorkingPrecision -> 90]
2.1950746252821515546830074912679107125599945310570775933×10⁻³⁵
Hmm, a bit tiny. Is it actually zero? Let's check with something slightly different.
Let's take whuber's splitting suggestion. Using the identity
$$\tanh\,u=1-\exp(-u)\;\mathrm{sech}\,u$$
and exploiting the Hankel transform identity
$$\int_0^\infty J_0(cu)\,\mathrm du=\frac1{c},\quad c>0$$
we start by integrating the integral with $\mathrm{sech}$, using again Longman's method:
NIntegrate[BesselJ[0, 50 q] Exp[-q] Sech[q], {q, 0, ∞},
Method -> "ExtrapolatingOscillatory", WorkingPrecision -> 90]
0.01999999999999999999999999999999997804925374717848445316992508732089287121184172744576
which can be seen to be quite close to $1/50$. Subtracting this quantity from $0.02$, yields a result that agrees with the earlier attempt, so we now have a bit more trust in the results.
I had used Longman's method in these examples, but one could also have chosen to use the methods of Ooura-Mori ("DoubleExponentialOscillatory"
) or Levin ("LevinRule
") instead.