Search code examples
netlogodivisiongamma

NetLogo: How do I use random-gamma and division for the same calculation formula without any error?


I am using random-gamma with NetLogo. When I add division to the syntax of random-gamma, NetLogo gets an error. The following is an example of calculation syntax using random-gamma. (In addition, these variables "number-dead, S, T" are registered in global variables.) In my simulation it is necessary to add division after random-gamma calculation result. What should I do? Please give some advice to this. We thank you for your cooperation.

set sim precision((number-dead * random-gamma(1 / (S * S))(1 / (T * (S * S)))) / number-dead)3

The following is a popup message when an error occurs.

It is divided by 0. error while observer running / called by procedure GOPARALLEL called by button 'goparallel'


Solution

  • I don't think the problem has anything to do with random-gamma. Either S, T, or number-dead are likely to be 0.

    If S is 0, then both (1 / (S * S)) and (1 / (T * (S * S))) will result in division by 0.

    If T is 0, then (1 / (T * (S * S))) will result in a division by 0.

    If number-dead is 0, then (number-dead * random-gamma (1 / (S * S)) (1 / (T * (S * S)))) / number-dead) will result in a division by 0.

    Also, I think that code is wrong. It's essentially doing:

    let rand random-gamma (1 / (S * S)) (1 / (T * (S * S)))
    let raw-num number-dead * rand / number-dead
    set sim precision raw-num 3
    

    That is, you're multiplying the result of random-gamma by number-dead, and then immediately dividing the result of that by number-dead, which just leaves you with the result of random-gamma. So I think you may have misplaced some parentheses or something.