2
$\begingroup$

I am studying Dynamic and DynamicModule, and I have tried to make a simple plot of a family of real functions. The number of functions should be a dynamic variable controlled by a slider. So I have tried something like this

{Slider[Dynamic[z], {1, 4, 1}], Plot[Evaluate[Dynamic[Table[Sin[i*t], {i, 1, z}]]], {t, 0, 2 Pi}]}

In this case variable t is highlighted in red and the output is empty. But if you do it outside of Plot[], then you get a correct list of functions

{Slider[Dynamic[z], {1, 4, 1}], Evaluate[Dynamic[Table[Sin[i*t], {i, 1, z}]]]}

So, how one plots this kind of things?

$\endgroup$
4
$\begingroup$

The Plot has to be within Dynamic, as the Plot needs to be updated when z is changed. You can't just update the content of Plot without making a new Plot.

{Slider[Dynamic[z], {1, 4, 1}], 
 Dynamic@Plot[Evaluate[Table[Sin[i*t], {i, 1, z}]], {t, 0, 2 Pi}]}

The syntax highlighting is due to the Head of your command inside Plot being Dynamic

Evaluate[Dynamic[Table[Sin[i*t], {i, 1, z}]]] // Head
Dynamic
$\endgroup$
  • $\begingroup$ right, thank you) $\endgroup$ – Ivan Aug 16 '14 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.