I was initially attempting visualize a 4 parameter function with Plot3D and Manipulate sliders (with two params controlled by sliders and the other vary in the “x-y” plane). However, I’m not getting any output when my non-plotted parameters are Manipulate controlled?
The following 1d plot example replicates what I’m seeing in the more complex plot attempt:
Clear[g, mu]
g[ x_] = (x Sin[mu])^2
Manipulate[ Plot[ g[x], {x, -10, 10}], {{mu, 1}, 0, 2 \[Pi]}]
Plot[ g[x] /. mu -> 1, {x, -10, 10}]
The Plot with a fixed value of mu has the expected parabolic output in the {0,70} automatically selected plotrange, whereas the Manipulate plot is blank in the {0, 1} range.
I was suspecting that the PlotRange wasn’t selected with good defaults when the mu slider control was used, but adding in a PlotRange manually also shows no output:
Manipulate[ Plot[ g[x], {x, -10, 10}, PlotRange -> {0, 70}], {{mu, 1}, 0, 2 \[Pi]}]
This is because the
Manipulateparameters are local.The
muinManipulate[ Plot[ g[x], {x, -10, 10}], {{mu, 1}, 0, 2 \[Pi]}]is different from the globalmuyou clear on the previous line.I suggest using
The following works too, but it keeps changing the value of a global variable, which may cause surprises later unless you pay attention, so I don’t recommend it:
It may happen that you
Clear[mu], but find that it gets a value the moment the Manipulate object is scrolled into view.