Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8814
| From | "djmpark" <djmpark@comcast.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Dynamic question |
| Date | 2012-03-01 10:38 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jinjjm$d2f$1@smc.vnet.net> (permalink) |
| 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@comcast.net
http://home.comcast.net/~djmpark/index.html
From: dominik.hezel@googlemail.com [mailto:dominik.hezel@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!
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Dynamic question "djmpark" <djmpark@comcast.net> - 2012-03-01 10:38 +0000
csiph-web