Define control as variable in Mathematica

后端 未结 2 1385
轻奢々
轻奢々 2021-02-09 08:13

When I use Manipulate I can do:

Manipulate[x, {u, 1, 10}]

In reality my controls are many and complicated, so I would prefer to take their defi

2条回答
  •  鱼传尺愫
    2021-02-09 08:45

    This

    con = {u, 1, 10};
    Manipulate[
     u,
     Evaluate@con
     ]
    

    does work. I suppose it doesn't work without the Evaluate because

    Attributes[Manipulate]
    

    shows that Manipulate has the attribute HoldAll (but I may be wrong). To see the effect of this attribute, try this:

    SetAttributes[f, HoldAll]
    f[con]
    f[Evaluate@con]
    g[con]
    (*
    f[con]
    f[{u, 1, 10}]
    g[{u, 1, 10}]
    *)
    

    Thus, it appears that due to the HoldAll atribute, Manipulate simply does not see "inside" con unless you explicitly evaluate it.

提交回复
热议问题