globals [ ticks ; how many clock ticks have passed ] turtles-own [ xc ; unwrapped xcor yc ; unwrapped ycor dist ; distance from home using xc, yc ] to setup ca set ticks 0 ; if the user so chooses, draw rings around (0, 0) to give a sense of how far turtles have traveled ; the furthest on-screen distance from home is screen-edge * sqrt (2) if draw-rings? [ ask patches [ if (pxcor = 0) [ set pcolor 3 ] ; y axis if (pycor = 0) [ set pcolor 3 ] ; x axis if (int ((distancexy 0 0) mod ring-radius) = 0) ; rings [ set pcolor 3 ] ] ] crt num-turtles setup-plots draw-plots end to go ask turtles [ ; head in a random direction rt random-float 360 set xc xc + (step-size * cos heading) set yc yc + (step-size * sin heading) ; hide turtles who have moved off the screen ifelse (abs xc > screen-edge-x) or (abs yc > screen-edge-y) [ ht ] [ st set xcor xc set ycor yc ] set dist sqrt (xc * xc + yc * yc) ] set ticks (ticks + 1) draw-plots end to setup-plots set-current-plot "Average Distance" set-plot-y-range 0 (5 * step-size) set-current-plot "Average X-Distance" set-plot-y-range 0 (5 * step-size) set-current-plot "Std.Dev. of Distance" set-plot-y-range 0 (5 * step-size) end to draw-plots ; plot the average distance of all the turtles from (0,0) set-current-plot "Average Distance" plot ((sum values-from turtles [ dist ]) / count turtles) ; plot the average xc of all the turtles set-current-plot "Average X-Distance" plot (sum values-from turtles [abs xc]) / num-turtles ; plot the standard deviation of the distance of all the turtles from (0,0) set-current-plot "Std.Dev. of Distance" plot (standard-deviation values-from turtles [ dist ]) end ; *** NetLogo Model Copyright Notice *** ; ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML). The project gratefully acknowledges the support of the ; National Science Foundation (Applications of Advanced Technologies ; Program) -- grant numbers RED #9552950 and REC #9632612. ; ; Copyright 1998 by Uri Wilensky. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; This model was converted to NetLogo as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; Converted from StarLogoT to NetLogo, 2001. Updated 2002. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1998). NetLogo Random Walk 360 model. ; http://ccl.northwestern.edu/netlogo/models/RandomWalk360. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/RandomWalk360 ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 290 10 605 346 30 30 5.0 1 10 1 1 1 CC-WINDOW 2 249 286 345 Command Center BUTTON 160 50 220 83 Go go T 1 T OBSERVER T BUTTON 77 50 148 83 Go Once go NIL 1 T OBSERVER T BUTTON 4 50 64 83 Setup setup NIL 1 T OBSERVER T SLIDER 164 101 283 134 step-size step-size 1.0 10.0 1.0 1.0 1 NIL SLIDER 126 150 284 183 ring-radius ring-radius 5.0 20.0 10.0 1.0 1 NIL SLIDER 2 101 161 134 num-turtles num-turtles 0 1000 500 10 1 NIL SWITCH 4 150 122 183 draw-rings? draw-rings? 0 1 -1000 PLOT 2 350 231 507 Average Distance Time Avg Dist 0.0 100.0 0.0 10.0 true false PENS "default" 1.0 0 -16776961 true PLOT 232 350 474 507 Average X-Distance Time Avg Dist 0.0 100.0 0.0 10.0 true false PENS "default" 1.0 0 -65536 true PLOT 476 350 708 507 Std.Dev. of Distance Time Std Dev 0.0 100.0 0.0 10.0 true false PENS "default" 1.0 0 -11352576 true MONITOR 70 194 139 243 Clock ticks 3 1 @#$#@#$#@ WHAT IS IT? ----------- In this model the turtles engage in a "random walk." Each turtle walks one step away from its current location in a different random direction at each clock tick. This movement is known as walking a 360-gon "lattice." A lattice is a set of points on the plane (or in space) that form a grid on which turtles walk. As the simulation continues, one can expect the turtles to become more spread out. Will they ever return home (to their point of origin at 0 0)? Observe the kinds of patterns that develop as the turtles move. HOW TO USE IT ------------- General Settings ---------------- Use the NUM-TURTLES slider to select how many turtles will participate in the random walk. Use the STEP-SIZE slider to decide how far from its current location a turtle will move on each step. How steps are implemented: if STEP-SIZE is set to n it will add (n * cos(theta)) to its current xcor value and it will add (n * sin(theta)) to its current ycor value. It will have moved n patch units from its current location. (Why?) Each of the above movements would be considered a single "pace." Distance Rings -------------- Set DRAW-RINGS to ON to draw the x-axis, y-axis, and a set of concentric circles about the point (0 0). This switch must be set prior to pressing SETUP. Use the RING-RADIUS slider to set the incremental distance between the distance rings. Plots ------------ "Average Distance" - measures the average distance over all turtles, from home (the origin at 0,0) to their current coordinates. "Average X-Distance" - measures the average distance over all turtles along the x-axis away from the origin (x = 0). "Std.Dev. of Distance" - measures the standard deviation of all turtles' true distance from home to their current position. NetLogo's standard deviation primitive is used. Note that xcor and ycor values are stored in such a way that turtles are tracked even if they move off the screen. These 'off screen' values are used to measure distances. They are stored at turtle variable xc (for xcor) and yc (for ycor). Distances are either zero or positive. Monitors -------- The CLOCK monitor displays how many paces the turtles have taken. Buttons ------- Press SETUP when all of the above selections have been made. This will create the selected number of turtles at the bottom center of the screen. Press GO-ONCE to make the turtles move one pace. Press GO to make the turtles move continuously. To stop the turtles, press the GO button again. RUNNING THE MODEL ----------------- Try starting with 500 turtles with a step size of 1. If you want to show distance rings, try setting the radius increment to 20. Press SETUP then press GO. The turtles all start at (0,0) (home). Think about how you would define an 'average' turtle and an 'average' walk. Where would you expect an average turtle to end up at a given time? Why? Will all turtles eventually return home? If so, how many paces would you expect a turtle to travel before it returned to home? Why? What kinds of calculations or measurements would you use in trying to answer these questions? THINGS TO NOTICE ---------------- Two characteristics of the plots you see are their smoothness and their slope. To think about smoothness of the plots, notice how much the lines move up and down over time. To think about slope of the plots, consider whether the plot appears to be going 'uphill' or 'downhill' and consider whether the 'hill' is steep or flat. What do you notice about the smoothness and slope of the plots? - Are they smooth? Why or why not? - Are they steep? Why or why not? - For a given plot, is its steepness the same at the far edges and at the center? Why or why not? Does the plot have any symmetry? Would you expect it to? Why? Does a single line plot ever change between positive and negative slopes? Why or why not? If it does, what does that mean? THINGS TO TRY ------------- Try to answer the following questions before running the simulations. Record your predictions. Compare your predicted results with the actual results. - What reasoning led you to correct predictions? - What assumptions that you made need to be revised? Try different numbers of turtles while keeping all other slider values the same. - What happens to the plot's smoothness and slope when the number of turtles is increased? - What happens to the plot's smoothness and slope when the number of turtles is decreased? - Does the simulation finish faster or slower than the first model? Try different numbers of steps while keeping all other slider values the same. - What happens to the plot's smoothness and slope when the number of steps is increased? - What happens to the plot's smoothness and slope when the number of turtles is decreased? - Does the simulation finish faster or slower than the first model? How do your answers to the above questions compare to the average values calculated for all turtles in a given simulation? EXTENDING THE MODEL ------------------- In this simulation, turtles can only move based on integer values of heading. Change the model so that any value of heading between 0 and 360 degrees is possible. Does this change the amount of time it would take for a turtle to return home? How? Why? How does this change impact answers to other questions asked above? One of the plots measures the average x-distance away from the origin over all turtles. Obviously, it could have measured the y-distance instead. Watch the plot under one run of the model, and then change the procedure so that it measures y-distance. How do the plots differ? Create a new monitor called home-turtles. Have it display the number of turtles at (or very near) home. Create a plot to display this information. NETLOGO FEATURES ----------------- Since NetLogo's default behavior is for turtles to "wrap", the special code below is needed for this model to simulate an infinite plane on which turtles are walking. set xc xc + (step-size * cos heading) set yc yc + (step-size * sin heading) ; hide turtles who have moved off the screen ifelse (abs xc > screen-edge-x) or (abs yc > screen-edge-y) [ ht ] [ st set xcor xc set ycor yc ] set dist sqrt (xc * xc + yc * yc) This model takes advantage of NetLogo's multiple plots. There are three different plots available at any one time. The auto-plot-on command allows the plots to be automatically resized once a plot pen reaches the borders of a plot. Coloring of patches is used to draw a polar coordinate grid on the turtle screen. CREDITS AND REFERENCES ---------------------- To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo Random Walk 360 model. http://ccl.northwestern.edu/netlogo/models/RandomWalk360. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 1998 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/RandomWalk360 for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 arrow true 0 Polygon -7566196 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box true 0 Polygon -7566196 true true 45 255 255 255 255 45 45 45 circle true 0 Circle -7566196 true true 35 35 230 person false 0 Circle -7566196 true true 155 20 63 Rectangle -7566196 true true 158 79 217 164 Polygon -7566196 true true 158 81 110 129 131 143 158 109 165 110 Polygon -7566196 true true 216 83 267 123 248 143 215 107 Polygon -7566196 true true 167 163 145 234 183 234 183 163 Polygon -7566196 true true 195 163 195 233 227 233 206 159 spacecraft true 0 Polygon -7566196 true true 150 0 180 135 255 255 225 240 150 180 75 240 45 255 120 135 thin-arrow true 0 Polygon -7566196 true true 150 0 0 150 120 150 120 293 180 293 180 150 300 150 truck-down false 0 Polygon -7566196 true true 225 30 225 270 120 270 105 210 60 180 45 30 105 60 105 30 Polygon -8716033 true false 195 75 195 120 240 120 240 75 Polygon -8716033 true false 195 225 195 180 240 180 240 225 truck-left false 0 Polygon -7566196 true true 120 135 225 135 225 210 75 210 75 165 105 165 Polygon -8716033 true false 90 210 105 225 120 210 Polygon -8716033 true false 180 210 195 225 210 210 truck-right false 0 Polygon -7566196 true true 180 135 75 135 75 210 225 210 225 165 195 165 Polygon -8716033 true false 210 210 195 225 180 210 Polygon -8716033 true false 120 210 105 225 90 210 turtle true 0 Polygon -7566196 true true 138 75 162 75 165 105 225 105 225 142 195 135 195 187 225 195 225 225 195 217 195 202 105 202 105 217 75 225 75 195 105 187 105 135 75 142 75 105 135 105 @#$#@#$#@ NetLogo 2.0beta1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@