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.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer
    
right, thank you) –  Ivan Aug 16 at 12:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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