# Scoping problem with Manipulate [duplicate]

Consider the following simple code:

f = Sin[a x];
Manipulate[
Plot[f, {x, 0, 10}],
{a, 0, 10}]


Manipulate takes f to be a variable which has no value.

I tried to evaluate f as follows:

 Manipulate[
Plot[Evaluate @ f, {x, 0, 10}],
{a, 0, 10}]


but now I still have a problem with the scope of a.

I know one way to do what I want, which is to define f as a function of a as follows:

f[a_] := Sin[a x];
Manipulate[
Plot[f[a], {x, 0, 10}],
{a, 0, 10}]


But what if I have many variables and I want to manipulate over all of them? Is there any way to make Manipulate substitute f by its value and take all of its symbols as a variables to be manipulated?

-

## marked as duplicate by Simon Woods, Kuba, ciao, Sjoerd C. de Vries, gpapMay 29 '14 at 10:18

This question was marked as an exact duplicate of an existing question.

Your last example is the standard way to do what you want. Why do you object to it? – m_goldberg May 29 '14 at 5:31
Manipulate[Plot[f /. a -> a1, {x, 0, 10}], {a1, 0, 10}] – Kuba May 29 '14 at 6:45
With[{f=f},Manipulate[...]]. But why bother? Just do it with a proper function as m_goldberg notes. This (and other scoping tricks) are either not needed, bad form, or asking for trouble in most cases. In any case, read the documentation - Manupulate has "special" behavior... – ciao May 29 '14 at 6:46
@kuba I know this trick but again I will need to replace all manipulating variables. – Algohi May 29 '14 at 15:07
@rasher Thanks. With does the trick. I need this because I have a function in which it will take to much time to be evaluated each time I change the manipulating variables. – Algohi May 29 '14 at 15:13