# Problem with the Plot of Functions and PlotLegends

For some odd reason the PlotLegends output is not as expected.

Clear[f, g, v]
v = Function[x, k*x^-k];
g = Function[x, (x^-k)*Sin[x^k]/(1 + x^k)];
f = Function[x, x^k/(1 + x^k)];
With[{f = f, g = g},
Manipulate[Plot[{v[x], f[x], g[x], D[f[x] - g[x]]}, {x, 0, 5},
PlotLegends -> "Expressions"], {k, 1, 10}]]


-
What specifically is wrong with the output? – whuber May 20 '13 at 19:38
I have to clarify that there is nothing wrong with the geometry of the function. The problem is the legend. The expression is rendered all wrong, – Jose E Calderon May 21 '13 at 4:17
@JoseECalderon: There is an answer that most probably solves your problem already, but I think your question would be much better if you state what it is that you expect (or more precisely want) to get from that input. I understand that the output is not what you want, but it seems to be what can be expected with some knowledge about the evaluation order and scoping quirks of Mathematica (where the latter is IMHO not exactly its strongest part)... – Albert Retey May 21 '13 at 10:10

The expression that is plotted in the legend are the provided pure functions (with some scoped internal variable names). PlotLegends is somewhat confused so we have to provide explicit entries for the Legend. Since the desired result is somewhat unclear here a few suggestions:

v[x_, k_] := k*x^-k;
g[x_, k_] := (x^-k)*Sin[x^k]/(1 + x^k);
f[x_, k_] := x^k/(1 + x^k);
Manipulate[Plot[{v[x, k], f[x, k], g[x, k], D[f[x, k] - g[x, k]]}, {x, 0, 5},
PlotLegends -> "Expressions"], {k, 1, 10}]


or, with the explicit expressions:

Manipulate[Plot[{v[x, k], f[x, k], g[x, k], D[f[x, k] - g[x, k]]}, {x, 0, 5},
PlotLegends -> TraditionalForm /@ {v[x, k], f[x, k], g[x, k],
D[f[x, k] - g[x, k]]}],
{k, 1, 10}]


-