# Manipulate fails with f[x]=x^k/(1+x^k)

I have this code:

Clear[f]
f = Function[x, x^k/(1 + x^k)];
Manipulate[Plot[f[x], {x, 0, 5}], {k, 1, 10}]


But nothing draws as I move the slider.

Am I missing something?

-

Manipulate has the attribute HoldAll and therefore f is not evaluated to your function. Therefore the expression with k is not visible for Manipulate.

Clear[f]
f = Function[x, x^k/(1 + x^k)];
With[{f = f},
Manipulate[Plot[f[x], {x, 0, 5}], {k, 1, 10}]
]


If you want to know, why With is one possible solution, you could check the following thread:

What are the use cases for different scoping constructs?

-

Try

Clear[f]
f = Function[{x, k}, x^k/(1 + x^k)];
Manipulate[Plot[f[x, k], {x, 0, 5}], {k, 1, 10}]


To see what is happening, do

Clear[f]
f = Function[{x, k}, x^k/(1 + x^k)];
Manipulate[f[x, k], {k, 1, 10}]


and

Clear[g]
g = Function[x, x^k/(1 + x^k)];
Manipulate[g[x], {k, 1, 10}]

-

Another option is to use Replace within the Manipulate

Clear[f]
f = Function[x, x^k/(1 + x^k)];
Manipulate[Plot[f[x] /. k -> k1, {x, 0, 5}], {k1, 1, 10}]

-