The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Sun's Java site.
powered by NetLogo
view/download model file: logistic.nlogo
;;; logistic.nogo, cr 15 apr 2011 by rha on pro
globals
[
deltax deltay ;;; window widths for conversion routines
deltau deltav ;;; world coord window widths
umin umax vmin vmax ;;; from def of map-u and map-v
xmin xmax ymin ymax ;;; from Graphics Window attributes
u0 x0 ;;; init values
;;; R defined by a slider from 0 to 4
]
;;; procedures
;;; these are for coord conversion functions (affine isomorphisms)
to init-globals
set xmin ( - max-pxcor )
set xmax max-pxcor
set ymin ( - max-pycor )
set ymax max-pycor
set deltax world-width ;;; this is Graphics Window attribute
set deltay world-height ;;; this is Graphics Window attribute
set umin 0
set umax 1
set vmin 0
set vmax 1
set deltau (umax - umin)
set deltav (vmax - vmin)
set u0 0.5
set x0 map-x u0
end
;;; reporters
;;; ==============================================
;;; conversion functions, world-coords <--> turtle-screen-coords:
;;; horizontal: (u <--> x), vertical (v <--> y)
;;; ----------------------------------------------
;;; (u <-- x): u = convert(x)
to-report horizconvert [ x ]
let u (deltau * ( x - xmin ) / deltax) + umin
report u
end
;;; (u --> x): x = deconvert(u)
to-report horizdeconvert [ u ]
let x (deltax * ( u - umin ) / deltau) + xmin
report x
end
;;; (v <-- y): v = convert(y)
to-report vertconvert [ y ]
let v (deltav * ( y - ymin ) / deltay) + vmin
report v
end
;;; (v --> y): y = deconvert(v)
to-report vertdeconvert [ v ]
let y (deltay * ( v - vmin ) / deltav) + ymin
report y
end
;;; ==============================================
;;; more procedures
to setup
ca
init-globals
crt 1 ;;; turtle 0 draws diag and arch
[
ht ;;; hide
]
draw-diag
draw-arch
crt 1 ;;; turtle 1 draws red cobwebs
[
;;; ht ;;; hide
set color green ;;; only for cobwebs
setxy 0 0 ;;; init value dep on choice of u0
pd ;;; ready to draw
]
end
to draw-diag ;;; red diagonal
ask turtle 0
[
set color red
set pen-size 3 ;;; wider for the arch and diag, narrower for the cobwebs
pu ;;; ready to move
setxy xmin ymin ;;; first move
pd ;;; ready to draw
setxy 0 0 ;;; needs two steps
setxy xmax ymax
]
end
to draw-arch ;;; yellow graph of logistic function
ask turtle 0
[
set color yellow
set pen-size 3 ;;; wider for the arch and diag, narrower for the cobwebs
pu ;;; ready to move
let xnow xmin
let ynow ymin
setxy xnow ynow ;;; first move
pd ;;; ready to draw
repeat world-width - 1
[
set xnow xnow + 1
set ynow map-x xnow
setxy xnow ynow
]
]
end
to step
ask turtle 1
[
let xnew map-x xcor ;;; new x
setxy xcor xnew ;;; draw vertigo
setxy xnew xnew ;;; draw horrid
]
end
to clear
clear-drawing ;;; erase red diag, yellow arch, green cobweb
draw-arch
draw-diag
end
;; calculate the horizontal component of the map where the turtle is located
to-report map-x [ x ] ;; turtle procedure
let utemp1 horizconvert x
let utemp2 map-u utemp1
let xtemp horizdeconvert utemp2
report xtemp
end
;;; and at last, the logistic func in world coords
to-report map-u [ u ]
report R * u * (1 - u)
end
;;; end of nlogo code