I am trying to compute numerically NSum[(-1)^n/n^3, {n, 1, Infinity}]
. Of course, using first Sum
would work here, but often it's not an option (no closed-form). I would like to compute the sum with an arbitrary number of digits.
So far, I've found that
NSum[(-1)^n/n^3, {n, 1, Infinity},
WorkingPrecision -> 24,
AccuracyGoal -> 24, PrecisionGoal -> Infinity]
will give only 16 digits (-0.9015426773696957
), whatever the value of WorkingPrecision
and AccuracyGoal
.
However, if I add the option Method -> "AlternatingSigns"
, I get as many digits as I want, and it's really controlled by WorkingPrecision
.
Among the other options, Method -> "EulerMaclaurin"
gives a wrong answer. Not all digits are correct, and there is an imaginary part: -0.901542677369695714049804 + 15.503138340149910087738157 I
.
And Method -> "WynnEpsilon"
also fails, giving -0.9015426773696957140
, even if I ask for more digits.
So, is there something I'm doing wrong? Is there a reason it does not work if I don't give a specific method? Is there a more straightforward way to compute a sum (or any numerical result, for that matter)?
And, since I'm quite interested by numerical computations with Mathematica and I'm a beginner (with Mathematica, not with numerical analysis :-)), is there a good guide out there ?
As an aside, I know Maxima better, and I'm used to the option fpprec
, that controls "bigfloat" evaluation in every computations. Is there something similar in Mathematica? I think it has a better control of accuracy, so maybe the question does not make sense (maybe there is no "global" setting).
To answer ciao's comment, since there is not much space in comments:
Actually, if I use larger values of the option NSumTerms
, I get more and more digits, but they don't agree with what I get with Method -> "AlternatingSigns"
:
NSum[(-1)^n/n^3, {n, 1, Infinity}, WorkingPrecision -> 50,
AccuracyGoal -> 50, PrecisionGoal -> Infinity, NSumTerms -> 5000]
-0.90154267736969571404980362113358749307373971926
NSum[(-1)^n/n^3, {n, 1, Infinity}, WorkingPrecision -> 50,
AccuracyGoal -> 50, PrecisionGoal -> Infinity,
Method -> "AlternatingSigns"]
-0.90154267736969378050491347983360150530995076960417
After 14 digits, they are different numbers.
And here it's possible to check:
Sum[(-1)^n/n^3, {n, 1, Infinity}] // N[#, 50] &
-0.90154267736969571404980362113358749307373971925537
So, the answer with Method -> "AlternatingSigns"
is also wrong!
And it's not better if I combine Method
and NSumTerms
options:
NSum[(-1)^n/n^3, {n, 1, Infinity}, WorkingPrecision -> 50,
AccuracyGoal -> 50, PrecisionGoal -> Infinity,
Method -> "AlternatingSigns", NSumTerms -> 5000]
-0.90154267736969571404546474460914681065800480608588
So the results differ after 20 digits.
Now I'm even more puzzled :-) I can see that your comment is right, since I get the right answer, but I absolutely don't understand why, and why the other methods fail without notification.
Also, it's not a very satisfying approach, since I can't set the number of accurate digits in the output (it depends on NSumTerms
in a non obvious way).
NSumTerms
is your friend... $\endgroup$Sum
andNSum
with theNSumTerms
-option deliver the same result (writeN[#, 47]&
) $\endgroup$"AlternatingSigns"
method. $\endgroup$