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?
Asked
Active
Viewed 77 times
1
Alejandro Marcos Aragon
- 339
- 2
- 9
2 Answers
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
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:
Have fun!
Alexei Boulbitch
- 39,397
- 2
- 47
- 96
-
2Recommend that you also include use of
Evaluateto distinguish between plots. – Bob Hanlon Sep 26 '18 at 14:34


{{L -> 1}, {L -> 2}, {L -> 3}}or take a look at Table etc. Related: 1731 – Kuba Sep 26 '18 at 11:59