How to get sum of points along curve?

676 Views Asked by At
startingQuantity / numberAvailable = price

5 apples / 4 available = $1.25

So if there are 4 available and the price is 1.25 and someone buys three apples then they would pay 1.25 + 1.666 + 2.5 = $5.416

What is the equation to get 5.416?

I'm looking for an equation that will work for larger numbers. For example how would you figure it out if starting quantity was 1,000,000 and number available was 500,000 and someone wanted to buy 240,000?

2

There are 2 best solutions below

0
On BEST ANSWER

Suppose there were $n$ apples available, with a starting quantity of $n+1$ and we wanted to buy $n$ apples. The total cost would be $s_n$ (I know this example isn't as general as you wanted, but I'm just trying to explain why what you're asking for is impossible).

$$s_n = \frac{n+1}{n}+\frac{n}{n-1}+...+\frac{2}{1}$$ $$t_n = \frac{1}{n}+\frac{1}{n-1}+...+\frac{1}{1}$$ $$s_n-t_n =\frac{n}{n}+\frac{n-1}{n-1}+...+\frac{1}{1}=n$$ so $$s_n=n+t_n$$ And the cost of buying $k$ apples would be $s_n-s_{n-k}$. Note that $t_n$ is the harmonic series, for which there is no general (simple) formula for, so I suspect that your search for a general formula won't be successful.

2
On

So, the prince for $n$ apples will be for $r(\le n)$ apples $$\text{startingQuantity}\cdot\sum_{s=n-r+1}^n\frac1s$$

For startingQuantity$=5,n=4, r=3$ we have $$5\cdot\sum_{s=2}^4\frac1s=5\left(\frac12+\frac13+\frac14\right)=\frac5{12}(6+4+3)=\frac{65}{12}$$