mathnetlogofractionsagent-based-modeling

Looking for a logic to keep a fraction in a range


I need to write some code that can calculate a variable which shows the preference of a consumer to buy a component for his laptop. The preference changes by the tax (T) and the importance of prices on people's purchases (PriceI). I need to include both T and PriceI to find the person's willingness (W) for purchasing a laptop. Tax changes in a slider ranging from 50 Cent to $6 . I want to keep the variable W in a range from 1 to 2, where 1 is when the tax is on its default, minimum values which is 50 cent.

So There are 2 variables that have influence on W:

50<T<600
0.6 < PriceI < 9

Since I want 1<W<2, I thought it should work if I first normalize all the data by dividing them by their max, then in order to find a fraction to be between 1 and 2, I made the numerator to be less than 4 and the denominator to be less than 2, hoping to have the result between 1 to 2 :

    to setup-WCalculator
ask consumers [
 set PP ((PriceI / 9) * 2)
  set TT ((T / 600) * 4) 
  set W TT / PP 
]

end

However, Netlogo makes both PP and TT zero while they should be a small value like 0.15! Does the logic for finding W make sense? Thanks,


Solution

  • Normalization is normally done with a formula such as

    TT  = (T - Tmin) / (Tmax - Tmin)
    

    or here

    TT = (T - 50) / (600 - 50)
    

    That gives a normalized value between 0 and 1 as T ranges between 50 and 600. If you want TTT to range between 1 and x, where x is > 1, then you can set

    TTT = 1.0 + TT * (x - 1.0)
    

    So

    TTT = 1.0 + TT * (4.0 - 1.0) = 1.0 + TT * 3.0
    

    will give you a value between 1 and 4.