# Evaluation inside a Manipulate

Let's assume I have a symbolic expression, and inside a Manipulate I define the actual values:

myf = x + y;
Manipulate[myf, {x, 0, 1}, {y, 0, 1}]


doing this I don't obtain the sum of the numbers, so I did

Manipulate[Evaluate@myf, {x, 0, 1}, {y, 0, 1}]


and is fine, actual numbers are added up. If however I have more expressions:

Manipulate[{{Evaluate@myf}, {1 + Evaluate@myf}}, {x, 0, 1}, {y, 0, 1}]


Evaluate does not substitute the x and y with the actual values.

How can I solve this? More specifically: how to replace symbolic values with actual ones inside a Manipulate in the most general case? Hope to have been clear ...

• myf[x_, y_] := x + y; Manipulate[myf[x, y], {x, 0, 1}, {y, 0, 1}]? – Karsten 7. Oct 26 '15 at 20:46
• What is the actual problem you want to solve? Your example problem is easily solved by using a function myf[x_, y_] := x + y – paw Oct 26 '15 at 20:46
• I have a pretty complicated Manipulate, with the plot of a symbolic expression function of values set by the manipulate. I knew that the function is the best option but for some reason I can't manage to define the function (gives me an error), so I was trying with the symbolic expression ... – dario Oct 26 '15 at 20:51
• Could you present the actual code you are working on? Perhaps this would be a good start to get everyone on board. – e.doroskevic Oct 26 '15 at 21:51

Another way, to show how to use Evaluate, is to apply it to the whole first argument:

Manipulate[Evaluate@{{myf}, {1 + myf}}, {x, 0, 1}, {y, 0, 1}]


With functions like Manipulate that hold their arguments, one applies Evaluate to the whole argument to override the argument being held. When it is buried inside another function, even one like List, the Evaluate has no effect.

Best to define a function:

myf[x_, y_] := x + y;
Manipulate[myf[x, y], {x, 0, 1}, {y, 0, 1}]


Two different ways of injection:

Manipulate[{{#}, {1 + #}}, {x, 0, 1}, {y, 0, 1}] & @ myf


or

With[{myf = myf},
Manipulate[{{myf}, {1 + myf}}, {x, 0, 1}, {y, 0, 1}]
]

• works perfectly fine, thank you, but I accepted the answer from Michael since it came first – dario Oct 27 '15 at 11:42
• @dario The answer by Michael came last, but I don't mind. – Karsten 7. Oct 27 '15 at 13:42