# Strange behavior of NIntegrate

I have some function f[x,y,a], where a is some parameter, defined as piecewise

f[x,y,a] = Piecewise[{{g[x,y,a], a<m[x]}, {0, True}}]


Here $m$ is some function. I need to integrate the function f with some weight h[x] over the two-dimensional domain {x, x1,x2}, {y, y1, v[x])}, where x1,x2,y1 are the ordinary numbers and v[x] is some given function. Precisely, I want to obtain the table of integral values for varying parameter a from a1 to a2 with the step da:

TableNeutral = Table[{a, Re[NIntegrate[h[x]f[x,y,a], {x, x1, x2},{y, y1, v[x]},Evaluated-> False]]}, {a, a1, a2, da}]


Surprisingly, when generating the table Mathematica writes:

The integrand ... has evaluated to non-numerical values for all sampling points in the region with boundaries $\begin{pmatrix}0 & 1 \\ 0 & 1\end{pmatrix}$

Moreover, the generated table contains the numerical values for some domain of the values $a$, while for some values of $a$ it just writes the code (see the picture): At the picture the role of parameter a is played by $m\chi$, the role of f[...] is played by CS1totalxscalar[...], the role of y is played by s2, and the role of g[...] is played by PhotonDFapprox[...].

What can be a reason for this, and how to correct this?

My code:

(*Not relevant*)
coef0 = g\[Chi]s*Sqrt[4*Pi*\[Alpha]]*gps

(*Pre-definition of the function f*)
CS1scalar[Ss_, s2_, m\[Chi]_, mp_]= ((4 m\[Chi]^2-s2) Sqrt[s2 (s2-4 m\[Chi]^2)] (Sqrt[mp^4-2 mp^2 (s2+Ss)+(s2-Ss)^2] (mp^6-mp^4 (s2+5 Ss)+mp^2 Ss (2 s2-25 Ss)+Ss^2 (7 s2-3 Ss))-2 Ss^2 (9 mp^4+mp^2 (6 Ss-10 s2)+2 s2^2-2 s2 Ss+Ss^2) Log[(mp^2-Sqrt[mp^4-2 mp^2 (s2+Ss)+(s2-Ss)^2]-s2+Ss)/(mp^2+Sqrt[mp^4-2 mp^2 (s2+Ss)+(s2-Ss)^2]-s2+Ss)] ))/(256 \[Pi]^3 s2^3 Ss^2 (mp^2-Ss)^3)

(*Definition of the function g*)
v[x_, mp_, EN_] = x*EN/(mp + x*EN);
gamma[x_, mp_, EN_] = 1/Sqrt[1 - v[x, mp, EN]^2];
ECM[x_, mp_, EN_] =
FullSimplify[
x*EN*(1 - v[x, mp, EN])*gamma[x, mp, EN] +
Sqrt[mp^2 + (x*EN*(1 - v[x, mp, EN])*gamma[x, mp, EN])^2],
Assumptions -> mp > 0 && EN > 0 && x > 0]
PhotonDFfullapprox[x_, Z_, \[Alpha]_, mN_, qperp_, R_, S_] =
Assuming[mN > 0 && x > 0,
3*\[Alpha]*Z^2/(4*Pi)*((1 + (1 - x)^2)/x)*
qperp^2/(qperp^2 + x^2*mN^2)^2*
SphericalBesselJ[1, R*Sqrt[(x*mN)^2 + qperp^2]]/(R*x*mN)*
Exp[-x^2*mN^2*S^2]];
PhotonDFapprox[x_, Z_, \[Alpha]_, mN_, R_, S_] =
Integrate[
PhotonDFfullapprox[x, Z, \[Alpha], mN, qperp, R, S]*2*
qperp, {qperp, 0, Sqrt[(4.49/5)^2 - x^2*mN^2]}];

(*Definition of the function f*)
CS1totalscalar[x_, s2_, m\[Chi]_, mp_, \[Alpha]_, g\[Chi]s_, gps_] =
coef0^2*CS1scalar[Ss, s2, m\[Chi], mp] /.
Ss -> ECM[x, 0.938, 3.6*10^4]^2 ;
CS1totalxscalar[x_, s2_, m\[Chi]_, mp_, \[Alpha]_, g\[Chi]s_,
gps_] =
Piecewise[{{CS1totalscalar[x, s2, m\[Chi], mp, \[Alpha], g\[Chi]s,
gps], m\[Chi] <= (ECM[x, 0.938, 3.6*10^4] - 0.938)/2}, {0,
m\[Chi] > (ECM[x, 0.938, 3.6*10^4] - 0.938)/2}}];
(Sqrt[2*0.938*3.6*10^4*10^-2 + 0.938^2] - 0.938)/2

(*Table*)

Tablescalar =
Table[{m\[Chi],
Re[NIntegrate[
CS1totalxscalar[x, s2, m\[Chi], 0.938, 1/137, 1, 0.1*0.938/240]*
PhotonDFapprox[x, 42, 1/137, 90, 5, 0.726], {x, 10^-7,
4.49/(5*90)}, {s2,
4*m\[Chi]^2, (ECM[x, 0.938, 3.6*10^4] - 0.938)^2},
Evaluated -> False]]}, {m\[Chi], 0.001, 12.5, 0.1}]

• Can you give us some working code that shows the problem? The f and Table you have presented have many undefined parameters and functions. – bill s Sep 25 '17 at 16:46
• @bills : I've added the code. I hope that it is more or less understandable. – John Taylor Sep 25 '17 at 17:27
• I fixed CS1totalxscalar and PhotonDFapprox to take only numeric s2 and x and it works. (There is no Evaluated->False in my version 10.1 so I deleted that ) I do get some slow convergence warnings but with reasonable looking numeric results returned. – george2079 Sep 25 '17 at 17:40
• @george2079 : sorry. but how did you do that? – John Taylor Sep 25 '17 at 17:43
• for the two functions called directly by NIntegrate do like: CS1totalxscalar[x_?NumericQ, s2_?NumericQ, m\[Chi]_, mp_, \[Alpha]_, g\[Chi]s_, gps_] = .. (restart your kernel to clear old definitions). I thought Evaluated->False eliminated the need for that but as I say I cant test it. – george2079 Sep 25 '17 at 17:52