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?
Manipulate[Plot[f /. a -> a1, {x, 0, 10}], {a1, 0, 10}]– Kuba May 29 '14 at 06:45With[{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 -Manupulatehas "special" behavior... – ciao May 29 '14 at 06:46