1
$\begingroup$

I'd like to plot something like this:

enter image description here

Except that instead of manually specifying all the functions to be plotted, I specify a range. So for example I could feed the command Range[0,6,2] to get it to plot four lines on the same plot, i.e. $\mathrm{Sin}[0],\mathrm{Sin}[2x],\mathrm{Sin}[4x]$ and $\mathrm{Sin}[6x]$.

How can I do this? I tried Plot[Sin[# x], {x, 0, 2 Pi}] & /@ Range[1, 3] which yields the desired three lines, but each in their own plot as opposed to one. Attempting to map twice with Plot[#, {x, 0, 2 Pi}] & /@ {Sin[# x] /@ Range[1, 3]} yields no plot at all.

$\endgroup$
3
$\begingroup$
Plot[Sin[# x] & /@ Range[1, 3] // Evaluate, {x, 0, 2 Pi}]
$\endgroup$
4
$\begingroup$

Note that Sin is Listable

Attributes[Sin]

(* {Listable, NumericFunction, Protected} *)

Plot[Evaluate@Sin[Range[3] x], {x, 0, 2 Pi},
 PlotLegends -> "Expressions"]

enter image description here

$\endgroup$
2
$\begingroup$

Try Show to combine the plots

Show[Plot[Sin[# x], {x, 0, 2 Pi}] & /@ Range[1, 3] ]

or

Plot[Table[Sin[om x], {om, Range[1, 3] }] // Evaluate, {x, 0, 2 Pi}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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