[Date Index]
[Thread Index]
[Author Index]
Re: difference between two commands
*To*: mathgroup at smc.vnet.net
*Subject*: [mg121647] Re: difference between two commands
*From*: Heike Gramberg <heike.gramberg at gmail.com>
*Date*: Sat, 24 Sep 2011 22:31:18 -0400 (EDT)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*References*: <201109230742.DAA07668@smc.vnet.net>
By default, the variables appearing in a Manipulate are localized. This
means that for each variable in Manipulate a unique symbol
is created to represent this symbol (similar to for example Module). In
this case, the c in Manipulate will internally be represented
by something like FE`c$$512. Try for example
Manipulate[HoldForm[c], {c, 0, 1}]
to see what the internal name of the variable c is. The c appearing in
the definition of p is a global variable and is different to the c
appearing in the Manipulate so it won't get replaced by the value of the
local c when you're trying to plot p inside the Manipulate.
To get the right behaviour you could do something like
Clear[p];
p[c_, x_] := Sin[c x]
Manipulate[Plot[p[c, x], {x, 0, 10}], {c, 1, 2}]
Alternatively you could set LocalizeVariables->False, but this might
cause all sorts of undesired side effects so you should be careful
with that.
Heike.
On 23 Sep 2011, at 09:42, Luiz M. Carvalho wrote:
> Hi,
>
> Let
> p := Sin[c x]
> Please, could someone explain to me the difference between those two
> commands
>
> Manipulate[Plot[p, {x, 0, 10}], {c, 1, 2}] and Manipulate[ Plot[Sin[c
> x], {x, 0, 10}], {c, 1, 2}]
>
> Thanks
> Luiz
>
Prev by Date:
**Re: 1-liner wanted**
Next by Date:
**Re: 1-liner wanted**
Previous by thread:
**difference between two commands**
Next by thread:
**help with integration**
| |