How can I plot the two functions below with same color for each value of k?
Evaluate the complete plot-argument:
Show[Map[Plot[ {vest[#, M], bb[#, M]},{M,0, 1},Evaluated -> True,
PlotStyle -> RGBColor[#/Max[k],0,1-#/Max[k]]] &, k], PlotRange -> All]
m = 10^-3;
k = {1, 5, 10, 25};
ron = 50m;
dcr = k ron;
vest[k_, M_] := k ron + (2 + (-1 + M) M (5 + M)) ron/(-1+M)^2;
bb[k_, M_]:= (2 ron+k ron);
Plot[
Evaluate @ Flatten @ {Map[{vest[#,M],bb[#,M]}&]@k}]
,{M,0,1}
,PlotStyle-> {Green,Green,Red,Red,Blue,Blue,Orange,Orange}
]
Another possibility is to use Style
wrappers around the individual functions. This enables you to have both data and appearance specified in the same place:
m = 10^-3;
k = {1, 5, 10, 25};
ron = 50 m;
vest[k_, M_] := k ron + ((2 + (-1 + M) M (5 + M)) ron)/(-1 + M)^2;
bb[k_, M_] := M (2 ron + k ron);
Plot[
Evaluate[
Style[
{vest[#, M], bb[#, M]},
ColorData["Rainbow"][#/Max@k]
] & /@ k
],
{M, 0, 1}
]
Note the use of Evaluate
, similar to the other answers.