I've seen the integer version $$m_n = m_{n-1} + \frac{a_n-m_{n-1}}{n}.$$ But how do I calculate it where there are amounts, which is $$A=[3, 5, 4]$$ and the corresponding quantities $$Q=[1.5, 2.5, 1]$$ Below version doesn't work, I'm doing it like this $$m_{1.5}=0+\frac{3-0}{1.5}=2$$ $$m_{4}=2+\frac{5-2}{4}=2.75$$ Which is wrong $m_4$ should have been $$\frac{3+5}{1.5+2.5}=2$$
In this case, do I calculate the average incrementally in correct way?
Example for clarification First I bought 1.5kg apple for 3 dollars, then 2.5kg for 5 dollars, then 1kg for 4 dollars. I need to calculate the average price per kg of apple incrementally
Please read the comments below