A variation of a 'leaky bucket' problem I'm looking at a 'leaky bucket' problem with a few differences, the system is set up as follows:

*

*the tank has a practically unlimited capacity

*water is added with a known flow rate

*periodically the drain valve is adjusted so that all of the water is drained over say 10 seconds

*we are interested to know how much water is contained at time $t$
To give a concrete example, lets assume the water is added with a rate of 10L per second, every 4 seconds the drain is adjusted. When the drain is adjusted it is adjusted to $\frac{1}{10}$ of current volume of water.
Initially I started with the following diff. eq. $dV=I-\frac{1}{10}V$ where $V$ stands for volume and $I$ is the incoming flow rate in L per sec. The issue is that in this equation the drain is constant with respect to volume, whereas in the actual problem the drain is adjusted periodically and in between those events the water is draining with a set flow rate.
I have a feeling it involves using a $\sin$ function to model the period, but I'm not certain as to how to go about it.
 A: Say volume of water at $t = 0$ is $V_0$.
Volume of water at time $t = 4n$ where $n \in 0, \mathbb{Z+}$ is then given by
$\displaystyle V_{4n} = \bigg(\frac{3}{5}\bigg)^n V_0 + 10I \bigg(1 - \bigg(\frac{3}{5}\bigg)^n \bigg)$
And volume of water at time $4n+t$ is given by,
$\displaystyle V_{4n+t} = V_{4n} \bigg(1 - \frac{t}{10}\bigg) + I \, t$ where $0 \leq t \leq 4$
Here is how the expression comes (wherever I write $t$, it is $0 \leq t \leq 4$) -
$V_t = V_0 - \frac{V_0}{10}t + I \, t$
$V_4 = V_0 - \frac{4V_0}{10} + 4I = \frac{3}{5}V_0 + 4I$
$\displaystyle V_{4+t} = V_4 - \frac{V_4}{10}t + I \, t$
i.e. $\displaystyle V_{4+t} = \frac{3}{5}V_0 + 4I - \frac{t}{10}(\frac{3}{5}V_0 + 4I) + I \, t$
i.e. $\displaystyle V_{4+t} = \frac{3}{5}V_0 (1 - \frac{t}{10})+ (4 + \frac{3t}{5})I$
$\therefore \displaystyle V_{8} = (\frac{3}{5})^2 V_0+ 4(1 + \frac{3}{5})I$
Similarly, $\displaystyle V_{12} = (\frac{3}{5})^3 V_0 + 4(1 + \frac{3}{5} + (\frac{3}{5})^2)I$
At $t = 4n$, the geometric series $\, 1 + \frac{3}{5} + ... + (\frac{3}{5})^{n-1} = \displaystyle \frac{1 - (\frac{3}{5})^{n}}{1 - \frac{3}{5}} = \frac{5}{2} (1 - (\frac{3}{5})^{n})$
And this leads to expression at time $4n$ and $4n + t$.
A: Assume the drain is adjusted every $\Delta t$ seconds. Let $V_n$ be the volume of water in the tank at $t=n\Delta t$. Let $t\in(n\Delta t,(n+1)\Delta t)$.$$\begin{align*}\frac{dV}{dt}=I-V_n/10\implies&V(t)-V_n=(t-n\Delta t)(I-V_n/10)\\\implies&V(t)=V_n(1+n\Delta t/10-t/10)+(t-n\Delta t)I\end{align*}$$We need to find an expression for $V_n$. The volume varies continuously so$$V_{n+1}=\lim_{t\to(n+1)\Delta t^-}V(t)=V_n[1-\Delta t/10]+I\Delta t$$
This is a first order non-homogeneous linear recurrence with constant coefficients whose solution is $$V_n=(V_0-10I)(1-\Delta t/10)^n+10I$$
Substituting $n=\lfloor t/\Delta t\rfloor$,$$V(t)=\left[\left(V_0-10I\right)\left(1-\frac{\Delta t}{10}\right)^{\lfloor t/\Delta t\rfloor}+10I\right]\left[1-\left(\frac{t-\lfloor t/\Delta t\rfloor\Delta t}{10}\right)\right]+I(t-\lfloor t/\Delta t\rfloor\Delta t)$$

Attached graph of $V(t)$ for $V_0=0,I=10,\Delta t=4$. Notice that the curve is piecewise linear as expected. The limiting value is $10I$.

