Random Walk Periodic Boundary Condition 2D Lattice

Random Walk Periodic Boundary Condition 2D Lattice 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 everyone
Model was written in NetLogo 5.0.4 • Viewed 621 times • Downloaded 34 times • Run 0 times
Download the 'Random Walk Periodic Boundary Condition 2D Lattice' 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
[
  root-mean-square
  sum-distance
  sum-prob
  west-prob-scale
  east-prob-scale
  north-prob-scale
  south-prob-scale
  prob
]

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

;; set up the patches and creates turtles

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

to setup-turtles
  crt number-of-particles
  [
    set color black
    pen-down
  ]
end 

to init-constant
  set sum-prob (west-prob + east-prob + north-prob + south-prob)
  set west-prob-scale (west-prob / sum-prob)
  set east-prob-scale (east-prob / sum-prob)
  set north-prob-scale (north-prob / sum-prob)
  set south-prob-scale (south-prob / sum-prob)
end 

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

to go
  ;; have the turtles randomly pick north, south, west, east and
  ;; move in that direction
  ask turtles
  [
    set color blue
    set prob (random-float 1)
    if (prob < west-prob-scale)
    [
      ;; go west
      set heading 270
      forward 1
    ]
    if (prob > west-prob-scale) and (prob < west-prob-scale + east-prob-scale)
    [
      ;; go east
      set heading 90
      forward 1
    ]
    if (prob > west-prob-scale + east-prob-scale) and (prob < west-prob-scale + east-prob-scale + north-prob-scale)
    [
      ;; go north 
      set heading 0
      forward 1
    ]
    if (prob > west-prob-scale + east-prob-scale + north-prob-scale)
    [
      ;; go south
      set heading 180
      forward 1
    ]
    set color black  
  ]
  ;; calculate root mean square of distance of all particles
  set sum-distance 0
  foreach sort turtles
  [
    ask ? [ set sum-distance (sum-distance + (xcor * xcor + ycor * ycor)) ]
  ]
  set root-mean-square (sqrt (sum-distance / (count turtles)))
  tick
end 

There are 4 versions of this model.

Uploaded by When Description Download
Do Trong Thanh over 10 years ago Wrong model uploaded, this is correction Download this version
Do Trong Thanh over 10 years ago Fix heading Download this version
Do Trong Thanh over 10 years ago Change to wrap world Download this version
Do Trong Thanh over 10 years ago Initial upload Download this version

Attached files

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

This model does not have any ancestors.

This model does not have any descendants.