Integration Problem in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter EngWiPy
  • Start date Start date
  • Tags Tags
    Integration Mathematica
Click For Summary

Discussion Overview

The discussion revolves around evaluating a complex integral numerically in Mathematica, specifically focusing on the integration of an expression involving exponential and Bessel functions as a function of the variable s. Participants explore methods for setting up the numerical integration and address issues related to variable assignments and errors encountered during the process.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant presents an integral to be evaluated numerically and seeks guidance on how to implement it in Mathematica.
  • Another participant suggests a structure for the function f[s_] using NIntegrate, emphasizing the need for all variables except x and s to have numerical values.
  • Further elaboration on the integration process includes a specific example of an integrand, but the participant encounters errors indicating non-numerical values during evaluation.
  • Concerns are raised about the variable n not having a value, prompting suggestions to assign values to all variables to avoid errors.
  • One participant proposes simplifying the problem to isolate the issue, but still encounters errors related to the variable s.
  • A suggestion is made that s must be assigned a value within the integration function to avoid errors, and an example is provided to illustrate this approach.
  • Another participant expresses the complexity of the integral and the need to multiply the result by another function of s before integrating over s, indicating the integral is part of a larger equation involving multiple summations.

Areas of Agreement / Disagreement

Participants generally agree on the necessity of assigning numerical values to variables within the integration to avoid errors. However, there are differing views on the specific challenges posed by the variable s and the complexity of the integral, indicating that the discussion remains unresolved regarding the best approach to handle these issues.

Contextual Notes

Limitations include unresolved variable assignments and the complexity of the integral, which may depend on specific values for parameters that have not been established in the discussion.

EngWiPy
Messages
1,361
Reaction score
61
Hello,

I have the following integration:

[tex]\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[/tex]

I want this integral to be evaluated numerically in Mathematica as a function of [tex]s[/tex], 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 different 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 ·
Replies
1
Views
2K
  • · Replies 14 ·
Replies
14
Views
5K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
7K