Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 want to sketch the graphs of $$u(t,x)=\frac{1}{2}+\sum_{n\geq 1} \frac{1}{n\pi} ((-1)^n-1)e^{-n^2t}\sin(nx)$$ for $t=0, 0.01, 0.1, 0.5, 1, 10$ on the same axes.

For $t=0$, I input

Plot[{1/2 + Sum[(1/n \[Pi]) ((-1)^n - 1) Sin [n x]], {n, 1, Infinity}}, {x, -\[Pi], \[Pi]}]

Then Mathematica keeps running...

Could you help me with this? Thanks.

share|improve this question
up vote 8 down vote accepted

If you define

f[x_, t_, nm_] := 1/2 + Sum[(1/n/ Pi) ((-1)^n - 1) Sin[n x] Exp[-t n^2], {n, 1, nm}];


Plot[Table[f[x, t, 150], {t, {0, 0.01, 0.1, 0.5, 1, 10}}] // Release, {x, -Pi, Pi}]


Mathematica graphics

and the "Gibbs ringing" i.e. the small oscillations near the sharp edges come from truncation of the sum at 150 instead of $\infty$.

Treating separately the t=0 case, which can be summed to infinity (see Sjoerd's answer), you can get a pretty accurate plot while choosing nm=1000

 1/2 + Sum[(1/n \[Pi]) ((-1)^n - 1) Sin[n x], {n, 1, Infinity}] // 
 Evaluate, {x, -\[Pi], \[Pi]},PlotStyle-> Darker[Blue,0.5]],
 1/2 + Sum[(1/n \[Pi]) Exp[-n^2 t] ((-1)^n - 1) Sin[n x], {n, 1, 
    1000}], {t, {0.01, 0.1, 0.5, 1, 10}}] // 
 Evaluate, {x, -\[Pi], \[Pi]}, PlotPoints -> 50]}]

Mathematica graphics

share|improve this answer
@J.M. sorry about the Release. I ll try and teach myself. – chris Nov 4 '12 at 15:27
Thank you so much! – Vladimir Nov 4 '12 at 15:35
I wasn't objecting to your use of Release[] at all... :) – J. M. Nov 4 '12 at 15:39

Your input contains a syntax error. You put the summation range outside the Sum. Another things that will improve plotting is adding an Evaluate, otherwise Plot will re-calculate the sum for every iteration.

  1/2 + Sum[(1/n \[Pi]) ((-1)^n - 1) Sin[n x], {n, 1, Infinity}] // Evaluate,
  {x, -\[Pi], \[Pi]}

Mathematica graphics

share|improve this answer
@chris This is the t=0 line of code that he reported keeps on running. For t=0 the Exp can be left away. – Sjoerd C. de Vries Nov 4 '12 at 15:15

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.