1
$\begingroup$

I have a problem with a numerical integration. I have a 4x4x4x4 array that has for each entry an integral and I want to use NIntegrate to evaluate it. It gives me no problem, it's actually pretty fast. But if I increase the size of the array to 9x9x9x9 I get this message:

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.

I increased the working precision already but it didn't help.

EDITED:

I put here a simplified version of my code:

B9b = Array[Nspher[#2, #4] &, {9, 9, 9, 9}, {1, 0, 1, 0}]

where

Nspher[l_, k_] := 
 NIntegrate[
  SphericalHarmonicY[l, 0, θ, φ] SphericalHarmonicY[k, 0, θ, φ]*Sin[θ],
  {θ, 0, π}, {φ, 0, 2 π},
  WorkingPrecision -> 50, AccuracyGoal -> 10, MaxRecursion -> 30]
$\endgroup$
  • $\begingroup$ Hmm, oscillatory and finite... try setting Method -> "ClenshawCurtisOscillatoryRule". $\endgroup$ – J. M. is away Jun 8 '13 at 11:36
  • $\begingroup$ @0x4A4D It didn't work $\endgroup$ – user24273 Jun 8 '13 at 11:39
  • $\begingroup$ I still do not understand why it works if the array is smaller and it doesn't if I increase the size. $\endgroup$ – user24273 Jun 8 '13 at 11:41
  • 1
    $\begingroup$ Could you be more descriptive? "Didn't work" tells me absolutely nothing on what might have gone wrong. Unless your actual integral does not in fact involve SphericalHarmonicY[]... $\endgroup$ – J. M. is away Jun 8 '13 at 11:42
  • 1
    $\begingroup$ Even so, you still have a separable integral; you can set things up so you have the product of two one-dimensional integrals, and that is a considerably easier task than multiple integration. $\endgroup$ – J. M. is away Jun 8 '13 at 12:00
1
$\begingroup$

Your example code seems to repeatedly evaluate the same integral many times. To see this, try changing Nspher as follows:

Nspher[l_, k_] := (Print[{l, k}]; 
  NIntegrate[
   SphericalHarmonicY[l, 0, \[Theta], \[Phi]] SphericalHarmonicY[k, 
     0, \[Theta], \[Phi]]*Sin[\[Theta]], {\[Theta], 
    0, \[Pi]}, {\[Phi], 0, 2 \[Pi]}, WorkingPrecision -> 50, 
   AccuracyGoal -> 10, MaxRecursion -> 30])

To fix it, use memoization:

Nspher[l_, k_] := 
 Nspher[l, k] = (Print[{l, k}]; 
   NIntegrate[
    SphericalHarmonicY[l, 0, \[Theta], \[Phi]] SphericalHarmonicY[k, 
      0, \[Theta], \[Phi]]*Sin[\[Theta]], {\[Theta], 
     0, \[Pi]}, {\[Phi], 0, 2 \[Pi]}, WorkingPrecision -> 50, 
    AccuracyGoal -> 10, MaxRecursion -> 30])

As for NIntegrate::slwcon, this message does not necessarily indicate an error. It is simply a report that the error estimate on a sub-region did not decrease as fast as it is expected to (eventually) decrease, assuming the function is nicely behaved. This can be a hint that better methods or other special handling can help you. If no other messages ensue, the result of NIntegrate is still likely to be good.

Using something like the above code, you can find out all/some of the specific values of {l, k} for which your computation is producing slwcon. For example, {l, k} == {2, 8} is one case. Investigate these, and once you are satisfied, you could Quiet slwcon or solve those cases in some other way.

$\endgroup$

Your Answer

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

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