2 Answers
2

When you do solns = Table[y = Sin[x] + i, {i, -5, 5}], you are setting y=Sin[x]+i at each iteration; the last one is y=Sin[x]+5, so that is what y is.

If you instead do solns = Table[Sin[x] + i, {i, -5, 5}] and then ContourPlot[y == solns, {x, -5, 5}, {y, -5, 5}, FrameLabel -> Automatic] then you get y as a label, because now no value has been assigned to y.

Regarding it being an unintended consequence, y=expr explicitly sets y to expr; so if you do not intend this, then simply do not put y there. And as for this not being indicated, it is not indicated for the same reasons something like x=12 would not be; it just returns the value being assigned to x.

That is, what is effectively happening with something like Table[f[i],{i,1,10}] is that a loop is set up (with i localized, effectively with Block); at each iteration, f[i] is evaluated, and whatever it returns is appended to a list. In the end, the list is returned. Thus, if evaluating f[i] has side effects (such as assigning a value to y), you do not see that.

So in this case, you can think of Table[f[i], {i, 1, 10}] as equivalent to

I think acl answered your questions, but I'm curious why you chose to use ContourPlot to display your solution? Perhaps I'm simply not understanding what you're trying to accomplish, but does the following work for you?

In case it's not clear why this worked, MMA cycles through options like PlotStyle for each curve in the figure. If there's only one style, it will necessarily apply that style to each curve (because the "cycle" is only one curve long). If you do PlotStyle->{Blue,Red} instead, you'll see alternating Blue and Red curves, and similarly if you do PlotStyle->{Blue,Red,Green}.

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.