# How to keep track of variations in states based on controls in optimal control problem?

Suppose that $$x(t)$$ is the state variable showing the level of water in a tank at time $$t$$, and water is leaking the tank with rate $$\lambda$$. Control is denoted by $$u(t)$$ which is the amount of water added into a tank at time $$t$$. I am willing to know how is it possible to consider the amount of water added into the tank during time interval $$[t-\tau,t]$$ and also the amount of water added into the tank in this time interval for a specific value of $$u(s)$$ which can be denoted as $$s_{\tau}(t,u)$$.

For example, $$s_{\tau}(t,2)$$ means the amount of water added into the tank in interval $$[t-\tau,t]$$ when control is exactly equal to 2 for some times in this interval.

If you need to know the change of the amount of water between time $$[t-\tau, t]$$, you just need to store the previously measured amounts somewhere they can be accessed later (using an array is a popular method here). If you like to test an alternative input, you first need to model the tank. This can be done using Bernoulli's principle (advised to express the input as a flow instead of an amount). As your system has some kind of leakage, the resulting system will be non-linear. This mean you can go in multiple directions:
1. Use ODE solvers to solve your system for a given $$s_\tau(t,u)$$, this will compute an accurate estimation including non-linear dynamics.
EDIT: To answer your question. That integral would suit if the water in the tank is not also leaking. So if the water level is denoted as $$x(t)$$ and the tank is not leaking, it can be expressed as the following: $$u(t) = S\dot{x}(t)$$ Where $$S$$ is the surface area of the tank and $$u(t)$$ is the flow of water entering the tank (controlled). This means that the waterlevel at time $$t$$ starting from time $$t-\tau$$ where $$\tau \geq t$$ is: $$x(t) = \frac{1}{S}\int_{t-\tau}^t u(t) dt + x(t-\tau)$$ Again, this can be only this simply expressed if the tank is not leaking. Using bernoulli's principle, if we include the leakage, the equation changes to: $$\dot{x}(t) = \frac{1}{S}u(t) - \frac{1}{S}\alpha\sqrt{2g x(t)}$$ With valve specific parameter $$\alpha$$ and the gravitation acceleration $$g$$. Now you cannot simply solve this by integrating it over time. Sadly, the only way to properly predict the future water level is to incorporate the leakage dynamics.
• Dear @Petrus1904 Thanks. Can I consider the amount of water added in interval $[t-\tau,t]$ as $\int_{max(t-\tau,0)}^{t} u(s) ds$ and then replace it with $y(t)$ where $\dot{y}(t)=u(t)-u(max(t-\tau,0))$? Here, I don't know how to calculate the amount of water added into the tank for a specific value of $u$.