Thank you for the response.
The challenge in this case is that the volume and flow in/out of the tank for which I am calculating the residence time are constantly changing. Occasionally, there is no flow in at all for up to a week or two, significantly affecting the residence time but not being taken into account through the traditional Volume/Flow. Basically, what my formula does is to estimate the average residence time (RT) for the fraction which has already been on the tank for x hours and the fraction which has just entered in the past hour. For simplicity, and since there is stirring on the tank, I assume a homogeneous mixture for the flow out of the tank. I figured estimating the residence time per hour should be enough. My final formula is:
RTaverage= ((RTold+RTnew)*amountold + (RTnew*amountnew)/2) / (amounttotal)
where RTold is RTaverage-1h (which is what I am struggling with expressing in my formula), RTnew is an hourly signal running regardless of conditions, amountold is the amount that was on the tank at the previous hour, and amountnew is the amount entering the tank for the past hour, and the amounttotal is the sum of amountold and amountnew.
At a certain point, the flow in was closed for approximately 2 weeks, and I figured this could serve as the starting point for the formula, providing an RTaverage starting point of 2 weeks. I am not sure how to incorporate this into the formula, or how to get the formula started seeing how it is dependent on a previously calculated point.