How to Plot a Series

I would like to plot

f1[x_, n_] := Sum[Sin[(2 j - 1) x]/(2 j - 1), {j, 1, n}]


on a single plot containing f1(x,50), f1(x,100), f1(x,1000), with three different colored lines.

• Are j and k equal?! What x should be? – Mahdi Oct 1 '14 at 22:41
• Yes, j and k and equal. I must've input k instead of j at the end – Curious14 Oct 1 '14 at 22:42

f1[x_, n_] := Sum[Sin[(2 j - 1) x]/(2 j - 1), {j, 1, n}];
Plot[ f1[x, #] & /@ {50, 100, 1000}, {x, -Pi, Pi}, Evaluated -> True]


• Can you help me to understand what the input "f1[x, #] & /@ {50, 100, 1000}" means? Specifically the "#" and "& /@" – Curious14 Oct 1 '14 at 22:47
• @MathStudent, f1[x, #] & /@ {50, 100, 1000} is shorter way of writing {f1[x, 50],f1[x,100],f1[x,1000]}. See docs on Slot (#) and Map (/@) – kglr Oct 1 '14 at 22:49
• Nice plot, it shows the Gibbs phenomenon clearly. – xslittlegrass Oct 1 '14 at 22:52
• Thank you for the clarification! – Curious14 Oct 1 '14 at 22:56

Assuming that this the correct function:

f1[x_, n_] := Sum[Sin[(2 k - 1) x]/(2 k - 1), {k, 1, n}];


We can plot them by the following command:

Plot[f1[x, #] & /@ {50, 100, 1000}, {x, 0, Pi}, PlotLegends -> Placed[{"50", "100", "1000"}, {1.01, 0.5}]]


or equivalently:

Plot[{f1[x,50],f1[x,100],f1[x,1000]}, {x, 0, Pi}, PlotLegends -> Placed[{"50", "100", "1000"}, {1.01, 0.5}]]


for 0 to $\pi$.

• Your second plotting input is much easier to understand, where you commanded each of the plots. May you help me to understand what "{1.01, 0.5}" means? – Curious14 Oct 1 '14 at 22:51
• Yes! I use Placed command to put the legend at {1.01,0.5}. Mathematica assumes that the figure coordinates is {0,1} horizontally and vertically. So for example if write {0.5,0.5} legend will be right at the middle of figure. – Mahdi Oct 1 '14 at 23:09