MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: DynamicModule causing problems with Manipulate setter bar

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102810] Re: [mg102748] DynamicModule causing problems with Manipulate setter bar
  • From: "David Park" <djmpark at comcast.net>
  • Date: Thu, 27 Aug 2009 06:39:08 -0400 (EDT)
  • References: <3338029.1251289546673.JavaMail.root@n11>

I would make a custom dynamic with Presentations:

Needs["Presentations`Master`"]

DynamicModule[
 {m = 1, functiontype = Sin},
 panelpage[
  pagelet[
   (* SetterBar for function choice *)
   phrase[Subscript[f, "m"][x], ": ",
    SetterBar[
     Dynamic[functiontype],
     {Sin -> HoldForm[Sin[\[Pi] "m" x] // TraditionalForm], 
      Cos -> HoldForm[Cos[\[Pi] "m" x] // TraditionalForm]}]],
   (* Slider for m *)
   phrase["m: ", 
    Slider[Dynamic[m], {0, 3, 1}, Appearance -> "Labeled"]],
   (* Function plot with filling *)
   Dynamic@
    Plot[functiontype[\[Pi] m x], {x, -1, 1},
     PlotRange -> {-1, 1}, PlotRangePadding -> .05,
     Filling -> Axis,
     Frame -> True,
     ImageSize -> 350]
   ](* pagelet *),
  Style["Harmonics of Sin and Cos", 16]
  ](* panelpage *)
 ]

Everything works the way you prescribed.


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  


From: Porscha Louise McRobbie [mailto:pmcrobbi at umich.edu] 


Hello,

I often have multiple Manipulate commands in a single file, and to 
avoid them interfering I always wrap them with a DynamicModule.

The following Manipulate is the basic idea of what I want:

Manipulate[
  Plot[ffun[y, m1], {y, -1, 1}, Filling -> Axis,
   PlotRange -> {{-1, 1}, {-1.1, 1.1}}],

  {{ffun, f1,
    "\!\(\*SubscriptBox[\"f\", \"m\"]\)(x)"}, {f1 ->
     TraditionalForm[Sin[m Pi x]], f2 -> TraditionalForm[Cos[m Pi x]]}},
  {{m1, 0, "m"}, 0, 3, 1},

  Initialization :> { (f1[yy_, mm_] := Sin[mm Pi yy]), (f2[yy_, mm_] :=
       Cos[mm Pi yy])}]

However, I've noticed the following two problems when trying to wrap 
the above with DynamicModule:

1. If I place {f1,f2} inside DynamicModule, the graph seems fine but 
the blue highlighter color on the setter bar for fm(x) has disappeared.

DynamicModule[{f1, f2},

  Manipulate[
   Plot[ffun[y, m1], {y, -1, 1}, Filling -> Axis,
    PlotRange -> {{-1, 1}, {-1.1, 1.1}}],

   {{ffun, f1,
     "\!\(\*SubscriptBox[\"f\", \"m\"]\)(x)"}, {f1 ->
      TraditionalForm[Sin[m Pi x]],
     f2 -> TraditionalForm[Cos[m Pi x]]}},
   {{m1, 0, "m"}, 0, 3, 1},

   Initialization :> { (f1[yy_, mm_] := Sin[mm Pi yy]), (f2[yy_, mm_] :=
        Cos[mm Pi yy])}]]

2. If I place {f1,f2,m,x} inside DynamicModule, the graph seems fine 
but now the labels for "m" and "x" read "$$m" and "$$x" (in addition 
to the blue highlighting being gone).

DynamicModule[{f1, f2, m, x},

  Manipulate[
   Plot[ffun[y, m1], {y, -1, 1}, Filling -> Axis,
    PlotRange -> {{-1, 1}, {-1.1, 1.1}}],

   {{ffun, f1,
     "\!\(\*SubscriptBox[\"f\", \"m\"]\)(x)"}, {f1 ->
      TraditionalForm[Sin[m Pi x]],
     f2 -> TraditionalForm[Cos[m Pi x]]}},
   {{m1, 0, "m"}, 0, 3, 1},

   Initialization :> { (f1[yy_, mm_] := Sin[mm Pi yy]), (f2[yy_, mm_] :=
        Cos[mm Pi yy])}]]

How can I localize the variables f1,f2,m,x but still have the labels 
look how I want them to?

Many thanks!
Porscha






  • Prev by Date: Re: ClearAll ?? or what
  • Next by Date: Re: DynamicModule causing problems with Manipulate setter bar
  • Previous by thread: DynamicModule causing problems with Manipulate setter bar
  • Next by thread: Re: DynamicModule causing problems with Manipulate setter bar