# Evaluation in Manipulate [duplicate]

I have an expression assigned to a variable. For example:

exp1 = a*x+b


Now I would like to plot it using something like this

Manipulate[
Plot[Evaluate[ex99], {x, 0, 1}],
{a, 0, 1},
{b, 0, 1}]


I can see 'a' and 'b' being properly substituted by 'Evaluate', but Plot does not work as expected. I suspect it has something to do with 'x' substitution. How can I fix that? Thanks!

-

## marked as duplicate by Ajasja, Sjoerd C. de Vries, ssch, Artes, Simon WoodsMay 20 '13 at 12:08

Did you try Manipulate[Plot[a*x + b, {x, 0, 1}], {a, 0, 1}, {b, 0, 1}] ? – Rod May 20 '13 at 0:21
You could also try Manipulate[Plot[a*x+b,{x,0,1},AxesOrigin->{0, 0}],{a,-1,1},{b,-1,1}] in order to better see the results... – Rod May 20 '13 at 0:24
Even better IMO: Manipulate[Plot[a*x+b,{x,0,1},AxesOrigin->{0,0},PlotRange->{{0,1},{-2,2}}], {a,-1,1},{b,-1,1}] – Rod May 20 '13 at 0:29

Another alternative is to define the function using set delayed.

ex99[a_, b_, x_] := a*x + b;
Manipulate[Plot[ex99[a, b, x], {x, 0, 1}], {a, 0, 1}, {b, 0, 1}]


Now it works fine.

-

You could try this:

Manipulate[Plot[a*x+b,{x,0,1},AxesOrigin->{0,0},PlotRange->{{0,1},{-2,2}}], {a,-1,1},{b,-1,1}]

-
Of course in this simple example I can copy and paste the expression. In real world my exp1 is result of Integrate and quite complex. – krokodil May 20 '13 at 4:46
When you said "Plot does not work as expected" I thought you we're interested in showing how $a$ and $b$ would influence your plot... – Rod May 20 '13 at 9:58

Using CompoundExpression (a.k.a ";"), you can include expressions within Manipulate:

Manipulate[
ex99 = a x + b;
Plot[ex99, {x, 0, 1}],
{a, 0, 1},
{b, 0, 1}
]


The semicolon ";" is postfix notation for the CompoundExpression command, which has amongst other things the effect of evaluating the command in the kernel without producing output in the front end.

-