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

MathGroup Archive 2012

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

Search the Archive

Re: Dynamic question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125239] Re: Dynamic question
  • From: "djmpark" <djmpark at comcast.net>
  • Date: Thu, 1 Mar 2012 05:35:50 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <32121567.62941.1330519007647.JavaMail.root@m06>

It's easy to get confused on that and WRI is not completely specific as to
where Dynamic should go.

But the general rule is that Dynamic goes around the "output" and not around
the "input" to the "output" .  If calculations are to be done then do them
all inside the Dynamic. So the following works:

X=8;
Dynamic[If[x >= 5, "a", "b"]] 
a

The FullForm of your statement is:

If[GreaterEqual[Dynamic[x] 5], "a", "b"]

Mathematica doesn't know how to further evaluate that. It just substitutes
the current dynamic value in the displayed result.

Sometimes one is doing a calculation with a set of primary dynamic variables
and a set of secondary dynamic variables that are calculated from the
primary variables. In the following x is a primary dynamic variable
controlled by a Slider.  The secondary variables are y and z. These are
calculated from x in the calcAll routine. 

DynamicModule[{x = 3, y, z, calcAll},
 calcAll[xvar_] := (y = 2 xvar; z = xvar^2);
 calcAll[x];
 
 Row[{Slider[Dynamic[x, (x = #; calcAll[x]) &], {0, 5, 0.01}],
   Spacer[10],
   Dynamic[
    Row[{"x = ", NumberForm[x, {3, 2}], ",", Spacer[5], "x y z = ", 
      x y z}]]}]
 ] 

The calcAll routine is invoked by the second argument in the Dynamic
statement within the Slider. # represents the current setting of the Slider.
Dynamic is then also wrapped around the entire output. All the variables (x,
y, z) are continually updated by the Slider. It wouldn't even make any sense
to wrap Dynamic around y or z individually because they're not even primary
dynamic variables. But they are all updated and the product evaluated.


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



From: dominik.hezel at googlemail.com [mailto:dominik.hezel at googlemail.com] 


Hello,

I'm stuck in program, because (simplified to the guts)

x = 8;
If[Dynamic[x] >= 5, "a", "b"]

doesn't work. Can anyone tell me why - or even better, offer me a solution
how to do this?

thanks a lot!




  • Prev by Date: Re: Plotting colorfunctions over multiple parametric curves
  • Next by Date: Re: Why no OpenCL output on iMac OS X Lion?
  • Previous by thread: Re: Dynamic question
  • Next by thread: Re: Dynamic question