3
$\begingroup$

Is it possible to speed up the calculation of the Kx integral?

ClearAll["Global`*"]

Psi1[r_, z_] := Exp[-2*z^2]*(Exp[-1.3*r^2] + Exp[-4*r^2] + Exp[-2.3*r^2]);
NN = 1/Sqrt[Integrate[Psi1[r, z]*Psi1[r, z]*r*2*Pi, {r, 0, Infinity}, {z, -Infinity, Infinity}]];
Psi[r_, z_] := NN*Psi1[r, z];

Kk[r_, z_] := FullSimplify[Psi[r, z]*Laplacian[Psi[r, z], {r, \[Theta], z}, "Cylindrical"]*r*2*Pi];
Kx = -(1/2)*Integrate[Kk[r, z], {r, 0, Infinity}, {z, -Infinity, Infinity}] //Timing

Out[42]= {5.375, 3.06865}
$\endgroup$

2 Answers 2

6
$\begingroup$

Using for general:

$$\text{Psi1}(r,z)=\exp \left(-a z^2\right) \left(\exp \left(-b r^2\right)+\exp \left(-c r^2\right)+\exp \left(-d r^2\right)\right)$$

then we have:

Kx = -((b c (b + c) d (b + d) (c + 
  d) (2 (-3 - (8 b c)/(b + c)^2 + (8 b^2)/(b + d)^2 - (8 b)/(
     b + d) - (8 c d)/(c + d)^2) + 
  a (-(1/b) - 1/c - 4/(b + c) - 1/d - 4/(b + d) - 4/(c + d))))/(
2 (c^2 d^2 (c + d) + b^3 (c^2 + 6 c d + d^2) + 
  b^2 (c + d) (c^2 + 15 c d + d^2) + 
  2 b c d (3 c^2 + 8 c d + 3 d^2))));

a = 2; b = 13/10; c = 4; d = 23/10;

Kx
(*161819640529/52733231019*)
% // N
(*3.06865*)
$\endgroup$
1
  • $\begingroup$ Thanks, for useful answer! $\endgroup$
    – Mam Mam
    Mar 21, 2023 at 16:36
5
$\begingroup$
Clear["Global`*"];

Psi1[r_, z_] := Exp[-2*z^2]*(Exp[-1.3*r^2] + Exp[-4*r^2] + Exp[-2.3*r^2]);
NN = 1/Sqrt[
    Integrate[
     Psi1[r, z]*Psi1[r, z]*r*2*Pi, {r, 0, Infinity}, {z, -Infinity, 
      Infinity}]];
Psi[r_, z_] := NN*Psi1[r, z];

Putting FullSimplify on the RHS of SetDelayed results in the simplification being used for every call to Kk. Use Set to do the simplification only once

Kk[r_, z_] = 
  FullSimplify[
   Psi[r, z]*Laplacian[Psi[r, z], {r, θ, z}, "Cylindrical"]*r*2*Pi];

Note that the timing should be isolated from the definition of Kx

(Kx = -(1/2)*
    Integrate[
     Kk[r, z], {r, 0, Infinity}, {z, -Infinity, Infinity}]) // AbsoluteTiming

(* {3.86644, 3.06865} *)

Since you introduced a machine precision number in the definition of Psi1, your calculations are done with machine precision. Since you are not concerned about precision, you can speed it up more by just using NIntegrate

(Kx = -(1/2)*
    NIntegrate[
     Kk[r, z], {r, 0, Infinity}, {z, -Infinity, Infinity}]) // AbsoluteTiming

(* {0.011498, 3.06865} *)
$\endgroup$
1
  • $\begingroup$ Thanks, for useful answer! $\endgroup$
    – Mam Mam
    Mar 21, 2023 at 16:35

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.