Re: novice needs help using Manipulate with Plot
- To: mathgroup at smc.vnet.net
- Subject: [mg78444] Re: [mg78424] novice needs help using Manipulate with Plot
- From: DrMajorBob <drmajorbob at bigfoot.com>
- Date: Mon, 2 Jul 2007 06:44:00 -0400 (EDT)
- References: <4377562.1183292796234.JavaMail.root@m35>
- Reply-to: drmajorbob at bigfoot.com
Notice what happens when you run this code:
Clear[test]
test[m_, x_] = m x
Manipulate[Print@SymbolName@m;
Plot[test[m, x], {x, 0, 10}], {{m, 1}, 0, 2}]
SymbolName::sym: Argument 1 at position 1 is expected to be a symbol. \
>>
SymbolName[1]
Move the slider, and the Plot changes as it should, but you'll get more
error messages:
SymbolName::sym: Argument 0.518` at position 1 is expected to be a \
symbol. >>
SymbolName[0.518]
SymbolName::sym: Argument 1.362` at position 1 is expected to be a \
symbol. >>
SymbolName[1.362]
Explicit mentions of m inside Manipulate are replaced With the slider
value, so a test function with no arguments, or only an x argument, can't
take account of the local value of m.
But THIS works:
Clear[test]
test = m x;
With[{test = m x}, Manipulate[Plot[test, {x, 0, 10}], {{m, 1}, 0, 2}]]
because test is replaced with its value BEFORE Manipulate is parsed and
executed, as if you had typed:
Manipulate[Plot[m x, {x, 0, 10}], {{m, 1}, 0, 2}]
Bobby
On Sun, 01 Jul 2007 06:43:46 -0500, <PHILLMAN5 at gmail.com> wrote:
> Manipulate seems at first to be very powerful, but I am having trouble
> using it with my own functions. To vastly simplify my problem say I
> want to plot y = m x, with x going from 0 to 10, with the slider in
> Manipulate controlling m. I have tried the following:
>
> test := m x
> Manipulate[Plot[test, {x, 0, 10}], {{m, 1}, 0, 2}]
>
> test3[x_] := m x;
> Manipulate[Plot[test3[x], {x, 0, 10}], {{m, 1}, 0, 2}]
>
> don't seem to work. If you define the function with m as a formal
> parameter, like the following it does.
>
> test2 = #1 #2 &;
> Manipulate[Plot[test2[m , x], {x, 0, 10}], {{m, 1}, 0, 2}]
>
> test4[m_, x_] := m x;
> Manipulate[Plot[test4[m, x], {x, 0, 10}], {{m, 1}, 0, 2}]
>
> Is there anyway to write functions to work with Manipulate without
> have to have all the slider(s) formally written as a parameter to the
> function?
>
>
>
--
DrMajorBob at bigfoot.com