mathematica Plot with Manipulate显示无输出

Pee*_*oot 4 wolfram-mathematica

我最初尝试使用Plot3D和Manipulate滑块可视化4参数函数(两个参数由滑块控制,另一个在"xy"平面中变化).但是,当我的非绘制参数是Manipulate控制时,我没有得到任何输出?

下面的1d绘图示例复制了我在更复杂的绘图尝试中看到的内容:

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}] 
Run Code Online (Sandbox Code Playgroud)

固定值为mu的Plot在{0,70}自动选择的绘图范围内具有预期的抛物线输出,而Manipulate图在{0,1}范围内为空白.

我怀疑在使用mu滑块控件时没有选择具有良好默认值的PlotRange,但手动添加PlotRange也没有显示输出:

Manipulate[ Plot[ g[x], {x, -10, 10}, PlotRange -> {0, 70}], {{mu, 1}, 0, 2 \[Pi]}]
Run Code Online (Sandbox Code Playgroud)

Sza*_*lcs 8

这是因为Manipulate参数是本地的.

muManipulate[ Plot[ g[x], {x, -10, 10}], {{mu, 1}, 0, 2 \[Pi]}]不同于全球mu您在上线清晰.

我建议使用

g[x_, mu_] := (x Sin[mu])^2
Manipulate[Plot[g[x, mu], {x, -10, 10}], {{mu, 1}, 0, 2 \[Pi]}]
Run Code Online (Sandbox Code Playgroud)

以下也可以,但它会不断更改全局变量的值,除非你注意,否则可能会引起意外,所以我不推荐它:

g[x_] := (x Sin[mu])^2
Manipulate[
 mu = mu2;
 Plot[g[x], {x, -10, 10}],
 {{mu2, 1}, 0, 2 \[Pi]}
]
Run Code Online (Sandbox Code Playgroud)

可能会发生这种情况Clear[mu],但发现它在Manipulate对象滚动到视图中时会获得一个值.