Random Walk Periodic Boundary Condition

Random Walk Periodic Boundary Condition preview image

1 collaborator

Default-person Do Trong Thanh (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.4 • Viewed 387 times • Downloaded 35 times • Run 0 times
Download the 'Random Walk Periodic Boundary Condition' 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

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; variable declarations ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

globals
[
  sum-distance
  root-mean-square
]

;;;;;;;;;;;;;;;;;;;;;;
;; setup procedures ;;
;;;;;;;;;;;;;;;;;;;;;;

;; set up the patches and creates turtles

to setup
  clear-all
  set-patch-size (200 / boundary)
  resize-world (- boundary) boundary 0 (boundary * 2)
  ask patches [ set pcolor gray + 3 ]
  setup-turtles
  reset-ticks
end 

;; determines the number of turtles and their color

to setup-turtles
  ;; the origin is at the bottom of the view so there is no need
  ;; to relocate the turtles upon creation
  crt number-of-particles
  [
    set color black
    ;; set pen-size 3
    set heading 0
    pd
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;
;; runtime procedures ;;
;;;;;;;;;;;;;;;;;;;;;;;;

to go
  if any? turtles with [ patch-at 0 1 = nobody ]
  [ 
    ask turtles [ set ycor 0 ]
    clear-drawing
  ]
  
  ;; have the turtles randomly pick either right or left and
  ;; move in that direction
  ask turtles
  [
    ifelse ((random-float 1) < left-probability )
    [
      ;; go left
      set heading 90
      forward 1
      set heading 0
      forward 1
    ]
    [
      ;; go right
      set heading 270
      forward 1
      set heading 0
      forward 1
    ]
    
    ;; set the color of the turtles to give a rough idea of how many turtles
    ;; are at each location -- the lighter the color, the greater the number
    ;; of turtles
    set color scale-color blue (count turtles-here) (number-of-particles / 5) 0
  ]

  ;; calculate root mean square of distance of all particles
  set sum-distance 0
  foreach sort turtles
  [
    ask ? [ set sum-distance (sum-distance + xcor * xcor) ]
  ]
  set root-mean-square (sqrt (sum-distance / (count turtles)))
  tick
end 

There are 2 versions of this model.

Uploaded by When Description Download
Do Trong Thanh over 10 years ago Add root mean square plot Download this version
Do Trong Thanh almost 11 years ago Initial upload Download this version

Attached files

File Type Description Last updated
Random Walk Periodic Boundary Condition.png preview Preview over 10 years ago, by Do Trong Thanh Download

This model does not have any ancestors.

This model does not have any descendants.