I have a numerical integral that evaluates fine for floating point arguments with low precision (e.g., 4 digits), with argument where only zeros follow the first, e.g., 4 non-zero digits, or with fractions with infinite precision. However, the evaluation crashes without error message when I enter a number that has 30 digits precision and non-zero values in these 30 digits.
Here is the specific code:
(* Define the integral function. *)
θ[ϱ_, ρ0_] := 2 ArcTan[Exp[(ϱ - ρ0)]] + 2 ArcTan[Exp[(ϱ + ρ0)]]
mz[ϱ_, ρ0_] := Cos[θ[ϱ, ρ0]]
Ka[k_] := EllipticK[k^2/(-1 + k^2)]/Sqrt[1 - k^2]
k[p_, y_, z_] := Sqrt[4 y z/(p^2 + (y + z)^2)]
g[p_, x_, ϱ_] :=
1/Pi Sqrt[1/(x ϱ)] (k[0, x, ϱ] Ka[k[0, x, ϱ]] - k[p, x, ϱ] Ka[k[p, x, ϱ]])
I3[ρ0_, δ_, rmax_] :=
δ^2 Re[
NIntegrate[
ϱ x (1 - mz[x, ρ0]) g[1,x δ , ϱ δ ] mz[ϱ, ρ0] Boole[x - ϱ < 0],
{x, 0, ρ0 + 15}, {ϱ, 0, rmax},
PrecisionGoal -> 7,
Method ->
{"GlobalAdaptive", "MaxErrorIncreases" -> 100000,
Method -> {"GaussKronrodRule", "Points" -> 3}},
MaxRecursion -> 20,
WorkingPrecision -> 30] +
NIntegrate[
ϱ x (1 - mz[x, ρ0]) g[1, x δ, ϱ δ] mz[ϱ, ρ0] Boole[x - ϱ > 0],
{x, 0, ρ0 + 15}, {ϱ, 0, rmax},
PrecisionGoal -> 7,
Method ->
{"GlobalAdaptive", "MaxErrorIncreases" -> 100000,
Method -> {"GaussKronrodRule", "Points" -> 3}},
MaxRecursion -> 20,
WorkingPrecision -> 30]]
(* This works fine, just gives a warning that the precision of the second argument is smaller than the working precision of the integral. *)
I3[10, 1.677 , 10^5]
(* This also works fine. *)
I3[10, 1.6770000000000000000000000000000000000000000000 , 10^5]
(* This will crash without error message or just output the NIntegrate command without executing it. *)
I3[10,
SetPrecision[1.677, 30] , 10^5]
The crash is reproducible with Mathematica 10.3.1.0 and 10.4. Switching the internet connection off, as suggested here, does not help.
Any suggestions how to evaluate the integral? As a workaround, I would be happy with a way to use SetPrecision in a way that it converts
1.677
to
1.67700000000000000000000000000
instead of
1.67700000000000004618527782441
I3[10, 1677/1000, 10^5]. – Anton Antonov Mar 08 '16 at 21:01