Random walk 1-D

Random walk 1-D preview image

1 collaborator

Suman_saurabh Suman Saurabh (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.2.2 • Viewed 45 times • Downloaded 3 times • Run 0 times
Download the 'Random walk 1-D' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;; This code simulates random walk in one dimension by an agent in netlogo
;;Author: Suman Saurabh (saurabh@utexas.edu)
globals[loc-list]

turtles-own [loc dist]

to setup
  clear-all;
  create-turtles 1
  ask turtles[
    set shape "person"
    set color red
    set size 3
    set heading 90                                     ;; sets the heading for agent towards positive x-cordinate movement
    set loc xcor
    set dist 0
  ]
  set loc-list [0]
  reset-ticks;
end 

to go

  ask turtles[
  let tempi xcor                                       ;; declares a temporary variable that keeps the current x-cordinate of agent
  pen-down                                             ;; so that when agent moves, it marks the patch/path
  fd random size-of-step + add-bias                    ;; randomly selects the stepsize from 0 to maximum of size-of-step and then moves the agent forward. The add-bias will add bias to the moevement of agent
  let tempn xcor                                       ;; declares another variable that keeps the new x-cordinate value
  set dist dist + abs (tempi - tempn)                  ;; updates the distance travelled by agent
  bk random size-of-step                               ;; randomly selects the stepsize from 0 to maximum of size-of-step and then moves the agent backwards
  let tempf xcor                                       ;; updated x-cordinate of the agent
  set dist dist + abs (tempn - tempf)                  ;; updates the distance travelled by agent
  set loc-list lput xcor loc-list
  ]
  tick
end 

to-report mean-loc
  report mean loc-list
end 

to-report std-loc
  report standard-deviation loc-list
end 

;;Copyright 2022 @ Suman Saurabh (sumanan047@gmail.com; saurabh@utexas.edu)

There is only one version of this model, created about 2 years ago by Suman Saurabh.

Attached files

File Type Description Last updated
Random walk 1-D.png preview Preview for 'Random walk 1-D' about 2 years ago, by Suman Saurabh Download

This model does not have any ancestors.

This model does not have any descendants.