The function is positive when q > 0
, and the output is negative: the result is clearly wrong. It seems to be ignoring the singularity at x == 0
and doing something like this:
f[x_, q_] = Integrate[1/x^2 Exp[-x^2/(2 q)]/Sqrt[2 \[Pi] q], x]
Limit[f[x, q], x -> Infinity] - Limit[f[x, q], x -> -Infinity]
When the parameter is numerical, Mathematica detects the singularity:
With[{q = 1},
Integrate[1/x^2 Exp[-x^2/(2 q)]/Sqrt[2 \[Pi] q],
{x, -Infinity, Infinity}]]