Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Manipulate with dynamic maximum on slider

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113687] Re: Manipulate with dynamic maximum on slider
  • From: Arend <asluis at gmail.com>
  • Date: Mon, 8 Nov 2010 03:36:47 -0500 (EST)
  • References: <iaonl4$jk6$1@smc.vnet.net>

Based on my experimenting, the initial value of a control in
Manipulate is set only once, so it is pointless to make it Dynamic.
Instead I opted to change my approach: make the control a variable
between 0 and 1 with a step size determined by the length of the list:

Manipulate[SeedRandom[rSeed]; {rl, ll} = Module[{newNum = 10000,
rList},
     rList = Reap[While[ !PrimeQ[newNum],
          Sow[newNum = RandomInteger[{10000, 100000}]]]][[2,1]];
      {rList, Length[rList] - 1}]; steps = 1 + ll*Round[relFrac, 1/
ll];
   Take[rl, steps], {{rSeed, 250}, 100, 400, 1,
   Appearance -> "Labeled"}, {{relFrac, 1}, 0, 1, Dynamic[1/ll],
   Appearance -> "Labeled"}]

Although this does not "reset" the value of relFrac to 1 every time
rSeed is updated, the behavior is more consistent when changing the
value of rSeed: it always show the same fraction of the list. As long
as you keep it set to 1, it shows the complete list when you change
rSeed.

I seem to remember that there is a way to have the control show a
fraction (3/5) instead of a floating point representation (0.6) of a
control variable. However, I can't find it in the documentation. Am I
misremembering?

Thank you!

On Nov 2, 5:03 am, Arend <asl... at gmail.com> wrote:
> I am a newbie at Mathematica and playing around with Manipulate.
>
> My problem: I have two controls, one completely independent, the other
> dependent on the results of a calculation in the body of Manipulate.
>
> Here is my code (simplified from the actual use case for clarity):
>
> Manipulate[
>  SeedRandom[seed];
> {rl, ll} = Module[{newNum = 10000, rList},
>    rList = Reap[
>       While[! PrimeQ[newNum],
>        Sow[newNum = RandomInteger[{10000, 100000}]]]][[2, 1]];
>  {rList, Length[rList]}];
>  (* If[steps != ll, steps = ll]; *)
>  Take[rl, steps],
>  {{seed, 250}, 100, 400, 1, Appearance -> "Labeled"},
> {{steps, ll}, 1,  Dynamic[ll], 1, Appearance -> "Labeled"}]
>
> The issue is that after the user changes the value of seed, the steps
> slider should be given a new maximum value (determined by the length
> of the list generated by the While loop) and the steps slider should
> be set to this maximum value. That is, after choosing a new seed, the
> user should see the complete list by default.
>
> I've read the four Mathematica tutorials on Dynamic/Manipulate, which
> are wonderful, but perhaps a bit of information overload.
>
> What simple thing am I missing here?
>
> Thank you for your help!



  • Prev by Date: Re: Fonts, Formats, and examples as learning tools
  • Next by Date: Re: Balance point of a solid
  • Previous by thread: Manipulate with dynamic maximum on slider
  • Next by thread: Re: is there an 'issue' with putting Notation[] command inside a Module[]?