0

This is a followup to this question.

The following code Plot[{Sin[x], Sin[2 x], Sin[3 x]}, {x, 0, 2 Pi}] results in the following plot: enter image description here

The following code:

Plot [Table[Sin[i x], {i, 1, 3}], {x, 0, 2 Pi}]

Results in the following plot:

enter image description here

This is kind of strange, specifically since the output of Table[Sin[i x], {i, 1, 3}]

Equals {Sin[x], Sin[2 x], Sin[3 x]}

Are these not essentially identical expressions? Why is Mathematica not producing the same plot?

user32882
  • 227
  • 2
  • 6
  • 3
    Because the input is different. In the first plot you have 3 functions, in the second Table is interpreted as one. Wrap the Table in Evaluate, it will look the same as the first plot. –  Jan 11 '17 at 16:11
  • 2
    The difference is that Plot has the HoldAll attribute, so in the first case, Plot is fed something that is already a list of three expressions by the time Plot evaluates, while in the second case, the Table has not yet evaluated into a list of three expressions. Add Evaluate@ in front of Table to circumvent the HoldAll attribute. – Marius Ladegård Meyer Jan 11 '17 at 16:13
  • Indeed when I do this Plot [Evaluate[Table[Sin[i x], {i, 1, 3}]], {x, 0, 2 Pi}]. It comes out with the different colors. Thanks. – user32882 Jan 11 '17 at 16:20
  • Another possibie syntax is Plot[Table[Sin[i x], {i, 1, 3}], {x, 0, 2 Pi}, Evaluated -> True] – Carl Woll Jan 11 '17 at 17:51

0 Answers0