1

Instead of using Show[Plot[f[x]/.{L->1},{x,0,1}],Plot[f[x]/.{L->2},{x,0,1}], Plot[f[x]/.{L->3},{x,0,1}]], I was wondering if there is a much simpler way by using some sort of replacing rule. Something like Plot[f[x]/.{L->1,L->2,L->3},{x,0,1}], and have the three curves on the same plot. Does Mathematica support something like this?

2 Answers2

3

Amplifying on Alexei's answer

f[x_, L_] := (x/L)^2;

Either

Plot[Evaluate@Table[f[x, L], {L, {1, 2, 3}}], {x, 0, 1},
 PlotLegends -> Placed["Expressions", {.25, .75}]]

or

Plot[Evaluate[f[x, #] & /@ {1, 2, 3}], {x, 0, 1},
 PlotLegends -> Placed["Expressions", {.25, .75}]]

produce

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
2

Let us fix the function f for this example, say, this way:

f[x_, L_] := (x/L)^2;

Then try this:

Plot[f[x, #] & /@ {1, 2, 3}, {x, 0, 1}]

or this:

Plot[Table[f[x, L], {L, {1, 2, 3}}], {x, 0, 1}]

or this:

Plot[Thread[f[x, #] &[{1, 2, 3}]], {x, 0, 1}]

They all return the following plot:

enter image description here

Have fun!

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96