1

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,

user710
  • 161
  • 2
  • 12
  • Since NetLogo uses floating point for all numeric values and calculations, I don't see how you can get zero from `((PriceI / 9) * 2` unless `PriceI` is indeed zero. Have you checked for that? – Charles Jul 26 '17 at 19:46
  • As you discussed, the problem was not because of the way netlogo deals with numbers. Also the variables were given values inside the program. I had defined a procedure `setup-WCalculator`, and inside another procedure, I was using `W`. It seems it was not working this way, and because it could not go into that procedure, a default zero made them zero. What I did that worked was that I called `setup-WCalculator` before the other procedure which was using `W`. It seems to be working now. I had not noticed this way of normalizing you mentioned and using that made the results improve. Thanks. – user710 Jul 26 '17 at 20:05

1 Answers1

3

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.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Charles
  • 3,888
  • 11
  • 13
  • Is your answer that the question is mistaken and that he cannot be getting zero? A comment to confirm that may have been a good idea before answering. – Patrick87 Jul 25 '17 at 10:29
  • Yes. That should have been a comment and the normalizing an answer. I've edited the response accordingly. Thanks. – Charles Jul 26 '17 at 19:39