Monday 12/05/2011 (12 = One Dozen is a handful for 05 Five Fingers).

Monte Carlo and using the Formula for an Ellipse in honor of WRC Ellipticals.

CS 1025 - Dime Quarter LAC class...


VIP: Throwing 20 Darts - old Monte Carlo Quiz illustrates the concepts of the Monte Carlo simulation approach to estimating an unknown area using uniform random points within a larger known area. If the larger area is not known, you at the very least can estimate the proportion of some enclosed area using Monte Carlo "dart throwing".

powered by NetLogo

view/download model file: DrawOvalMonteCarlo.nlogo

WHAT IS IT?

Generate a randomX location and a randomY location for each turtle inside the turtle world, after drawing an Elliptical geometric object. Then choose the hatch either a cow if inside the Oval or build a House if outside the Oval. The turtle that hatched the cow or built the house dies. The count of houses and cows is used to estimate the proportion of the area the OVAL takes up. The entire known area is shown in the COUNT PATCHES Monitor.


HOW IT WORKS

Use the SLIDER to run the simulation with different numbers of turtles. 50, 100, 150, ... 950, 1000 are the 20 choices for how many turtles become Monte Carlo darts.


HOW TO USE IT

Adjust the height and width of the Ellipse by using the h and w sliders. When h = w, you have a special ellipse, i.e. a circle. Just as a square is a special instance of rectangle, where h = w.


THINGS TO NOTICE

When h is not equal to w, you have an ellipse, also known as an oval, also shaped like an egg. Seems only appropriate or at least poetic for TURTLE agents and LOGO Turtle Graphics.


THINGS TO TRY

This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model. Feel free to move the sliders and turn the SWITCH ON and OFF.


EXTENDING THE MODEL

Add a slider to draw the ellipse at different speeds, from a delay of 0 to a delay of perhaps 0.1 with the increment being 0.01 and the default being 0.01.

wait 0.01   ;; would become    wait drawEllipseDelay 
         
            ;; drawEllipseDelay slider would allow 0, 0.01, 0.02, 0.03, ... , 0.09, 0.1

The MonteCarlo procedure was created on December 5th and 6th, 2011.

This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.


The Ellipse drawing NetLogo was created during February 2010.

PROCEDURES

;; Tuesday - February 16 until 12:30 a.m. Wednesday February 17, 2010

globals [locX locY1 locY2 howFar]


breed [cows cow]
breed [houses house]



TO MonteCarlo
   if count turtles > 0 [ ca prepareIt ]
   
   if seePatches
   [
      checkerBoard
   ]
   
   cro howManyTurtles
   
   ask-concurrent turtles
   [     
     setxy random-xcor random-ycor
      
     set color black
     
     ifelse abs xcor <= w
     [
        SET locY1 sqrt ( abs (h * h * (1 - (xcor * xcor) / (w * w)) ))
        SET locY2 0 - locY1
        
        ifelse ycor >= locY2 and ycor <= locY1
        [
           hatch-cows 1 [ set shape "cow" set color black ]
           die
        ]
        [
           hatch-houses 1 [ set shape "house" set color green ]
           die
        ]
     ]
     [
        hatch-houses 1 [ set shape "house" set color green ]
        die
     ]
        
   ]  
END
   

TO checkerBoard
     ask patches 
     [
         ifelse remainder (pxcor + pycor) 2 = 0
         [
            set pcolor white
         ]
         [
            set pcolor yellow
         ]
     ]  
END
  

TO prepareIt
   ca
   
   cro 2
   
   ask patches [ set pcolor white ]
   
   ask-concurrent turtles [ OVAL ]
END 
 


TO OVAL
   pu
   
   set howFar (2 * w / 300)
   set locX w
   
   setxy locX 0
   
   pd
   set pen-size 2
   set color blue
   
   REPEAT 300
      [
         wait 0.01
         set locX xcor - howFar
         
         SET locY1 sqrt ( abs (h * h * (1 - (locX * locX) / (w * w)) ))
         SET locY2 0 - locY1
         
         ifelse (remainder who 2 = 0) 
         [
           facexy locX locY1 
           setxy locX locY1
         ]
         [
           facexy locX locY2 
           setxy locX locY2
         ]
         
         ;; SET locX locX - howFar
      ]
   
   wait 1
   
   die
         
END