0

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?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78
  • Your last example is the standard way to do what you want. Why do you object to it? – m_goldberg May 29 '14 at 05:31
  • Manipulate[Plot[f /. a -> a1, {x, 0, 10}], {a1, 0, 10}] – Kuba May 29 '14 at 06:45
  • 1
    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 06:46
  • @kuba I know this trick but again I will need to replace all manipulating variables. – Basheer 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. – Basheer Algohi May 29 '14 at 15:13

0 Answers0