0
$\begingroup$

I'm building a program that calculates the cost of an item based on it's size (let's say a bamboo pole). As the customer requests a longer pole, it gets hard to find a bamboo, plus requires more resources to grow, therefore, I would want to charge more per inch for the piece of bamboo based on it's length approaching a particular length. Then after that point the cost per inch would really escalate.

I believe that log would be the function that I need to use, but I just can't figure out how to make my formula. I've tried log(-x), log(x-1), log(y-x), I can't figure out how to get the log to shoot up to infinity, nor target a specific point.

Referencing the example above, I would want the cost/inch of the bamboo to stay reasonable up to 72", but after that, the cost/inch should rapidly increase, until it gets to 100", where it would become ridiculously expensive. Before 72", it should rise in cost/inch, but at a slow rate (it costs a little bit more per inch to grow a 72" stick than a 6" stick). I'm looking for a uniform growth, not a split formula. No f(x) where x<72, g(x) where x>72.

I'm not necessarily looking for the formula to solve the above question. I am looking for the HOW to research and solve the above question.

Many Thanks, Matt

  • 0
    Slopes do not need to match. If you want slope match, look up *splines*. (Income Tax people certainly don't bother with matching slopes. Why should you?)2011-05-19

2 Answers 2

2

You are looking for functions that go to infinity, preferably in finite time (vertical asymptote) or something similar. you then construct a scale to get to your infinity point at the number of inches you want (say 100). so, for tan(x) as an example, pi/2 is infinity, so map 0-100 to pi/4-pi/2, and you have something that works (you might want to add a constant to formula to help you on on the low end).

A possibility: f(x) = Tan(x/200*pi/2+pi/4)+5

f(10) = 6.2

f(72) = 9.5

f(90) = 17.7

f(95) = 35.45

f(98) = 68.7

Feel free to massage the constants, or pick a different function to get the behavior that you want.

  • 0
    This definitely gets me going in the right direction! Perfect. I am going to take the advice of lewellen and user6312 above though and go ahead and split the equation into a linear before the break point of 72 and then use a formula similar to this after 72.2011-05-19
0

Try looking into statistics distributions. By messing with the degrees of freedom you can get something that could do what you want. If you take the inverse of the probability of something happening, then you can get your arbitrarily large number. Bonus: you can probably set 75" as the average parameter for the distro and not have to worry about it.