Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm a beginner at Mathematica. I would like to plot the following function:

$${n\over2} \sum_{j\ge1} 2^{-j}(1-2^{-j})^{n-1}$$

However the following code is just too slow:

Plot[n/2 NSum[2^(-j) (1 - 2^(-j))^(n - 1), {j, 1, Infinity}], {n, 1, 100}]

I think it may be trying to expand the $(n-1)$th power symbolically instead of numerically. How can I fix that?

share|improve this question
You can try giving the following options to Plot, and tweak them until you have a good speed/quality trade-off: PlotPoints -> 10, MaxRecursion -> 3 If you search the site for those options you'll find more in-depth explanations and examples :) – ssch Apr 6 '13 at 14:36
up vote 8 down vote accepted

If you know in advance that your sum is already convergent, you can skip the convergence check. Also, it sometimes helps to change the Method used by NSum[]. Here, I use the Shanks transformation as the summation method:

Plot[n/2 NSum[2^(-j) (1 - 2^(-j))^(n - 1), {j, 1, ∞}, 
              Method -> {"WynnEpsilon", Degree -> 2, "ExtraTerms" -> 30}, 
              NSumTerms -> 50, VerifyConvergence -> False], {n, 1, 100}, 
     Frame -> True, PlotRange -> {0.72, 0.724}]

plot of the sum

share|improve this answer
Much faster, thanks! – Ricbit Apr 6 '13 at 15:20

This is an approximation, but the result is immediate calculating over the integers:

f[n_] := Sum[2^(-j) (1 - 2^(-j))^(n - 1), {j, 1, Infinity}]

DiscretePlot[n/2 f@n, {n, 1, 101}, Joined -> True, PlotRange -> {0.72, 0.724}]

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.