I am calculating the below formula: $$ \text{ER2}(\alpha,\text{K},\text{q})\text{:=}1+\sum _{m=0}^{K-1} \binom{K+\alpha }{m} \sum _{r=0}^m \frac{(-1)^r \binom{m}{r}}{\left(\frac{1}{q}\right)^{\alpha +K-m+r}-1}; $$ with the code:
ER2[α_, K_, q_] := 1 + Sum[Binomial[α + K, m]
Sum[Binomial[m,
r]*(-1)^r /((1/q)^(α + K + r - m) - 1), {r, 0, m}]
, {m, 0, K - 1}];
when $\alpha=0,K=268,q=0.1$. The code produced a negative number -7306.51.
But I know the answer is positive! And Maple produce 3.196969869 as expected.
I think it's the matter of cancellation error, so I tried to use SetPrecision:
ER2PP = SetPrecision[ER2[α, K, q], 50];
Mathematica complaints:
NSum::nslim: Limit of summation -1.00000000000000000000000000000000000000000000000000000000000+K is not a number.NSum::nslim: Limit of summation -1.00000000000000000000000000000000000000000000000000000000000+K is not a number.
NSum::nslim: Limit of summation -1.00000000000000000000000000000000000000000000000000000000000+K is not a number.
General::stop: Further output of NSum::nslim will be suppressed during this calculation.
Please help me to solve the problem, thanks!
ER2[0, 268, 1/10] // N. – b.gates.you.know.what Jan 21 '15 at 08:14ER2[0, 268, 0.1`40] // N, and it also produce an positive number. But I still can't understand why it's failed to use SetPrecision... – robit Jan 21 '15 at 08:20ER2[0, 268, 0.1\40] // N`. – robit Jan 21 '15 at 08:33SetPrecision[exp,p], according to the documentation, "yields a version of expr in which all numbers have been set to have precision p." Thus, it probably changes integer indices to real numbers, which may cause problems. What I find curious is that includingSetPrecisioninside the definition of ER2, either around the outerSumor the innerSum, produces no error messages but also computes the wrong answer to high precision. – bbgodfrey Jan 21 '15 at 11:37