One shouldn't expect a general method which might be comparable to NSum
, which is universal on one side and very fast on the other side (Options[ NSum, Compiled]
gives {Compiled -> Automatic}
). Other methods can be faster only for very specific series or special data. NSum
yields estimated results but we can alwas make them arbitrarily precise. There are adequate tools in numerical functionality like e.g. AccuracyGoal
to reach appropriate accuracy. See this answer for a more detailed discussion related to the main issue. It appears that Silvia's and Mr.Wizard's methods seem to be more handy for this specific problem, but if you try e.g. finding the minimal n
which satisfies
$\frac{1}{2}+\frac{1}{2+\sqrt{2}}+...+\frac{1}{n+\sqrt{n}}>30$ then you'll have to work with appropriately increased WorkingPrecision
(the default value Options[NSum, WorkingPrecision]
is MachinePrecision
, i.e. its numerical value $MachinePrecision
is 15.9546
). Accumulate
wouldn't be a good approach since you'd have to sum up roughly 5 10^13
terms.
This series is obviously not convergent :
SumConvergence[ 1/(k + Sqrt[k]), k]
False
i.e. you might explore analogical issue for any positive number not just (15
or 30
).
To find n
for the sum > 15
we can try a few parameters, first we check NSum[1/(k + Sqrt[k]), {k, 10^7}]
then we slightly decrease the upper limmit of summation and we end up with very accurate result :
FindRoot[ 15 - NSum[1/(k + Sqrt[k]), {k, x},
WorkingPrecision -> 50, AccuracyGoal -> 25, NSumTerms -> 10^3],
{x, 9881300, 9881500}, WorkingPrecision -> 20, AccuracyGoal -> 10] // Quiet
{x -> 9.8813293871411276453*10^6}
Thus we have a candidate n0 == 9881329
. Let's increase NSumTerms
decreasing WorkingPrecission
:
NSum[ 1/(k + Sqrt[k]), {k, #}, WorkingPrecision -> 30, AccuracyGoal -> 15,
NSumTerms -> 10^5] & /@ {9881329, 9881330}
{14.9999999608590703242577, 15.0000000620278381114430}
One might ensure that n == 9881330
increasing as well NSumTerms
up to 10^7
.
If we apply directly Silvia's method myfunc
to determine the minimal n
such that the sum is > 25
we find that n == 217788342012
which is incorrect. Mr.Wizard's methods are even worse here. Therefore we can proceed analogically as before by trial and error. It brings us to this conclusion :
NSum[ 1/(k + Sqrt[k]), {k, #}, WorkingPrecision -> 50, AccuracyGoal -> 25,
NSumTerms -> 10^5] & /@ {217788341981, 217788341982}
{24.99999999999638162229253940380424, 25.00000000000097322645325278931633}
Thus we've found n[25] == 217788341982.
NSum
as you're wasting time calculating sums you already have. Is it acceptable to identify a range, say 9x10^6 through 10^7, then dodata = NestList[{#[[1]] + 1, #[[2]] + 1./(#[[1]] + 1 + Sqrt[#[[1]] + 1])} &, {9 10^6, NSum[1.0/(i + Sqrt[i]), {i, 900000}] - 15}, 10^6];
? This is very fast and you can then inspectdata
. $\endgroup$NSum
. Read e.g. my comment to Mr.Wizard's answer. Of course there can be alwas some improvements, nevertheless in general, you can't substituteNSum
with anything else. $\endgroup$