MathGroup Archive 2010

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

Search the Archive

Re: Manipulate with variable number of controls

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107889] Re: Manipulate with variable number of controls
  • From: dh <dh at metrohm.com>
  • Date: Tue, 2 Mar 2010 03:35:58 -0500 (EST)
  • References: <hm6ts0$ggb$1@smc.vnet.net>

Hello Dominic,
here is a clumsy solution. Manipulate seems to be a very obstinate 
command, it does not listen to all the Hold typoe commands, neither With 
was working. So as a last resort, I got the big axe and made it a 
string. Sorry not very elegant, but a work around:
Assume that rtable contains the radii of the different circles, n is the 
number of circles:

rtable = {1, 2, 3, 4};
circles[n_] := Table[Circle[{0, 0}, r], {r, n}]
sliders[n_] := Table[{Symbol["t" <> ToString[i]], 0, 2 Pi}, {i, n}]
lines[n_] :=
  Table[t = Symbol["t" <> ToString[i]];
   Line[{If[i == 1, 0, rtable[[i - 1]]] {Cos[t], Sin[t]},
     rtable[[i]] {Cos[t], Sin[t]}}], {i, 1, n}]

ToExpression@
  StringReplace[
   "Manipulate[Show[Graphics[{circles,lines}],Axes\[Rule]True,\
PlotRange\[Rule]{{-5,5},{-5,5}}],sliders]", {"sliders" ->
     StringTake[ToString@sliders[4], {2, -2}],
    "circles" -> ToString[circles [4]], "lines" -> ToString[lines[4]]}]

Daniel

On 25.02.2010 23:33, Dominic wrote:
> Hi,
>
> Can I set up a Manipulate with a variable number of controls?  The code
> below draws 4 circles and line segments between them at the angles given
> by the slider values.  As you can see, I had to hard-code the function
> for the lines, and the number of controls given by the size of rtable.
> Is is possible to dynamically construct this Manipulate based on the
> size of rtable?  I noticed if I try to build a control outside of
> Manipulate such as mycontrol1={"t1",0,2 PI}, and then use mycontrol1
> inside of Manipulate, it doesn't work.  Also, I use
> LocalizeVariales->False since I then go on to use the values of the
> angles (t1,t2, ...) in the program.
>
> Can anybody help me to get this working for arbitrary-size rtable with
> not more than five entries,  or is Manipulate not capable of dynamically
> allocating a variable number of controls?
>
> Thanks guys,
>
> Dominic
>
>
> rtable = {0, 1, 2, 3, 4};
> t1 = 0;
> t2 = 0;
> t3 = 0;
> t4 = 0;
>
>
> myf4[t1_, t2_, t3_, t4_] :=
> {Line[{{Re[rtable[[1]]*Exp[I*t1]],
> Im[rtable[[1]]*Exp[I*t1]]},
> {Re[rtable[[2]]*Exp[I*t1]],
> Im[rtable[[2]]*Exp[I*t1]]}}],
> Line[{{Re[rtable[[2]]*Exp[I*t2]],
> Im[rtable[[2]]*Exp[I*t2]]},
> {Re[rtable[[3]]*Exp[I*t2]],
> Im[rtable[[3]]*Exp[I*t2]]}}],
> Line[{{Re[rtable[[3]]*Exp[I*t3]],
> Im[rtable[[3]]*Exp[I*t3]]},
> {Re[rtable[[4]]*Exp[I*t3]],
> Im[rtable[[4]]*Exp[I*t3]]}}],
> Line[{{Re[rtable[[4]]*Exp[I*t4]],
> Im[rtable[[4]]*Exp[I*t4]]},
> {Re[rtable[[5]]*Exp[I*t4]],
> Im[rtable[[5]]*Exp[I*t4]]}}]};
>
>
> mycircles = Table[Circle[{0, 0},
> rtable[[n]]], {n, 2,
> Length[rtable]}];
>
>
> Manipulate[Show[Graphics[
> {myf4[t1, t2, t3, t4], mycircles}],
> Axes ->  True, PlotRange ->
> {{-5, 5}, {-5, 5}}], {t1, 0, 2*Pi},
> {t2, 0, 2*Pi}, {t3, 0, 2*Pi},
> {t4, 0, 2*Pi}, LocalizeVariables ->
> False]
>
>
>


-- 

Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:dh at metrohm.com>
Internet:<http://www.metrohm.com>



  • Prev by Date: Re: Stock tracking
  • Next by Date: Re: CONDITION/DATA ANALYSIS/PLOTS
  • Previous by thread: Re: Stock tracking
  • Next by thread: Re: Manipulate with variable number of controls