       Re: Dynamic changing of variables

• To: mathgroup at smc.vnet.net
• Subject: [mg96362] Re: [mg96314] Dynamic changing of variables
• From: "David Park" <djmpark at comcast.net>
• Date: Thu, 12 Feb 2009 06:37:24 -0500 (EST)
• References: <20000937.1234350071252.JavaMail.root@m02>

```A dynamic display will have primary dynamic variables that are set by
controls (Sliders, InputFields, etc.) and dependent variables that are
calculated from the primary dynamic variables.

The trick to handling this is to use the second argument of Dynamic. This
allows us to call a calculation routine that will calculate all of the
dependent variables. The calculation can even do more; it can apply a
constraint to the primary dynamic variable.

Here is a modification of your example that illustrates these things.

DynamicModule[
{(* Primary dynamic variables *)
b = 3,
(* Dependent dynamic variables *)
a, c,
(* Routine to calculate dependent variables *)
calcAll},

calcAll[bvar_] :=
((* Constrain the b variable to 1 <= b <= 5  *)
b = Max[1, Min[5, bvar]];
(* Calcuate the dependent dynamic variables *)
a = Sin[b];
c = a + 1);

(* Initialze *)
calcAll[b];

Column[
{Dynamic@{b, a, c},
Slider[Dynamic[b, (b = #; calcAll[b]) &], {0, 2*Pi}]}]
]

This simple form is easily generalize to create very complex custom
displays. You have complete control of how you place controls and how you
display information and you can dynamically calculate very complicated
objects from the primary dynamic variables.

Throw Manipulate into the ashcan. You will never need it again.

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

From: Patrick Scheibe [mailto:pscheibe at trm.uni-leipzig.de]

Hi,

assume the following code lines:

DynamicModule[{a, b = 0},
a = Dynamic[Sin[b]];
Column[{
Dynamic[a],
Slider[Dynamic[b], {0, 2*Pi}]
}]
]

In order to update "a" with the actual value of Sin[b] I need
Dynamic around it. Unfortunately, now the variable "a" is invisibly
wrapped and completely useless for further calculations. I'm not able to
calculate even a+1 inside the DynamicModule.

DynamicModule[{a, b = 0},
a = Dynamic[Sin[b]];
Column[{
Dynamic[a+1],
Slider[Dynamic[b], {0, 2*Pi}]
}]
]

If I'm not just too stupid and this behaviour is intended, then I'm
wondering whether this doesn't lead to problems when you have more
complex constructs with several dynamic variables.

Cheers
Patrick

PS: I was just pointed by another person on this and I found a way
around it. So cannot provide a real problem I'm having. Nevertheless, I
would be glad to know what you think since I couldn't really find the
point in the documentation where this is explained.

```

• Prev by Date: Re: Dynamic changing of variables
• Next by Date: Re: Re: LabeledListPlot
• Previous by thread: Re: Dynamic changing of variables
• Next by thread: Re: Dynamic changing of variables