How do I plot this on Mathematica version 5.2?
$\frac{4}{\pi} \sin{x} + \frac{4}{3 \pi} \sin{3 x} + \cdots + \frac{4}{(2 N+1) \pi} \sin{(2 N+1) x}$
over $x \in [-\pi,\pi]$ for $N= 3, 6, 12, 24$.
I tried and got this error:
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityThis seems to work fine:
f[x_, n_] := (4/Pi) Sum[Sin[(2 k + 1) x]/(2 k + 1), {k, 0, n}];
Plot[Table[f[x, n], {n, 5}], {x, -Pi, Pi}]
This is a documented behavior of Plot
in or before v5.2. Just click the More... button in the Plot::plnr
warning, you'll see the following explanation:
If
Plot
is used to plot a list of functions, that list should appear explicitly as the first argument inPlot
or should be introduced usingEvaluate
or other means.
together with a typical example:
So one solution is, as you've noticed, using Evaluate
:
f[x_, n_] := (4/Pi) Sum[Sin[(2 k + 1) x]/(2 k + 1), {k, 0, n}];
Plot[Table[f[x, n], {n, 5}] // Evaluate, {x, -Pi, Pi}]
It's not the only solution, of course. A few other solutions:
With[{table = Table[f[x, n], {n, 5}]}, Plot[table, {x, -Pi, Pi}]]
Plot[#, {x, -Pi, Pi}] &@Table[f[x, n], {n, 5}]
Plot @@ {Table[f[x, n], {n, 5}], {x, -Pi, Pi}}