Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why are the sliders in the following code not affecting the plot? (Without using Manipulate)

Module[{t, o, z}, f[t]];
{Slider[ Dynamic[o], {1, 5, 0.1}], Dynamic[o]}
{Slider[ Dynamic[z], {0.1, 1.4, 0.1}], Dynamic[z]}
{Slider[ Dynamic[Ts], {5, 20, 1}], Dynamic[Ts]}
tf[o_, z_] := TransferFunctionModel[ω^2/(s^2 + 2 z o s + o^2), s];
f[t] = OutputResponse[tf[o, z], UnitStep[t], t];
Plot[f[t], {t, 0, T}, PlotRange -> {{0, T}, {0, 2}}]
share|improve this question
And why do you think a Plot should be affected by a slider? – Dr. belisarius Jul 13 '12 at 3:53
Because f[t] depends on o, z and t – Alel Jul 13 '12 at 4:15
why write Module[{t, o, z}, f[t]]; on its own? what it means like this? code give error running. fix bug in code, not good to post code with coding error. bad for other people to waste time on it. – Robert H Jul 13 '12 at 4:32
Seems you cross posted… – Dr. belisarius Jul 14 '12 at 17:43

Your code modified and with syntax errors fixed

DynamicModule[{o, z, capTs, ω, s},
tf[o_, z_, ω_, s] := TransferFunctionModel[ω^2/(s^2 + 2 z o s + o^2), s];
f[t_, o_, z_, ω_] := OutputResponse[tf[o, z, ω, s], UnitStep[t], t];
Grid[{{"o", Slider[Dynamic[o], {1, 5, 0.1}], Dynamic[o]},
 {"z", Slider[Dynamic[z], {0.1, 1.4, 0.1}], Dynamic[z]},
 {"ω", Slider[Dynamic[ω], {0.1, 1.4, 0.1}], Dynamic[ω]},
 {"Ts", Slider[Dynamic[capTs], {5, 20, 1}], Dynamic[capTs]}, 
 {Dynamic@ Plot[Evaluate@f[t, o, z, ω], {t, 0, capTs}, 
  PlotRange -> {{0, capTs}, {0, Automatic}}], SpanFromLeft}}]]


enter image description here

share|improve this answer

One of the problems is that you use Set (=) to define f[t]. This means that f[t] will be equal to the evaluated form of the right-hand side of its definition where o and z are replaced by their values as they were at the time that f was defined.

What you want is SetDelayed (:=) which leaves the right-hand side in its unevaluated form. In that case the right-hand side will be re-evaluated with the current values for o and z every time f is called.

The second issue is that to get a plot that is updated dynamically, you would need to do something Dynamic[Plot[f[t], ...]]. I don't have access to Mathematica at the moment but I suspect that since o and z don't appear explicitly in Plot[f[t],...] you would also need to set TrackedSymbols -> {o, z} in Dynamic[Plot[...]].

share|improve this answer

Your Answer


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.