Contradiction between Analytic and Numerical Integration
I think the Levin Rule is messing up somehow (the default choice of Method
here). I recall seeing such a mistake somewhere before. Here's a workaround:
NIntegrate[
f[x, p, 1*I*x]*(p^2/2), {p, -Infinity, Infinity}, {x, -Infinity, Infinity},
Method -> {"CartesianRule", Method -> {"GaussKronrodRule", "Points" -> 11}}]
NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.
(* 0.25 + 0. I *)
Addendum
A way to get the Levin Rule to work is to make the substitution p^2 -> p
and use the even symmetry of f
in p
to change the p
integral to the domain {p, 0, Infinity}
. This transforms the oscillatory part of the integrand into Exp[I * <linear>]
, which the Levin Rule seems to handle properly.
ff[x_, p_, b_] = Exp[-p - x^2]*Exp[4 b*p/(1 + 4 b)]/Pi/Sqrt[1 + 4 b];
NIntegrate[
ff[x, p, 1*I*x]*(Sqrt[p]/2),
{p, 0, Infinity}, {x, -Infinity, Infinity}]
(* 0.25 - 5.07359*10^-13 I *)
If we nest the NIntegrate
it gets it right..
c=2;
g[x_?NumericQ] :=
NIntegrate[f[x, p, c*I*x]*(p^2/2), {p, -Infinity, Infinity}]
NIntegrate[g[x], {x, -Infinity, Infinity}]
0.25 + 0. I
however.. reversing the order (which shouldn't matter) fails:
h[p_?NumericQ] :=
NIntegrate[f[x, p, c*I*x]*(p^2/2), {x, -Infinity, Infinity}]
NIntegrate[h[p], {p, -Infinity, Infinity}]
(convergence warning)
0.665207 - 0.0424908 I