Mathematica Integration Problem in Mathematica

AI Thread Summary
The discussion focuses on evaluating a complex integral in Mathematica, specifically the integral involving an exponential function and a Bessel function. Users are encountering errors related to non-numerical values during the numerical integration process, particularly when variables such as 'n' and 's' lack assigned numerical values. It is suggested that all variables except for the integration variable must have numerical values for successful evaluation. A proposed solution involves defining a function that incorporates the integral and allows for the substitution of 's' with specific numerical values. The aim is to ultimately multiply the result of this integral by another function of 's' and perform a further integration over 's'.
EngWiPy
Messages
1,361
Reaction score
61
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
 
Physics news on Phys.org
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)?
 
CompuChip said:
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
 
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 :)
 
CompuChip said:
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
 
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.
 
CompuChip said:
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
 

Similar threads

Replies
1
Views
1K
Replies
14
Views
3K
Replies
4
Views
3K
Replies
13
Views
2K
Replies
2
Views
2K
Replies
19
Views
2K
Replies
2
Views
2K
Replies
2
Views
2K
Replies
6
Views
7K
Back
Top