0

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?

Michael E2
  • 235,386
  • 17
  • 334
  • 747
Jim Napolitano
  • 101
  • 1
  • 1
  • 2

1 Answers1

2

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}]
Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198