This page was automatically generated by NetLogo 5.0.1.

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 Oracle's Java site.


In order for this to work, this file, your model file (sintest10.nlogo), and the files NetLogoLite.jar and NetLogoLite.jar.pack.gz must all be in the same directory. (You can copy NetLogoLite.jar and NetLogoLite.jar.pack.gz from the directory where you installed NetLogo.)

On some systems, you can test the applet locally on your computer before uploading it to a web server. It doesn't work on all systems, though, so if it doesn't work from your hard drive, please try uploading it to a web server.

You don't need to include everything in this file in your page. If you want, you can just take the HTML code beginning with <applet> and ending with </applet>, and paste it into any HTML file you want. It's even OK to put multiple <applet> tags on a single page.

If the NetLogoLite files and your model are in different directories, you must modify the archive= and value= lines in the HTML code to point to their actual locations. (For example, if you have multiple applets in different directories on the same web server, you may want to put a single copy of the NetLogoLite files in one central place and change the archive= lines of all the HTML files to point to that one central copy. This will save disk space for you and download time for your users.)

powered by NetLogo

view/download model file: sintest10.nlogo

WHAT IS IT?

A demo showing how many ants can do integral calculus.

HOW IT WORKS

You choose 3 different sine waves that are added together to display a periodic wave form. Many ants then proceed to measure the area under each multiple of possible waves, to decide which sine waves were necessary to produce the displayed periodic wave form.

HOW TO USE IT

Use the sliders to choose frequencies of the 3 different sine waves that will produce the displayed wave form. The “setup” button computes the displayed wave form and shows it. The “go” button will start the ants measuring the area under different curves that are multiples of all possible original waves.

THINGS TO NOTICE.

Measuring the area under a curve with only ants is easy, therefore integral calculus is easy using many discrete ants.

EXTENDING THE MODEL

Add more initial wave forms to add to the displayed one.
Figure out how handle different amplitudes of waveforms.

CREDITS AND REFERENCES

Thanks to many very cleaver people. Especially Fourier.

CODE


;;sintest2
;; Selcts and draw 2 sine waves in red, then the addition of those two waves in blue
;;uses separate breeds for drawing the waves and total wave during setup
;; sintest3----An ant wanders around random...If it hits xcor=0 then it goes due north till it hits a blue pcolor. 
;; sintest4---sort of works...totunder does not get above or below 3000 in 1000 measures.
;;sinetest6--works for only one test curve
;;sinetest7--works with 5 but lies ..cant determine number of big vs small totunders
;;sinetest8-- convert final totunders to % Doesn't work ...it mixes different undercounters
;;sinetest9-- makes each each ant that hits the xaxis do a loop. This works
;;sinetest10--cleanup and extra wave and 10freqs

breed [ s1s s1  ]
s1s-own [ feq ]
breed [ s2s s2 ]
s2s-own [ feq ]
breed [s3s s3 ]
breed [stots stot ]
stots-own [ feq ]
breed [tc1s tc1]
breed [tc2s tc2 ]
breed [tc3s tc3]
breed [tc4s tc4 ]
breed [tc5s tc5 ]
breed [tc6s tc6]
breed [tc7s tc7 ]
breed [tc8s tc8]
breed [tc9s tc9 ]
breed [tc10s tc10 ]
breed [ ants ant ]
ants-own [  totundercurve]
globals [
 time
 s2sy
 s1sy
 s3sy
 totunder1
 totunder2
 totunder3
 totunder4
 totunder5
 counter
 perunder1
 perunder2
 perunder3
 perunder4
 perunder5
totunder6
 totunder7
 totunder8
 totunder9
 totunder10

 perunder6
 perunder7
 perunder8
 perunder9
 perunder10
 totperunder
 loopcounter
 sizeofwave
  ] 

patches-own [ 
  tcc1
  tcc2
  tcc3
  tcc4
  tcc5
  tcc6
  tcc7
  tcc8
  tcc9
  tcc10 ]

to setup
clear-all
;;  __clear-all-and-reset-ticks
  clear-output
  
  create-ants 25 [
  setxy random-xcor random-ycor
  set size 10
 ;; set color red
;; pen-down
]

create-s1s 1 [
  setxy 0 0 
]
create-s2s 1 [
  setxy 0 0
   set color 12
 
]
create-s3s 1 [
  setxy 0 0
   set color 12
 
]

create-stots 1 [
  setxy 0 0
  set color 96
    set pen-size 3
   ]
create-tc1s 1 [
  setxy 0 0
  set color 65
    set pen-size 3
   ]
create-tc2s 1 [
  setxy 0 0
  set color 67
    set pen-size 3
   ]
create-tc3s 1 [
  setxy 0 0
  set color 68
    set pen-size 3
   ]
create-tc4s 1 [
  setxy 0 0
  set color 69
    set pen-size 3
   ]
create-tc5s 1 [
  setxy 0 0
  set color 63
    set pen-size 3
   ]
create-tc6s 1 [
  setxy 0 0
  set color 65
    set pen-size 3
   ]
create-tc7s 1 [
  setxy 0 0
  set color 67
    set pen-size 3
   ]
create-tc8s 1 [
  setxy 0 0
  set color 68
    set pen-size 3
   ]
create-tc9s 1 [
  setxy 0 0
  set color 69
    set pen-size 3
   ]
create-tc10s 1 [
  setxy 0 0
  set color 63
    set pen-size 3
   ]

set time 0
set sizeofwave 60

ask patches [
  if pycor = 0 [ set pcolor 45 ] 
  if (pxcor = 360) or (pxcor = 0 ) or (pxcor = 720 ) [
    set pcolor 44 ]
  ]
    loop [
 if time >= 720 [ stop ]
  
  ask s1s [
   ;; pen-down
      set s1sy (sin (time * FreqOfCurve1 ))
     
  setxy time (sizeofwave * s1sy)
  ]
    ask s2s [
       ;;  pen-down
    set s2sy (sin (time * FreqOfCurve2))
  setxy time ( sizeofwave * s2sy)
  ]
        ask s3s [
     ;;    pen-down
    set s3sy (sin (time * FreqOfCurve3))
  setxy time (s3sy *  sizeofwave   )
  ]
;;   if time >= 180 [ 
;;     show s1sy
;;     show s2sy
;;     show s3sy
;;     show ( s1sy + s2sy + s3sy )
     
 ;;    stop ]
    
        ask stots [ 
  setxy time (sizeofwave * ( s1sy + s2sy + s3sy ) )
  set pcolor 96
  ]
        
        ask tc1s [
          setxy time  (sizeofwave * ( s1sy + s2sy + s3sy) * sin (time * 1 ))
          ask patch-here [ 
        ;;  set pcolor 44
            set tcc1 1 ]
        ]
        
            ask tc2s [
          setxy time  (sizeofwave * ( s1sy + s2sy + s3sy ) * sin (time * 2 ))
          
          ask patch-here [ 
       ;;     set pcolor 64
            set tcc2 2 ]
        ]    
                    ask tc3s [
          setxy time  (sizeofwave * ( s1sy + s2sy + s3sy  ) * sin (time * 3 ))
          ask patch-here [ 
         ;;  set pcolor 24
            set tcc3 3 ]
        ]
        
            ask tc4s [
          setxy time  (sizeofwave * ( s1sy + s2sy + s3sy  ) * sin (time * 4 ))
          
          ask patch-here [ 
           ;; set pcolor 84
            set tcc4 4 ]
        ]    
                       ask tc5s [
          setxy time  (sizeofwave * ( s1sy + s2sy + s3sy  ) * sin (time * 5 ))
          
          ask patch-here [ 
           ;; set pcolor 134
            set tcc5 5 ]
        ]    
                       ask tc6s [
          setxy time  (sizeofwave * ( s1sy + s2sy + s3sy) * sin (time * 6 ))
          ask patch-here [ 
        ;;  set pcolor 44
            set tcc6 6 ]
        ]
        
            ask tc7s [
          setxy time  (sizeofwave * ( s1sy + s2sy + s3sy ) * sin (time * 7 ))
          
          ask patch-here [ 
       ;;     set pcolor 64
            set tcc7 7 ]
        ]    
                    ask tc8s [
          setxy time  (sizeofwave * ( s1sy + s2sy + s3sy  ) * sin (time * 8 ))
          ask patch-here [ 
         ;;  set pcolor 24
            set tcc8 8 ]
        ]
        
            ask tc9s [
          setxy time  (sizeofwave * ( s1sy + s2sy + s3sy  ) * sin (time * 9 ))
          
          ask patch-here [ 
           ;; set pcolor 84
            set tcc9 9 ]
        ]    
                       ask tc10s [
          setxy time  (sizeofwave * ( s1sy + s2sy + s3sy  ) * sin (time * 10 ))
          
          ask patch-here [ 
           ;; set pcolor 134
            set tcc10 10 ]
        ]    
        
   set time (time + .1)
 ] ;;;end ask patches
   
   reset-ticks
end

to go
  
  Ask ants [
    walk
   
    If pcolor = 45 [ ;;ant tc1 just hit the x axis
     ifelse random 2 < 1 [ set heading 0 ][set heading 180]
    pen-down
        loop [          ;;
        fd 1
       
        if ([tcc1] of patch-here ) = 1 [ 
          set totunder1 (totunder1 + ycor)
           set counter (counter + 1)
           pen-up
          ]
          if ([tcc2] of patch-here ) = 2 [ 
          set totunder2 (totunder2 + ycor)
           pen-up
          ]
           if ([tcc3] of patch-here ) = 3 [ 
          set totunder3 (totunder3 + ycor)
           pen-up
          ]
            if ([tcc4] of patch-here ) = 4 [ 
          set totunder4 (totunder4 + ycor)
           pen-up
          ]
             if ([tcc5] of patch-here ) = 5 [ 
          set totunder5 (totunder5 + ycor)
           pen-up
          ]
          if ([tcc6] of patch-here ) = 6 [ 
          set totunder6 (totunder6 + ycor)

           pen-up
          ]
          if ([tcc7] of patch-here ) = 7 [ 
          set totunder7 (totunder7 + ycor)
           pen-up
          ]
           if ([tcc8] of patch-here ) = 8 [ 
          set totunder8 (totunder8 + ycor)
           pen-up
          ]
            if ([tcc9] of patch-here ) = 9 [ 
          set totunder9 (totunder9 + ycor)
           pen-up
          ]
             if ([tcc10] of patch-here ) = 10 [ 
          set totunder10 (totunder10 + ycor)
           pen-up
          ]
        set loopcounter (loopcounter + 1)
      ;;  show loopcounter
        if loopcounter = 400 [ 
          set loopcounter 0
          pen-up
          setxy random-pxcor random-pycor
          ;;pen-down
          stop ]
        
        ]  ;;end loop
        ]  ;end end if 45
     ;;   pen-up
    ] ;;end ask
   
 
  if counter > 15000 [ 
    
      set totperunder (abs totunder1 + abs totunder2 + abs totunder3 + abs totunder4 + abs totunder5 + abs totunder6 + abs totunder7 + abs totunder8 + abs totunder9 + abs totunder10)
  set perunder1 (abs totunder1 / totperunder)
   set perunder2 (abs totunder2 / totperunder)
    set perunder3 (abs totunder3 / totperunder)
     set perunder4 (abs totunder4 / totperunder)
      set perunder5 (abs totunder5 / totperunder)
  set perunder6 (abs totunder6 / totperunder)
   set perunder7 (abs totunder7 / totperunder)
    set perunder8 (abs totunder8 / totperunder)
     set perunder9 (abs totunder9 / totperunder)
      set perunder10 (abs totunder10 / totperunder)
 
;; print perunder1
;; plot perunder1
;;  print perunder2
;;plot perunder2
;;print perunder3
;;plot perunder3
;;print perunder4
;;plot perunder4
;;  print perunder3
;;  print perunder4
;;  print perunder5
 ;; print perunder6
;;  print perunder7
;;  print perunder8
;;  print perunder9
;;  print perunder10
    
    
    
    
    output-print "This curve is"
    output-print "made up of:"
    
    if perunder1 > .15 [
           output-print "1 HZ curve"
           
     ]
     if perunder2 > .15 [
           output-print "2 HZ curve"
     ]
     
   
    if perunder3 > .15 [
           output-print "3 HZ curve"
           
     ]
     if perunder4 > .15 [
           output-print "4 HZ curve"
     ]
      if perunder5 > .15 [
           output-print "5 HZ curve"
     ]
        if perunder6 > .15 [
           output-print "6 HZ curve"
           
     ]
     if perunder7 > .15 [
           output-print "7 HZ curve"
     ]
     
   
    if perunder8 > .15 [
           output-print "8 HZ curve"
           
     ]
     if perunder9 > .15 [
           output-print "9 HZ curve"
     ]
      if perunder10 > .15 [
           output-print "10 HZ curve"
     ]
    stop
  ]
end


to walk
  right random 30
  left random 30
  fd 1
end