Re: Dynamic function application problem
- To: mathgroup at smc.vnet.net
- Subject: [mg108240] Re: Dynamic function application problem
- From: dh <dh at metrohm.com>
- Date: Thu, 11 Mar 2010 06:37:58 -0500 (EST)
- References: <hmvq6k$11s$1@smc.vnet.net>
Hi Istvan,
you could try to nest two Manipulates like e.g.:
Manipulate[Clear["x*"];
it = Table[{Symbol["x" <> ToString[i]], 1, 10}, {i, 1, n}];
Manipulate0[set = it[[All, 1]]
, Sequence @@ it, LocalizeVariables -> False] /.
Manipulate0 -> Manipulate
, {n, 1, 5}]
Dynamic@set
Note that I clear all variables with a name starting witjh "x".
Daniel
On 07.03.2010 10:04, István wrote:
> Dear All,
>
> every time I construct a simple interface for something like the
> common demonstration "Understanding function x" to get a grip on the
> behaviour of the function, I run into
> some unresolvable problem of Dynamic. I mean: EVERY time. This is the
> newest one.
>
> The interface uses a master slider that controls the length (n) of a
> list (set). Each element in this list has an independent slider to
> control its value. What I want to do is to allow the values in set to
> be saved in some way. That is, if the user increases n from default 2
> to e.g. 4, and then changes the value of set[[2]], and then decides to
> go back to n = 2, the set should keep the changed value. That's why I
> use the 'truncate' function. To conclude:
>
> time1: n = 2, set = {1, 2}
> time2: n = 4, set = {1, 2, 3, 4} (user increased n)
> time3: n = 4, set = {1, 7, 3, 4} (user changed set[[2]])
> time4: n = 2, set = {1, 7} (user decreased n)
>
> And the code is below. Be aware that this is a TOY modell with the
> sole purpose of demonstraing a problem I don't understand, please
> don't ask questions like "your function 'update' is an unnecessary
> intermediate step, why do you use it??".
>
>
> DynamicModule[{
> n = 2, m = 8, def, set,
> update, truncate
> },
>
> Panel@Column@{
> Slider[Dynamic[n, (n = #; update[#])&], {1, m, 1},
> ImageSize -> 110],
> Dynamic@
> Column[Slider[Dynamic@set[[#]], {1, 30, 1}, ImageSize -> 110]& /
> @
> Range@n],
> Dynamic@Column@{n, set}
> },
>
> Initialization :> (
> truncate[set_, n_, def_] :=
> If[n<= Length@set, Take[set, n],
> Join[set, Take[def, {n + 1, Length@def}]]];
>
> update[n_] := (
> set = truncate[set, n, def];
> );
>
> def = Range@m;
> update@n;
> )
> ]
>
>
> At present, the code simply cannot deal with truncate, and crashes
> (with fresh kernel), or at least produces severe errors due to
> recursion problems (with old kernel). Could you please suggest a
> resolution for this matter?
>
> Thank you in advance
>
> Istvan
>
--
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>