4
$\begingroup$

Consider the following function with a numerical integration:

BDMAF[n_, γ_, x_, c_] := 
 Module[{K1 = EllipticK[1/Sqrt[1 + γ^2]], 
   E1 = EllipticE[1/Sqrt[1 + γ^2]], y0},
  y0 = ((π^2 (IntegerPart[x + 1] - x + n))/(2 K1 E1))^(1/2);
  Exp[-y0^2] NIntegrate[
    Exp[y^2] Sin[(n + IntegerPart[x + 1])/2 π + c y]^2, {y, 0, y0}]
  ]

that works perfectly if all parameters are explicitly defined:

BDMAF[1, 1, 1, 1]

0.0391914

I need to calculate the infinite sum over n. Naive approach gives

NSum[BDMAF[n, 1, 1, 1], {n, 0, ∞}]

NIntegrate::nlim: y = 1.38268 Sqrt[1. +n] is not a valid limit of integration. >>

Following the answer to the question about nested NIntegrate, I tried to redefine BDMAF as follows:

BDMAF[n_?NumericQ, γ_, x_, c_] := BDMAF[n, γ, x, c] = 
  Module[{K1 = EllipticK[1/Sqrt[1 + γ^2]], 
    E1 = EllipticE[1/Sqrt[1 + γ^2]], y0},
   y0 = ((π^2 (IntegerPart[x + 1] - x + n))/(2 K1 E1))^(1/2);
   Exp[-y0^2] NIntegrate[
     Exp[y^2] Sin[(n + IntegerPart[x + 1])/2 π + c y]^2, {y, 0, y0}]
   ]

The problem remains, but I receive another error message:

NSum[BDMAF[n, 1, 1, 1], {n, 0, ∞}]

NIntegrate::inumr: The integrand BDMAF(n,1,1,1) has evaluated to non-numerical values for all sampling points in the region with boundaries (15. 4.64782*10^14). >>

How BDMAF function should be defined?

$\endgroup$
9
  • $\begingroup$ The problem is your integral. Try to evaluate BDMAF[4.64782*10^14, 1, 1, 1] and see, why it results in a non-numerical value. $\endgroup$
    – halirutan
    Nov 4, 2012 at 13:56
  • $\begingroup$ You're sure this sum of yours converges? Some experimentation with various settings of NSum[] and NIntegrate[] are yielding somewhat conflicting results on my end... $\endgroup$ Nov 4, 2012 at 14:20
  • $\begingroup$ Table[BDMAF[n, 1, 1, 1], {n, 0, 120}] // ListLinePlot produces this i.stack.imgur.com/P0sRg.png which as @J.M. points out suggests slow convergence if any. $\endgroup$
    – chris
    Nov 4, 2012 at 15:32
  • $\begingroup$ Thanks. I rechecked the derivations and figured out that instead of Sin^2 there should be Cos^2. In this case the sum converges faster and everything works. It is strange that Mathematica did not show the message about the sum convergence. $\endgroup$ Nov 4, 2012 at 15:55
  • 1
    $\begingroup$ The problem was in the invalid testing series, that did not converge. Another sample series NSum[Exp[-Pi n] BDMAF[n, 1, 1, 1], {n, 0, Infinity}] which is closer to the original expression that I actually need converges perfectly, and works well with NIntegrate inside NSum. Case closed. Thank you for your attention. $\endgroup$ Nov 7, 2012 at 13:42

1 Answer 1

3
$\begingroup$

Problem was in the non-convergent sum. This example with the new sum works good:

BDMAF[n_?NumericQ, \[Gamma]_, x_, c_] := BDMAF[n, \[Gamma], x, c] = 
  Module[{K1 = EllipticK[1/Sqrt[1 + \[Gamma]^2]], 
    E1 = EllipticE[1/Sqrt[1 + \[Gamma]^2]], y0},
   y0 = ((\[Pi]^2 (IntegerPart[x + 1] - x + n))/(2 K1 E1))^(1/2);
   Exp[-y0^2] NIntegrate[
     Exp[y^2] Sin[(n + IntegerPart[x + 1])/2 \[Pi] + c y]^2, {y, 0, y0}]
   ]

NSum[Exp[-Pi n] BDMAF[n, 1, 1, 1], {n, 0, Infinity}]

Thanks for your attention.

$\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.