Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 7 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
add comment

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
add comment

Your Answer

 
discard

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.