Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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


I've tried to do this:


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.

share|improve this question
up vote 8 down vote accepted

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

 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"}]

enter image description here

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]

enter image description here

share|improve this answer
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. – Voyska Jul 3 '12 at 1:53
Leonid Shifrin :) – Andreas Lauschke Jul 3 '12 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 ;-) – Yves Klett Jul 3 '12 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]

Mathematica graphics

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.

share|improve this answer
I always thought you would recommend (x Range@9)~(Plot[#1, #2, Evaluated -> True] &)~{x, 1, 10} :D – Dr. belisarius Jul 3 '12 at 2:54
@belisarius no, of course not! ... it doesn't localize x. ;^p – Mr.Wizard Jul 3 '12 at 3:17
I don't understand the meaning of "correctly localized". – Voyska Jul 3 '12 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] – Mr.Wizard Jul 3 '12 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}]


enter image description here

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

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


enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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