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?
BDMAF[4.64782*10^14, 1, 1, 1]
and see, why it results in a non-numerical value. $\endgroup$NSum[]
andNIntegrate[]
are yielding somewhat conflicting results on my end... $\endgroup$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$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 withNIntegrate
insideNSum
. Case closed. Thank you for your attention. $\endgroup$