I have this part of my code, which takes forever to run. Does anybody know how to make it faster?

Using NIntegrate I face error: "NIntegrate::eincr: The global error of the strategy GlobalAdaptive has increased more than 2000 times. The global error is expected to decrease monotonically after a number of integrand evaluations. Suspect one of the following: the working precision is insufficient for the specified precision goal; the integrand is highly oscillatory or it is not a (piecewise) smooth function; or the true value of the integral is 0. Increasing the value of the GlobalAdaptive option MaxErrorIncreases might lead to a convergent numerical integration. NIntegrate obtained 7.38363*10^-15-7.76592*10^-15 I and 5.976982225106196`*^-10 for the integral and error estimates."

ℓ0 = 3;
dvec = {Sin[2 Pi/2 Sin[θ]] Cos[ϕ - Pi/2], 
        Sin[2 Pi/2 Sin[θ]] Sin[ϕ - Pi/2], 
        Cos[2 Pi/2 Sin[θ]]}

σvec = {PauliMatrix[1], PauliMatrix[2], PauliMatrix[3]}

bhat = 1000 Abs[dvec].σvec

F = Table[
        1.*Conjugate[SphericalHarmonicY[ℓ0, i, θ, ϕ]] bhat SphericalHarmonicY[ℓ0, j, θ, ϕ], 
        {ϕ, 0, 2 π}, {θ, 0, π}
      {i, -ℓ0, ℓ0}, {j, -ℓ0, ℓ0}
  • 1
    $\begingroup$ Try NIntegrate . $\endgroup$ – Ulrich Neumann Jan 30 '19 at 19:27
  • 3
    $\begingroup$ There are two problems here: (i) spherical harmonics oscillate quite a lot and (ii) they are extraordinary slow in Mathematica... $\endgroup$ – Henrik Schumacher Jan 30 '19 at 19:29
  • $\begingroup$ even when I try NIntegrate it give me thie error: NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. $\endgroup$ – Delaram Nematollahi Jan 30 '19 at 19:32
  • 2
    $\begingroup$ If I compare Length[Union[Flatten[Simplify[Table[withoutintegrating],0<=ϕ<=2 π&&0<=θ<=π]]]] with Length[Flatten[Simplify[Table[withoutintegrating],0<=ϕ<=2 π&&0<=θ<=π]]] I see 30% of your integrands are duplicates. Might be even more if I removed constant multiples. Perhaps you might be able to take advantage of this to speed your problem up $\endgroup$ – Bill Jan 30 '19 at 22:39
  • 1
    $\begingroup$ You can replace Conjugate[SphericalHarmonicY[ℓ0, i, θ, ϕ]] with SphericalHarmonicY[ℓ0, i, θ, -ϕ]. $\endgroup$ – Roman Feb 7 '19 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.