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.

Consider the following simple code:

f = Sin[a x];
  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:

   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];
  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?

share|improve this question

marked as duplicate by Simon Woods, Kuba, rasher, Sjoerd C. de Vries, gpap May 29 '14 at 10:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new 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... –  rasher 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