I have the following (simplified) integral:
f[x_, x0_] := Sinh[x]/(Cosh[2 x] + Cosh[2 x0])
g[x_, xp_] := EllipticK[(4 x xp)/(x + xp)^2]/(x + xp)
NIntegrate[
f[x, 101.] f[xp, 101.] g[x, xp], {x, 51., 101.}, {xp, 50., x-10.^-6},
PrecisionGoal -> 6, MaxRecursion -> 100]
For me (with Mathematica v. 10.3), the integral fails with
NIntegrate::inumri: "The integrand (...) has evaluated to Overflow, Indeterminate, or Infinity for all sampling points the region with boundaries {{0.,9.35762*10^-14},{0,1}}"
Why is that? Both f
and g
are finite and well defined for all values (in particular in the integration range).
Also, the "boundaries" given in the error message do not make sense to me. How do I read this? None of these values are in the interval [51, 101]
.
When I omit the MaxRecursion
parameter, the integral gives a warning instead of an error saying that it could not get a correct value with the given number of recursions (wrong number and no number seem equally bad to me).
Edit:
It also fails when defining f
and g
to be numeric:
f[x_?NumericQ, x0_?NumericQ] := Sinh[x]/(Cosh[2 x] + Cosh[2 x0])
g[x_?NumericQ, xp_?NumericQ] :=
EllipticK[(4 x xp)/(x + xp)^2]/(x + xp)
NIntegrate[
f[x, 101.] f[xp, 101.] g[x, xp], {x, 51., 101.}, {xp, 50.,
x - 10.^-6},
Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 100000},
MaxRecursion -> 100]
The MaxErrorIncreases
parameter was required to avoid warnings about inaccurate results.
In my real application, f
has an additional factor Cosh[x0]
that I omitted here because it is a constant factor in the integral. Just now, it happens that f
evaluates to very small numbers, but again, this should only be a constant factor. The same result is obtained with WorkingPrecision -> 20
.
Edit2:
Since there was some concern about the small values of the function f
, here another function that gives the same problem:
f2[x_?NumericQ, x0_?NumericQ] := Sech[x - x0] (1 - x Tanh[x - x0])
NIntegrate[
f2[x, 100.] f2[xp, 100.] g[x, xp], {x, 51., 101.}, {xp, 50.,
x - 10.^-6},
Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 100000},
MaxRecursion -> 100]
With the previous value of x0=101
, this new integral gives a value without any error messages, but with x0=100
, it fails as before. It seems to be quite random when the integral can be calculated and when not.
g[51, 51]
, which happens to be on one of the boundaries of your region of integration, evaluates toComplexInfinity
, so perhaps your functions are not as finite-valued as you thought. $\endgroup$x=xp
from the integration (i.e., by stopping atxp=x-1e-6
, see edits to the question. $\endgroup$f
andg
usingNumericQ
; that's typically safer for numerical evaluations:f[x_?NumericQ, x0_?NumericQ] := ...
and similarly withg
. See mathematica.stackexchange.com/a/26037/27951. I'm not sure that this will fix the problem though. Thef
andg
functions evaluate to very very small numbers over your domain. Instead of aPrecisionGoal
, try using only exact numbers in your definitions, and settingWorkingPrecision -> $MachinePrecision
(or higher) to enable arbitrary-precision arithmetic and error tracking. $\endgroup$Plot3D[]
, just to check that what you're integrating is not nasty-looking? $\endgroup$