Created
October 8, 2013 20:52
-
-
Save mihi-tr/6891462 to your computer and use it in GitHub Desktop.
SensitiveDependence - a DRY version of the SensitiveDependence NetLogo script from complexityexplorer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
turtles-own [xc xn] | |
to setup | |
;; (for this model to work with NetLogo's new plotting features, | |
;; __clear-all-and-reset-ticks should be replaced with clear-all at | |
;; the beginning of your setup procedure and reset-ticks at the end | |
;; of the procedure.) | |
;;__clear-all-and-reset-ticks | |
clear-all | |
draw-axes | |
draw-parabola | |
;; create the turtles in one go | |
create-turtles 3 | |
[ | |
set shape "dot" | |
set size 5 | |
set xc x0 | |
set label-color black | |
] | |
let x-list (list x0 x0' x0'') | |
;; initialize the turtles | |
(foreach [2 3 4] [0 1 2] [5 3 2] [blue red yellow] | |
[ask turtle ?1 | |
[ | |
set xc item ?2 x-list | |
set size ?3 | |
set color ?4 | |
]]) | |
;; do the first calculation | |
ask turtles | |
[ | |
set xn (R * xc * (1 - xc)) | |
set xcor (xc * max-pxcor) | |
set ycor (xn * max-pycor) | |
set label (word precision xc 3 "," precision xn 3) | |
] | |
reset-ticks | |
end | |
to go | |
iterate ; do one iteration of logistic map | |
; update-plot | |
wait .1 | |
tick ; increase tick number by 1 | |
end | |
to iterate | |
ask turtles | |
[ | |
set xc xn | |
set xn (R * xc * (1 - xc)) | |
set xcor (xc * max-pxcor) | |
set ycor (xn * max-pycor) | |
set label (word precision xc 3 "," precision xn 3) | |
] | |
end | |
to draw-axes ; draws x and y axes | |
ask patches | |
[set pcolor white] | |
create-turtles 1 | |
ask turtles | |
[ | |
set color black | |
set xcor min-pxcor | |
set ycor min-pycor | |
set heading 0 | |
pen-down | |
fd max-pycor ; draw y axis | |
pen-up | |
set xcor min-pxcor | |
set ycor min-pycor | |
set heading 90 | |
pen-down | |
fd max-pxcor ; draw x axis | |
die | |
] | |
end | |
to draw-parabola ; draws parabola representing logistic map for given value of R | |
let x 0 | |
let y 0 | |
create-turtles 1 | |
ask turtles | |
[ | |
set color black | |
set xcor x * min-pxcor | |
set ycor y * min-pycor | |
pen-down | |
] | |
repeat 10000 | |
[ | |
set x (x + .0001) | |
ask turtles | |
[ | |
set xcor (x * max-pxcor) | |
set ycor (R * x * (1 - x)) * max-pycor | |
] | |
] | |
ask turtles [die] | |
end | |
to-report x-current | |
ifelse turtle 2 != nobody [ | |
report [xc] of (turtle 2) | |
] | |
[report x0 | |
] | |
end | |
to-report x-new | |
report [xn] of turtle 2 | |
end | |
to-report x-current' | |
ifelse turtle 3 != nobody [ | |
report [xc] of (turtle 4) | |
] | |
[ | |
report x0' | |
] | |
end | |
to-report x-new' | |
report [xn] of turtle 3 | |
end | |
to-report x-current'' | |
ifelse turtle 4 != nobody [ | |
report [xc] of (turtle 4) | |
] | |
[ | |
report x0'' | |
] | |
end | |
;;plotting procedures ------------------- | |
to setup-plot | |
set-current-plot "logistic map" | |
set-plot-x-range 0 1 | |
set-plot-y-range 0 1 | |
end | |
to update-plot | |
set-current-plot-pen "x" | |
plot x-current | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment