I'm trying to get this code working:
a = 2;
func[t_] := Dynamic[t + a];
Plot[func[t], {t, -5, 5}]
The idea is: I'd like to have the dynamic parameter a change the graph, without the need of actually re-evaluate the Plot
command after each change of the parameter a
. But this code delivers no plot printed on the screen. I've tried adding an Evaluate
command as well, without luck.
What am I missing of the Dynamic
command? Or where did I do something wrong?
Thank you all for your answers and your help!
Plot
is to be reevaluated dynamically as the current answers show -- that is, the user does not have to hit shift-enter. It is possible to do if you do not want the functionPlot
to be actually reevaluated every time the parametera
changes, but the result will likely be dissatisfying, unless your examplefunc
is exactly the function you want to use. $\endgroup$Graphics
output fromPlot
and remapping the coordinates to depend dynamically ona
. It seems a bad idea to me. SincePlot
makes choices depending onfunc
, you lose that. (The sample function could be done withGraphics@Dynamic@Line[{{-5, -5+a}, {5, 5+a}}]
, but I assume the OP has something more complicated in mind.) I haven't been able to imagine a situation in which this second method would be a real advantage. But technically, it should be possible. $\endgroup$