Wolfram mathematica Mathematic带有操纵的绘图不显示输出

Wolfram mathematica Mathematic带有操纵的绘图不显示输出,wolfram-mathematica,Wolfram Mathematica,我最初尝试使用Plot3D和Operation滑块可视化一个4参数函数(两个参数由滑块控制,另一个在“x-y”平面中变化)。然而,当我的非打印参数被操纵控制时,我没有得到任何输出 下面的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,

我最初尝试使用Plot3D和Operation滑块可视化一个4参数函数(两个参数由滑块控制,另一个在“x-y”平面中变化)。然而,当我的非打印参数被操纵控制时,我没有得到任何输出

下面的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}] 
具有固定值mu的绘图在{0,70}自动选择的绘图范围内具有预期的抛物线输出,而操纵绘图在{0,1}范围内为空

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

Manipulate[ Plot[ g[x], {x, -10, 10}, PlotRange -> {0, 70}], {{mu, 1}, 0, 2 \[Pi]}]

这是因为
操纵
参数是本地的

operation[Plot[g[x],{x,-10,10}],{mu,1},0,2\[Pi]}]
中的
mu
与您在前一行中清除的全局
mu
不同

我建议使用

g[x_, mu_] := (x Sin[mu])^2
Manipulate[Plot[g[x, mu], {x, -10, 10}], {{mu, 1}, 0, 2 \[Pi]}]
下面的方法同样有效,但它会不断更改全局变量的值,这可能会在以后引起意外,除非您注意,所以我不建议您这样做:

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

您可能会
清除[mu]
,但在Operate对象滚动到视图中时发现它得到了一个值。

克服
Operate
局限性的另一种方法是将函数放入
Operate[]
中:

Manipulate[Module[{x,g},
  g[x_]=(x Sin[mu])^2;
  Plot[g[x], {x, -10, 10}]], {{mu, 1}, 0, 2 \[Pi]}]
甚至

Manipulate[Module[{x,g},
  g=(x Sin[mu])^2;
  Plot[g, {x, -10, 10}]], {{mu, 1}, 0, 2 \[Pi]}]
这两种方法都有好处


Module[{x,g},…]
可防止全局环境产生不必要的副作用。这使得g有了一个简单的定义:我已经有了几十个可调参数的
Operation[]
ed绘图,当将所有这些参数作为参数传递给函数时,这可能会很麻烦。

谢谢,这很好,并且对我实际尝试的四参数绘图进行了概括。