Saturday, October 1, 2022

Casio fx-CG 50: Random Walk Histogram

Casio fx-CG 50:  Random Walk Histogram


Mosquitos an Inspiration, What? 


Inspiration:  

Ellenberg, Jordan.   Shape:  The Hidden Geometry of Information, Biology, Strategy, Democracy, and Everything Else  Penguin Books:  New York, NY. 2021


The beginning of Chapter 4, Sir Ronald Ross proposes the problem:  In a simple case, a mosquito can only travel in one of two directions, which is northeast or southwest.   The goal was to find the average distance a mosquito is from its home after a given life span.


The program TWALK would address a similar problem.  


N = number of trials


S = number of steps the mosquito (or whatever you want to imagine) walks in a single direction


Each trial calculates the final position.  The program draws a histogram of all the trails.   


TWALK gives two choices:


(-1, 1):  Each turn, the mosquito must move forward 1 step or backward 1 step


(-1, 0, 1):  Each turn, the mosquito must either move forward 1 step, move backward 1 step, or stay still for one turn. 



Drawing an Histogram Program in Casio Programming


Syntax:


S-Grph#  DrawOn, Hist, List x, 1, [ColorLinkOff], [Color] ColorLighter


# = Graph 1, 2, 3

List x = List 1 to List 26

Color Commands:  ColorLinkOff, 

Colors: One of 8 eight colors

ColorLighter: the fill of the color is lighter than the bar


The color commands are optional.  If you are using a Casio fx-9750GIII, leave of the color commands.



Casio fx-CG50 Program TWALK


Text:

'ProgramMode:RUN

"EWS 2022-08-04"

"RANDOM WALK 2.0"

"NO. TRIALS"?->N

N->Dim List 26

"NO. STEPS"?->S

Menu "STEPS","_(-)_1,1",2,"-1,0,1",3

Lbl 2:2->F:Goto 1

Lbl 3:3->F:Goto 1

Lbl 1

For 1->I To N

F=2=>Sum (2*RanInt#(0,1,S)-1)->List 26[I]

F=3=>Sum (RanInt#((-)1,1,S))->List 26[I]

Next

"POSITIONS LIST:"Disps

List 26Disps

(-)S->H Start

1->H pitch

S-Gph1 DrawOn,Hist,List 26,1,ColorLinkOff,Blue ColorLighter 

DrawStat



On the Screen:

"EWS 2022-08-04"

"RANDOM WALK 2.0"

"NO. TRIALS"?→N

N→Dim List 26

"NO. STEPS"?→S

Menu "STEPS","-1,1",2,"-1,0,1",3

Lbl 2:2→F:Goto 1

Lbl 3:3→F:Goto 1

Lbl 1

For 1->I To N

F=2⇒Sum (2×RanInt#(0,1,S)-1)→List 26[I]

F=3⇒Sum (RanInt#(-1,1,S))→List 26[I]

Next

"POSITIONS LIST:"◢

List 26◢

-S->H Start

1->H pitch

S-Gph1 DrawOn,Hist,List 26,1,ColorLinkOff,Blue ColorLighter 

DrawStat


Examples


N = 50, S = 5


(-1, 1):  Mosquito cannot rest





(-1, 0, 1): Mosquito can rest






Wishing you an excellent day,


Eddie 


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Casio fx-991CW: Input Output Formats

Casio fx-991CW: Input Output Formats The Four Formats There are four input/output formats that the Casio fx-991CW has. With eac...