Assume that in the place of RandomInteger
what obtains is the result of a simulation step (the $j-th$ step).
j = 0;
While[
j < 10,
RandomInteger[{0, 100},5];
j++
]
Also, assume that the maximum number of iterations (10 in the example above) is a parameter of the simulation. Consider that the same thing applies for the length of the output list (ie 5).
main[J_, x_] := Module[{j},
j = 0;
While[
j < J,
RandomInteger[{0, 100}, x];
j++
]
]
(I understand that main
is not supposed to output anything, like this. In order to get an output, you can enclose RandomInteger
in Sow
and apply Reap
on While
. But that is not what I'm trying to do.)
Using a variation of the main
function defined above in a Dynamic
context produces nothing:
DynamicModule[{J, x, j},
Row@{
Column@{
Row@{"J", Null, Slider[Dynamic[J], {9, 13, 1}], Null, Dynamic[J]},
Row@{"x", Null, Slider[Dynamic[x], {2, 7, 1}], Null, Dynamic[x]},
},
Null,
Framed@main[Dynamic[J], Dynamic[x]]
}
]
This is the 'dynamic' main
:
main[J_, x_] := DynamicModule[{j},
j = 0;
While[
j < Dynamic[J],
ListPlot[RandomInteger[{0, 100}, Dynamic[x]]];
j++
]
]
What am I doing wrong?
update
I have had success with a stripped down version of main
:
main[Dynamic[J_], Dynamic[x_]] := DynamicModule[{},
ListPlot[RandomInteger[{0, 100}, x], Frame -> True]
]
(also, I had to insert another Dynamic
between Framed
and main
:
Framed@Dynamic@main[Dynamic[J], Dynamic[x]]
in the calling code (see above))
The downside is that with this version, I can only visualize lists of varying Length
(Dynamic[x]
). I still have not figured out a way to visualize what goes on inside the loop (how to display a succession of Listplot
's).
update2:
I wanted to replicate this (display tournaments dynamically, mostly). I have so far gotten to this (package) and this (Manipulate
):
update3:
This is the package with the additional functionality for repeated tournaments (evolutionary-ish) and this is the Manipulate
code:
any suggestions for improvements esp. on the Dynamic
side of things is particularly welcome.
Dynamic[J]
is not a number, see: 5817 and linked topics. $\endgroup$Dynamic
is purely for display. It has no room in any function which computes things (as opposed to display things computed elsewhere). $\endgroup$Dynamic
functionality of some plots is to first generate them and then display them? $\endgroup$Dynamic[x]
.Dynamic[x]
is meant to be displayed, and it auto-updates wheneverx
changes. If you want to display a plot, useDynamic@Plot[...]
. $\endgroup$