Calculate integral by Monte Carlo method
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
(a general understanding of what the model is trying to show or explain)
HOW IT WORKS
(what rules the agents use to create the overall behavior of the model)
HOW TO USE IT
(how to use the model, including a description of each of the items in the Interface tab)
THINGS TO NOTICE
(suggested things for the user to notice while running the model)
THINGS TO TRY
(suggested things for the user to try to do (move sliders, switches, etc.) with the model)
EXTENDING THE MODEL
(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)
NETLOGO FEATURES
(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)
RELATED MODELS
(models in the NetLogo Models Library and elsewhere which are of related interest)
CREDITS AND REFERENCES
(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)
Comments and Questions
;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; variable declarations ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; globals [ value-integral approx-integral scale-factor ] ;;;;;;;;;;;;;;;;;;;;;; ;; setup procedures ;; ;;;;;;;;;;;;;;;;;;;;;; to setup clear-all set scale-factor 25 resize-world 0 scale-factor 0 scale-factor set-default-shape turtles "dot" reset-ticks if (function = "y = x^5") [ set value-integral 1 / 6 ] if (function = "y = (cos x)^2") [ set value-integral 0.7273243567 ] if (function = "y = (sin (1/x))^2") [ set value-integral 0.6734567683 ] end to-report scale [ x ] report (x / scale-factor) end to-report degree [ x ] report (x * 180 / pi) end to-report value-function [ x ] if (function = "y = x^5") [ report (scale x) * (scale x) * (scale x) * (scale x) * (scale x) ] if (function = "y = (cos x)^2") [ report (cos (degree (scale x))) * (cos (degree (scale x))) ] if (function = "y = (sin (1/x))^2") [ report (sin (degree (1 / (scale x)))) * (sin (degree (1 / (scale x)))) ] end ;;;;;;;;;;;;;;;;;;;;;;;; ;; runtime procedures ;; ;;;;;;;;;;;;;;;;;;;;;;;; to go create-turtles 10 [ set size 0.5 setxy random-float scale-factor random-float scale-factor set color yellow if (ycor < scale-factor * (value-function xcor)) [ set color red ] ] set approx-integral (count turtles with [color = red]) / (count turtles) tick end
There are 3 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Calculate integral by Monte Carlo method.png | preview | Preview | almost 12 years ago, by Do Trong Thanh | Download |
This model does not have any ancestors.
This model does not have any descendants.