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


Groups > comp.soft-sys.math.mathematica > #13777 > unrolled thread

Re: Fixed Typo in Code---> Re: updating a simulation

Started byW Craig Carter <ccarter@MIT.EDU>
First post2013-03-08 21:45 +0000
Last post2013-03-08 21:45 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Fixed Typo in Code---> Re: updating a simulation W Craig Carter <ccarter@MIT.EDU> - 2013-03-08 21:45 +0000

#13777 — Re: Fixed Typo in Code---> Re: updating a simulation

FromW Craig Carter <ccarter@MIT.EDU>
Date2013-03-08 21:45 +0000
SubjectRe: Fixed Typo in Code---> Re: updating a simulation
Message-ID<khdm6f$f00$1@smc.vnet.net>
Thanks Bob,
That's better.

I'm still surprised that is the cleanest way to do it.  What I wasn't 
sure about is if that If[] is being called repeatedly if its argument is 
Dynamic.  I think it is not because the the kernel and the FrontEnd 
don't seem to be taxing the cpu.

Craig

W Craig Carter
Professor of Materials Science, MIT



On Mar 8, 13, at 6:22 AM, Bob Hanlon wrote:

> Use of If structure seems reasonable. Recommend that you use a
> separate color for the latest point/disk so that the current position
> is evident. Other minor changes made.
>
> randomStep[bias_, stepList_] :=
>  Module[
>   {angle = RandomVariate[
>      NormalDistribution[bias, 1]]},
>   Join[stepList,
>    {Last[stepList] + {Cos[angle], Sin[angle]}}]];
>
> walkerGraphic[stepList_, range_] :=
>  Graphics[{
>    Gray,
>    PointSize[.04],
>    Point@Most@stepList,
>    Blue,
>    Point@Last@stepList},
>   PlotRange -> range {{-1, 1}, {-1, 1}}];
>
> DynamicModule[{walkerPath = {{0, 0}}},
> Manipulate[
>  If[keepWalking,
>   walkerPath = randomStep[bias, walkerPath]];
>  walkerGraphic[walkerPath, range],
>  Row[{
>    Control[
>     {{keepWalking, False, "Keep Walking"},
>      {True, False}}],
>    Spacer[20],
>    Button["Reset",
>     reset = False;
>     keepWalking = False;
>     walkerPath = {{0, 0}},
>     ImageSize -> Tiny,
>     BaseStyle -> {8}]
>    }],
>  Delimiter,
>  {{range, 20, "Range"}, 0, 100},
>  {{bias, 0, "Bias"}, -Pi, Pi,
>   AngularGauge[##, ImageSize -> 160,
>     ScaleOrigin -> {{-4 Pi, 4 Pi}, 1}] &}]]
>
>
> Bob Hanlon
>
>
> On Thu, Mar 7, 2013 at 10:47 PM, W Craig Carter <ccarter@mit.edu> wrote:
>> On previous message, there is a typo in the example code, please use this instead:
>>
>> 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},
>>  {{bias, 0}, -Pi, Pi,
>>   AngularGauge[##, ImageSize -> 160,
>>     ScaleOrigin -> {{-4 Pi, 4 Pi}, 1}] &}]]
>>
>>
>>
>> W Craig Carter
>> Professor of Materials Science, MIT
>>
>>
>>
>> On Mar 7, 13, at 17:16 PM, 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
>>>
>>>
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web