Integration of a 'stairstep' function

1. May 31, 2009

USNavyFish

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!

Last edited: May 31, 2009
2. May 31, 2009

USNavyFish

Still no takers? I was hoping this problem would spark interest in some minds.

3. Jun 1, 2009

logarithmic

The integral of a stepwise function is the the summation you're talking about, so I don't think it will solve you're problem.

4. Jun 1, 2009

USNavyFish

So you're saying you don't think you can use integration to solve this? What if the value function is treated as a a series of delta functions or something similar?

I'm determined to find a solution to this conundrum..

5. Jun 1, 2009

Geomancer

There is a gizmo called "Euler MacLauren Summation" that allows one to rapidly approximate sums by integrals; this may get you where you want to go.
I must note that the example formula you gave may be simple enough to allow exact results. I'll think about this.

6. Jun 1, 2009

USNavyFish

Wow! Excellent suggestion Geomancer!

I setup the Euler MacLaurin Summation up to the fifth order term, and the results were identical to the numerical sum, for all intents and purposes.

Turns out that after the 1st order term, the remaining terms reduce to less than 0.000001, which is still well within my desired margin of error. Thus, problem solved.

Thank you so much Geomancer, this was exactly what I was looking for

Last edited: Jun 1, 2009