1
$\begingroup$

I have the following function which I try to integrate:

lmbda0 = 132.19377;
a0 = 1.318;
Re0 = 2.235;
xe0 = a0*Re0;
alpha0 = 2 lmbda0 - 2 n0 - 1;

n0 = 5;

Plot[(Exp[
    0.5*(Log[n0!*alpha0] - Log[Gamma[2 lmbda0 - n0]]) + (lmbda0 - 
        n0 - 0.5) Log[2 lmbda0 Exp[-(a0*R - xe0)]] - 
     0.5 (2 lmbda0 *Exp[-(a0*R - xe0)]) + 
     Log[LaguerreL[n0, alpha0, 2 lmbda0 Exp[-(a0*R - xe0)]]]])^2
 , {R, 2, 2.5}]

Integrate[(Exp[
    0.5*(Log[n0!*alpha0] - Log[Gamma[2 lmbda0 - n0]]) + (lmbda0 - 
        n0 - 0.5) Log[2 lmbda0 Exp[-(a0*R - xe0)]] - 
     0.5 (2 lmbda0 *Exp[-(a0*R - xe0)]) + 
     Log[LaguerreL[n0, alpha0, 2 lmbda0 Exp[-(a0*R - xe0)]]]])^2, {R, 
  2, 2.5}]

The plot looks like what I would expect with reasonable values, however when I try to integrate it, I get lots of errors and usually an output of the integral itself where R is still a variable (even if I defined it as the integration variable, so it should work). Can someone tell me what I am doing wrong? Thank you!

$\endgroup$
2
  • $\begingroup$ Never use upper-case letters for variables, as they conflict with naming conventions of internal variables. $\endgroup$ Commented Nov 21, 2022 at 5:21
  • $\begingroup$ I tried replacing R with x, but I get the same result. Also, the plotting works fine with both R and x as variables. $\endgroup$
    – JohnDoe122
    Commented Nov 21, 2022 at 5:28

1 Answer 1

3
$\begingroup$

The expression that OP plots and integrates contains Exp of large numbers. One solution (in this case) is to organize things so that the expression is only evaluated when R is already numeric:

lmbda0=132.19377;
a0=1.318;
Re0=2.235;
xe0=a0*Re0;
alpha0=2 lmbda0-2 n0-1;

n0=5;

f[R_?NumericQ]:=(Exp[0.5*(Log[n0!*alpha0]-Log[Gamma[2 lmbda0-n0]])+(lmbda0-n0-0.5) Log[2 lmbda0 Exp[-(a0*R-xe0)]]-0.5 (2 lmbda0*Exp[-(a0*R-xe0)])+Log[LaguerreL[n0,alpha0,2 lmbda0 Exp[-(a0*R-xe0)]]]])^2;

NIntegrate[f[R],{R,2,2.5}]
(* 0.737361 *)

Plot[f[R],{R,2,2.5}]
(* like OP *)

Also note that I used NIntegrate.

$\endgroup$

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.