Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13778

Re: updating a simulation within Manipulate.

From W Craig Carter <ccarter@MIT.EDU>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: updating a simulation within Manipulate.
Date 2013-03-08 21:45 +0000
Message-ID <khdm6m$f05$1@smc.vnet.net> (permalink)
References <20130308035142.51AD66799@smc.vnet.net> <5139E091.8000909@idi.ntnu.no>
Organization Time-Warner Telecom

Show all headers | View raw


Thanks Waclwaw,
That is informative; I'm going to have to read the docs about ScheduledTask[]s.

My "real" example is quite a bit more involved---I have a Manipulate buried inside a Manipulate.  I am not looking at random walks per se, but that was an example I cooked up which was simple enough to illustrate my question.  I think this is the preferred method for asking questions in the group? (As long as one doesn't make the silly typos that I am prone to..).

Thanks, Craig


W Craig Carter
Professor of Materials Science, MIT



On Mar 8, 13, at 7:58 AM, Waclaw Kusnierczyk wrote:

> Hi Craig,
>
> Looks like you want to dynamically show the progress of a random walk. Rather than directly modify your solution, I'd suggest to have a look at an alternative using scheduled tasks and buttons.
>
> An example of random walk code:
>
> step[bias_] :=
> Through[{Cos, Sin}[RandomVariate[NormalDistribution[bias, 1]]]]
> next[state_, bias_] :=
> state + step[bias]
> extend[path_, bias_] :=
> Append[path, next[Last@path, bias]]
>
> An example of random walk plot code:
>
> show[path_] :=
> Show[
>  ListLinePlot[path,
>   PlotMarkers -> {Graphics[Circle[{0, 0}, 1]], 0.015},
>   Axes -> None,
>   AspectRatio -> 1,
>   PlotRange -> {{-10, 10}, {-10, 10}}],
>  Graphics[{Red, Point[Last@path]}]]
>
> An example of dynamic random walk plot:
>
> Module[{path = {{0, 0}}, walk, bias = 0},
> Manipulate[
>  show[path],
>  Column@{
>    Row@{
>      Button["start", Quiet@RemoveScheduledTask@walk;
>       walk = RunScheduledTask[path = extend[path, bias], 0.5]],
>      Button["stop", StopScheduledTask[walk]],
>      Button["reset", path = {{0, 0}}]},
>    AngularGauge[Dynamic@bias, {-\[Pi], \[Pi]},
>     ScaleOrigin -> {-\[Pi], \[Pi]}]}]]
>
> Best,
> vQ
>
>
> On 03/08/2013 04:51 AM, W Craig Carter wrote:
>>
>> I *think* I've asked this question before, but I can't find it on mathgroup. In any case, I don't know the answer now.
>>
>> Here is a simple example of a Manipulate that updates a graphic as long as a boolean is true.  This method seems like a kludge to me---is it? If so, what would be a better way to do this.
>>
>> This is a constructed example, the real case I am looking at is much more involved; but kudos to anyone who can make a reasonable facsimile of their signature by adjusting the random walker's bias....
>>
>> randomStep[bias_, stepList_] :=
>>  Module[{angle = RandomVariate[NormalDistribution[bias, 1]]},
>>   Join[stepList, {Last[stepList] + {Cos[angle], Sin[angle]}}]]
>>
>> walkerGraphic[stepList_, range_] :=
>>  Graphics[GraphicsComplex[stepList, Disk /@ Range[Length[stepList]]],
>>   PlotRange -> range {{-1, 1}, {-1, 1}}]
>>
>> DynamicModule[
>>  {walkerPath = {{0, 0}}},
>>  Manipulate[
>>   If[keepWalking,  (*  kludge warning---testing for If[True...] seems inefficient   *)
>>    walkerPath = randomStep[bias, walkerPath]
>>    ];
>>   If[reset,
>>    reset = False; keepWalking = False;
>>    walkerPath = {{0, 0}}
>>    ];
>>   walkerGraphic[walkerPath, range],
>>   {{keepWalking, False}, {True, False}},
>>   {{reset, False}, {True, False}},
>>   Delimiter,
>>   {{range, 20}, 0, 100},
>>   {{a, 0}, -Pi, Pi,
>>    AngularGauge[##, ImageSize -> 160 ,
>>      ScaleOrigin -> {{-4 Pi, 4 Pi}, 1}] &}
>>   ]
>>  ]
>>
>>
>>
>> W Craig Carter
>> Professor of Materials Science, MIT
>


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: updating a simulation within Manipulate. W Craig Carter <ccarter@MIT.EDU> - 2013-03-08 21:45 +0000

csiph-web