# Integration Problem in Mathematica

• Mathematica

## Main Question or Discussion Point

Hello,

I have the following integration:

$$\int_0^{\infty}\text{e}^{-\gamma(p+s)}\gamma^a(\gamma^2+\gamma)^{b/2}K_b\left(\beta\sqrt{\gamma^2+\gamma}\right)\,d\gamma$$

I want this integral to be evaluated numerically in Mathematica as a function of $$s$$, how can I do that?

Regards

Related MATLAB, Maple, Mathematica, LaTeX News on Phys.org
CompuChip
Homework Helper
Something like:

f[s_] := NIntegrate[ Exp[-x(p + s)] ... /. {p -> NumericalValueForP, a -> NumericalValueForA, b -> NumericalValueForB}, {x, 0, Infinity}]

(where you need to make sure that all variables except x and s have a numerical value inside the integration)?

Something like:

f[s_] := NIntegrate[ Exp[-x(p + s)] ... /. {p -> NumericalValueForP, a -> NumericalValueForA, b -> NumericalValueForB}, {x, 0, Infinity}]

(where you need to make sure that all variables except x and s have a numerical value inside the integration)?
I wrote it as:

Code:
NIntegrate[
E^(-g ((gB*(j2 + 1) + gA*(j1 + 1))/(gA*gB) + s))*g^(
NA + k2 + p + m - n - 1)*(g^2 + g)^((n - m + 1)/2)*
BesselK[(n - m + 1),
N[2*Sqrt[((g^2 + g) (j1 + 1) (j2 + 1))/(gA*gB)]]] , {g, 0,
Infinity} /. s -> gp/Sin[y]^2
where all variables has numerical values except g and s, but it gives me the following error:

Code:
NIntegrate::inumr: The integrand \[ExponentialE]^(-g (4.+s)) \
Sqrt[g+g^2] BesselK[1,4. Sqrt[g+g^2]] has evaluated to non-numerical \
values for all sampling points in the region with boundaries {{\
\[Infinity],0.}}. >>

NIntegrate::inumr: The integrand \[ExponentialE]^(-g (4.+s)) \
Sqrt[g+g^2] BesselK[1,4. Sqrt[g+g^2]] has evaluated to non-numerical \
values for all sampling points in the region with boundaries {{\
\[Infinity],0.}}. >>

NIntegrate::inumr: The integrand \[ExponentialE]^(-g (4.+s)) g^-n \
(g+g^2)^((1+n)/2) BesselK[1+n,4. Sqrt[g+g^2]] has evaluated to \
non-numerical values for all sampling points in the region with \
boundaries {{\[Infinity],0.}}. >>

General::stop: Further output of NIntegrate::inumr will be suppressed \
during this calculation. >>
Regards

CompuChip
Homework Helper
Are you sure about that? It looks like n, for one, does not have a value (I see it in your output).

Try something like
Code:
Block[{g = 1},
N[ yourIntegrand ]
]
and check if it gives a number. If it gives an expression, assign a value to the variable names you still see and repeat until you get a number :)

Are you sure about that? It looks like n, for one, does not have a value (I see it in your output).

Try something like
Code:
Block[{g = 1},
N[ yourIntegrand ]
]
and check if it gives a number. If it gives an expression, assign a value to the variable names you still see and repeat until you get a number :)
Actually, it is not that easy, since the integral inside multiple summations, and in for loop. But strange, all other summation indices like n have no problem, but why n has problem? Let us make the problem easier as in the following code:

Code:
NIntegrate[
E^(-g*s)*g^2*(g^2 + g)^(3/2)*BesselK[3, 2 Sqrt[g^2 + g]], {g, 0,
Infinity}]
this code gives me the following error:

Code:
NIntegrate::inumr: The integrand \[ExponentialE]^(-g s) g^2 \
(g+g^2)^(3/2) BesselK[3,2 Sqrt[g+g^2]] has evaluated to non-numerical \
values for all sampling points in the region with boundaries {{\
\[Infinity],0.}}. >>
What is the problem? Is it the s variable? If yes, how to generate a function of s from this integral?

Regards

CompuChip
Homework Helper
In the integration s needs to have been assigned a value.
As I suggested in my original post, you can accomplish this by writing
Code:
f[s_] := NIntegrate[
E^(-g*s)*g^2*(g^2 + g)^(3/2)*BesselK[3, 2 Sqrt[g^2 + g]], {g, 0,
Infinity}]
Then when you evaluate, for example, f[0], it will perform the NIntegrate with s replaced by 0. The numerical integration is sufficiently fast that for example
Code:
Plot[f[x], {x, 0, 10}]
works perfectly.

In the integration s needs to have been assigned a value.
As I suggested in my original post, you can accomplish this by writing
Code:
f[s_] := NIntegrate[
E^(-g*s)*g^2*(g^2 + g)^(3/2)*BesselK[3, 2 Sqrt[g^2 + g]], {g, 0,
Infinity}]
Then when you evaluate, for example, f[0], it will perform the NIntegrate with s replaced by 0. The numerical integration is sufficiently fast that for example
Code:
Plot[f[x], {x, 0, 10}]
works perfectly.
Let me explain my problem well, as you can see this integral is a complicated one, and I couldn't solve it in closed form, so I have no choice but numerical integration. What I suppose to do is to multiply f(s) which is the result of this integral by another function of s, say g(s), and then integrate over s.

Again this integral is just a sample of long equation which is multiple summations of this integral with differnt parameters, so I need to find the whole function in term of s, multiply it with another, simpler function of s, and then integrate over s.

Regards