Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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}]
]

Mathematica graphics

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?

share|improve this answer

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}]
share|improve this answer

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}]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.