# Order of evaluation in NIntegrate

I have the following function of three variables:

sbbf[ω_,κ2_,g2_]:=(38.4 g2^2 Sqrt[κ2^2])/(16 g2^4 (1/100000000 +
4 ω^2) + (κ2^2 + 4 ω^2) (16 +
8 (1/10000 - 4 ω^2) + (1/100000000 + 4 ω^2) (1 +
4 ω^2)) +
8 g2^2 ((κ2 - 4 ω^2) (1/100000000 + 4 ω^2) +
4 (κ2/10000 + 4 ω^2))) + (9.6 (κ2^2 +
4 ω^2))/(16 g2^4 (1/100000000 +
4 ω^2) + (κ2^2 + 4 ω^2) (16 +
8 (1/10000 - 4 ω^2) + (1/100000000 + 4 ω^2) (1 +
4 ω^2)) +
8 g2^2 ((κ2 - 4 ω^2) (1/100000000 + 4 ω^2) +
4 (κ2/10000 + 4 ω^2))) + (0.0122 (16 g2^4 +
8 g2^2 (κ2 - 4 ω^2) + (1 +
4 ω^2) (κ2^2 + 4 ω^2)))/(16 g2^4 (1/
100000000 + 4 ω^2) + (κ2^2 + 4 ω^2) (16 +
8 (1/10000 - 4 ω^2) + (1/100000000 + 4 ω^2) (1 +
4 ω^2)) +
8 g2^2 ((κ2 - 4 ω^2) (1/100000000 + 4 ω^2) +
4 (κ2/10000 + 4 ω^2)))


I wish to integrate sbbf with respect to ω. I do the following:

T =
Table[{cc2,
NIntegrate[
Evaluate[(sbbf /. {g2 ->
Sqrt[ cc2]/2*Sqrt[κ1*κ2]}) /. { κ2 ->
10.}], {ω, -100, 100}]}, {cc2, 0, 100, 0.1}]


And I run into an error that says: the integrand sbbf has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,100}}. I proceed to look about this online and found something that seemed relevant from this article: http://support.wolfram.com/kb/12502

From what I can understand, it appears that the function is undefined for non-numeric values (perhaps κ2 and cc2?) and NIntegrate is unable to evaluate it. I think the solution is to reverse the order of evaluation (integrate only when the input constants are numeric). So I proceeded to do the following modification:

T[cc2_?NumericQ] :=
Table[{cc2,
NIntegrate[
Evaluate[(sbbf /. {g2 ->
Sqrt[ cc2]/2*Sqrt[κ1*κ2]}) /. { κ2 ->
10.}], {ω, -100, 100}]}, {cc2, 0, 100, 0.1}]


Unfortunately the above fix did not work and I suspected that I need more ?NumericQ for my other constants. So I did

T[cc2_?NumericQ, κ1_?NumericQ, κ2_?NumericQ, g2_?NumericQ]:= ...


For good measure but unfortunately that didn't work as well. I am quite lost at this moment and I could use any help that I can get.

• What you tried was sensible but there remains a symbolic κ1 in the input. Mar 11, 2018 at 16:27
• What is the value of κ1 supposed to be? Mar 11, 2018 at 16:27
• Apologies, [Kappa]1 goes to 1. I placed that right before [Kappa]2 -> 10 but it still didn't work. Mar 11, 2018 at 16:35
• sbbf by itself (without [args]) has not been defined. you should use sbbf[Sqrt[ cc2]/2*Sqrt[κ1*κ2],10.,w] Mar 11, 2018 at 16:47
• @george2079 I think what you meant was to put the first argument as w, followed by 10 for k2 and 'Sqrt[cc2*k1*k2]/2' (your order of argument is different from mine). But it worked without the need for defining ?NumericQ for my table T. Mar 11, 2018 at 17:07

You can try this, as you already have defined sbbf:
pts={#, NIntegrate[sbbf[\[Omega], 10, Sqrt[#]/2*Sqrt], {\[Omega], -100, 100}]} and by seeing the result, no need to use fine sampling in cc2`.