I get an error saying "It is dividing by 0". How can I avoid the "dividing by 0" error during the dividing process compiling with Behavior space of Netlogo? This is a Run-time Error popup message. " It is divided by 0. Error while observer running / Called by procedure GO, Called by button 'go' " The following is sample program. The variable "number-of-stop" means that number of ticks while stopping the turtles stopped on the road, and "number-of-dead" means that the number of dead turtles. Behavior space collects the data by every tick. When the variable is 0, the divide-by-zero error occurs. Are there any ideas? Thank you.
globals [ Ans number-of-stop number-of-dead ]
set Ans precision((number-of-stop) / (number-of-dead))3
just set a test before doing the calculation, for example (not tested):
set Ans ifelse-value (number-of-dead = 0)
[ -1 ]
[ precision((number-of-stop) / (number-of-dead))3 ]
This sets the value to -1 if the denominator is 0 and only does the division if the test fails (that is, if number-of-dead is not 0)