0
$\begingroup$

The following works exactly as advertised:

Manipulate[
 Plot[5 Cos[Pi t] Sin[Pi x], {x, 0, 2},
  PlotRange -> {-5, 5}],
 {t, 0, 4}]

However, if I use an expression in a variable instead of explicitly in the Plot command, that is...

wave = 5 Cos[Pi t] Sin[Pi x];
Manipulate[
 Plot[wave, {x, 0, 2},
  PlotRange -> {-5, 5}],
 {t, 0, 4}]

... then the plot is blank. However, I can get this to work by replacing t with a different variable and manipulating on that instead:

wave = 5 Cos[Pi t] Sin[Pi x];
Manipulate[
 Plot[wave /. t -> tt, {x, 0, 2},
  PlotRange -> {-5, 5}],
 {tt, 0, 4}]

Does anybody out there understand why I can't use the second example?

$\endgroup$
2
$\begingroup$

It is a scoping issue. The t associated with the control is localized to the Manipulate whereas the t in the definition of wave is in the global context. Make wave an explicit function of t

wave[t_] = 5 Cos[Pi t] Sin[Pi x];
Manipulate[Plot[wave[t], {x, 0, 2}, PlotRange -> {-5, 5}], {t, 0, 4}]
$\endgroup$

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