0
$\begingroup$

I have a complicated function as follows:

f[rp_] := (E^(-2 rp^2 \[Gamma]) M^2 norm^2 \[Pi]^(
     3/2) (E^((M \[Alpha] - 2 me rp \[Gamma])^2/(
        2 (M^2 \[Beta] + 
           me^2 \[Gamma]))) ((-1 + E^((4 M me rp \[Alpha] \[Gamma])/(
             M^2 \[Beta] + me^2 \[Gamma]))) M \[Alpha] + 
          2 (1 + E^((4 M me rp \[Alpha] \[Gamma])/(
             M^2 \[Beta] + me^2 \[Gamma]))) me rp \[Gamma]) + 
       E^((M \[Alpha] - 2 me rp \[Gamma])^2/(
        2 (M^2 \[Beta] + me^2 \[Gamma]))) (M \[Alpha] - 
          2 me rp \[Gamma]) Erf[(M \[Alpha] - 2 me rp \[Gamma])/(
         Sqrt[2] M Sqrt[\[Beta] + (me^2 \[Gamma])/M^2])] - 
       E^((M \[Alpha] + 2 me rp \[Gamma])^2/(
        2 (M^2 \[Beta] + me^2 \[Gamma]))) (M \[Alpha] + 
          2 me rp \[Gamma]) Erf[(M \[Alpha] + 2 me rp \[Gamma])/(
         Sqrt[2] M Sqrt[\[Beta] + (me^2 \[Gamma])/M^2])]))/(8 Sqrt[2]
      me rp \[Gamma] (M^2 \[Beta] + me^2 \[Gamma]) Sqrt[\[Beta] + (
      me^2 \[Gamma])/M^2]);

I want to do some calculations on f function to obtain my desire final number. In this vein I need to integrate over rp as follows $$ \int_{|re-r|}^{re+r} f(r_p) dr_p \tag{1} $$ As Mathematica can't solve (1) analytically, I have to use NIntegrate, but when I try (1) numerically

NIntegrate[f[rp], {rp, Abs[re - r], r + re}, {re, 0, \[Infinity]}, {r, 0, \[Infinity]}]

where the numerical values of constants are

me = 1;
mp = 1;
M = mp + me;
\[Omega] = 100;
\[Gamma] = SetPrecision[0.5*M*\[Omega], 50];
{\[Alpha], \[Beta]} = \
{0.407310205953620829699701744175399653613567352294921875`50., 
   24.586618270213069337160050054080784320831298828125`50.};
norm = 189.2253326188998254888908479720045476056553654261503687655661`\
49.454966552225144;

I get this error:

NIntegrate::nlim: rp = Abs[-1. r+re] is not a valid limit of integration.

So how can I solve my integral?! Any idea?

$\endgroup$
9
  • $\begingroup$ You doesn't show the call to NIntegrate: Perhaps re,r isn't defined yet? You should also provide numerical values for all the parameters! $\endgroup$ Nov 15, 2021 at 14:42
  • $\begingroup$ Please see the update $\endgroup$
    – Wisdom
    Nov 15, 2021 at 14:44
  • 2
    $\begingroup$ NIntegrate is a numerical function and needs numerical parameter values! $\endgroup$ Nov 15, 2021 at 14:48
  • $\begingroup$ the situation is the same when I add limits of re and r. Please see the update again $\endgroup$
    – Wisdom
    Nov 15, 2021 at 14:51
  • 1
    $\begingroup$ Have you defined numerical values for $\alpha$, $\beta$, $\gamma$, M, norm, and me? You haven't provided them in the code above, and NIntegrate definitely won't work if you don't. $\endgroup$ Nov 15, 2021 at 14:54

1 Answer 1

2
$\begingroup$

Changing the order of the integration seems to help. I'm not sure why; it probably has something to do with how Mathematica does its sampling. The documentation for NIntegrate says that "The first variable given [for the integration region] corresponds to the outermost integral and is done last", so it is plausible that the limits of the first integration variable must be numeric.

NIntegrate[f[rp], {re, 0, \[Infinity]}, {r, 0, \[Infinity]}, {rp, Abs[re - r], r + re}]

enter image description here

enter image description here

(* 3.98439 *)
$\endgroup$
1
  • $\begingroup$ Yes, perhaps the order of integration is matter for Mathematica, specially in this case where the limits of third variable is determined by the previous two! $\endgroup$
    – Wisdom
    Nov 15, 2021 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.