# Help on evaluation control?

I want to plot series of slopes:

x, 2x, 3x, 4x, 5x, 6x...

I'm trying to do this:

a = Range[10]; c = 0; Clear[b]
f := ToExpression[ToString[b] <> ToString[a[[c = c + 1]]]]


So everytime I input f, it gives me:

b1
b2
b3
b4
...


Now I want to assign every bn to one of the plots:

b1=Plot[x,{x,1,10}]
b2=Plot[2x,{x,1,10}]
b3=Plot[3x,{x,1,10}]
b4=Plot[4x,{x,1,10}]
...


I've tried to do this:

f=Plot[x,{x,1,10}]


But It will only switch the variable from the first fuction to the Plot function. How can I do to the fbecome b1 first and then the b1 be assigned to the Plot function? I guess it has something to do with evaluation control, something like that.

NOTE:. The ? in the title means that I'm not very sure If it's about evaluation control.

I thought a minimal code can make a nice visualization of it:

Manipulate[
Plot[Evaluate[{Range[n] x, n x}], {x, -2, 10}, PlotStyle -> Thick,
PlotRange -> {{-2, 10}, {-20, 50}}, Filling -> 0]
, {{n, 0, "slope"}, 0, 10, Appearance -> "Labeled"}]


If on the other hand you would like to plot all slopes separately, this could do:

GraphicsGrid[Partition[Plot[# x, {x, -2, 5}, Frame -> True,
AxesStyle -> Directive[Gray, Thick], PlotStyle -> Thick,
PlotRange -> {{-2, 5}, {-30, 80}},
PlotLabel -> "Slope = " <> ToString[#]] & /@ Range[16], 4],
ImageSize -> 900]


• Oh, It's because I'm still a little afraid of using the #'s and && and all that pattern stuff. I'm reading Leonard Shinfrin's book now. Commented Jul 3, 2012 at 1:53
• Leonid Shifrin :) Commented Jul 3, 2012 at 1:57
• Although Leonard evokes associations with actors that play pointy-eared highly competent aliens, which somehow resonates (in a very positive, awe-inspiring way) with my impression of Leonid ;-) Commented Jul 3, 2012 at 12:46

Once again I shall recommend a different form for evaluating the first argument of Plot:

Plot[x Range[9], {x, 1, 10}, Evaluated -> True]


Though the option Evaluated is undocumented it is superior because it works even if x has a global value, whereas Plot[Evaluated[ . . . ], . . .] will not. That is, the Plot variable is correctly localized.

• I always thought you would recommend (x Range@9)~(Plot[#1, #2, Evaluated -> True] &)~{x, 1, 10} :D Commented Jul 3, 2012 at 2:54
• @belisarius no, of course not! ... it doesn't localize x. ;^p Commented Jul 3, 2012 at 3:17
• I don't understand the meaning of "correctly localized". Commented Jul 3, 2012 at 6:29
• @Gustavo when you enter something like x = 7; Plot[Sin[x], {x, 0, 2 Pi}] it still works because x is localized by Plot. If you use Evaluate this breaks; e.g. x = 7; Plot[Evaluate@Sin[x], {x, 0, 2 Pi}] you get a single horizontal line because you are effectively doing Plot[Sin[7], {x, 0, 2 Pi}]. On the other hand, Evaluated -> True localizes x before evaluation: x = 7; Plot[Sin[x], {x, 0, 2 Pi}, Evaluated -> True] Commented Jul 3, 2012 at 6:34

It's slightly simpler if you're willing to use b[1] instead of b1:

Do[b[i] = Plot[i x, {x, 1, 10}],{i, 10}]

b[3]


If you're really keen on using b1, you can do something like:

Do[
Set[Evaluate[Symbol["b" <> ToString[i]]],
Plot[i x, {x, 1, 10}]],
{i, 10}]

b3