- #1
USNavyFish
- 4
- 0
Good evening!
I'm developing a small economic simulation for kicks, and have been stumped for the last few days.
The value of a commodity within a market is a function of the quantity of that commodity, with respect to the capacity of the market. The function I use to generate those values looks something like:
Value(Quantity) = BaseValue * 2-(1.5*((Quantity/Capacity)^R))
where R = (Log(3) / Log(2) ) - 1
The specifics of are irrelevant, I'm simply providing it for context. What's important to note is that as Quantity in a market decreases, value increases.
Now, say you're going to determine the total cost to purchase 5 units from that market. The easy way to do this is this is to sum Value(Quantity - 0) + Value(Quantity -1) + Value(Quantity -2) ... all the way to Value(Quantity - 4).
Unfortunately, this process is very computationally expensive for large values of Q (quantity). The immediate answer is to take the integral of the value function. That integral looks like:
Integral of Value with respect to Q = (Q)*(2 - (1.5*(Q/Capacity)^(R))/(R+1))Now, here's where the problem begins. For large values of Q, and also at the extremes of the function where the slope is large (i.e. Q = 0 or Q = Capacity), Integration over a specified range DIFFERS from the numerical sum over that range by a small error (generally no more than 1-2%).
I've come to reason that the cause for this error is due to the integration of non-integer quantity values. The summation obviously deals with only integer values.. but the integration takes care of all the values in between these integers as well.
Assuming that's what causes this error, I would assume that if the value function were instead written as a "stairstep" function, the error would drop out. Such a stairstep function would treat all Q values from (integerQ - 0.5) to (integerQ + 0.5) as having the same value as IntegerQ.
I have not been able to figure out how to define, nor take the integral of such a stairstep function. How would you go about solving this problem analytically? Any assistance would be greatly appreciated!
I'm developing a small economic simulation for kicks, and have been stumped for the last few days.
The value of a commodity within a market is a function of the quantity of that commodity, with respect to the capacity of the market. The function I use to generate those values looks something like:
Value(Quantity) = BaseValue * 2-(1.5*((Quantity/Capacity)^R))
where R = (Log(3) / Log(2) ) - 1
The specifics of are irrelevant, I'm simply providing it for context. What's important to note is that as Quantity in a market decreases, value increases.
Now, say you're going to determine the total cost to purchase 5 units from that market. The easy way to do this is this is to sum Value(Quantity - 0) + Value(Quantity -1) + Value(Quantity -2) ... all the way to Value(Quantity - 4).
Unfortunately, this process is very computationally expensive for large values of Q (quantity). The immediate answer is to take the integral of the value function. That integral looks like:
Integral of Value with respect to Q = (Q)*(2 - (1.5*(Q/Capacity)^(R))/(R+1))Now, here's where the problem begins. For large values of Q, and also at the extremes of the function where the slope is large (i.e. Q = 0 or Q = Capacity), Integration over a specified range DIFFERS from the numerical sum over that range by a small error (generally no more than 1-2%).
I've come to reason that the cause for this error is due to the integration of non-integer quantity values. The summation obviously deals with only integer values.. but the integration takes care of all the values in between these integers as well.
Assuming that's what causes this error, I would assume that if the value function were instead written as a "stairstep" function, the error would drop out. Such a stairstep function would treat all Q values from (integerQ - 0.5) to (integerQ + 0.5) as having the same value as IntegerQ.
I have not been able to figure out how to define, nor take the integral of such a stairstep function. How would you go about solving this problem analytically? Any assistance would be greatly appreciated!
Last edited: