Getting differential equation from Boyle's law

I'm trying to simulate pipe installation with known amount of air in Simulink and design a PI controller for it. I was able to construct equations which reflects well my real installation. My pressure calculations is based on Boyle's law and assumption that initial amount of air is constant, therefore for pressure calculation I'm always using constant value in nominator(P0*V0)

My problem is that I don't know how to describe them in differential equations, so I can model them in Simulink as a non-linear model. Could you help me with that? When I'm calculating air volume, I'm using old value from previous calculation and I don't know how to descibe it as a differential.

Tank picture with equations:

• Welcome to MSE. It is in your best interest that you type your questions (using MathJax) instead of posting links to pictures. – José Carlos Santos Aug 16 '18 at 11:04

The physical setup seems reasonable (it's basic hydrodynamics without viscosity taken into account) It also seems like the atmospheric pressure is being neglected in the first equation, the one for y(t), which is ok if the pressure conditions in the tank are extreme. As a mathematical remark now, you are calculating difference of the volume in discrete time in equation 3 of your sheet, which is interesting because discretization happened early. I don't know if my suggestions are directly on point, but here's a plan:

1) Write out the last equation using a derivative for the rate of volume change which is induced by water coming in and out of the two openings:

$$\frac{dV_{water}}{dt}=-\frac{dV_{air}}{dt}=y(t)-u(t)$$

2) Substitute in for Boyle's law:

$$P_0V_0\frac{d(1/P_w)}{dt}=C-K\sqrt{P_w}$$

3) Solve the resulting equation by separation of variables (I substitute $P_w=\frac{1}{x}$)

$$P_0V_0\frac{\sqrt{x}}{C\sqrt{x}-K}dx=dt$$

which you can do for the result:

$$\frac{2P_0V_0}{C}\Big[(x+\frac{K}{C}\sqrt{x})+(\frac{K}{C})^2\log(\sqrt{x}-\frac{K}{C})\Big]=t+A, \hspace{0.3cm}A\in\mathbb{R}$$

and fix the constant A by the initial conditions (also substitute back for pressure). This removes the necessity for a more detailed simulation on a computer. However, I should emphasize that this calculation needs to be verified, and the OP should make sure that the assumptions of thermal equilibrium and near stationarity of the flow in the water/ gravity neglected are fit for the purposes of the problem because all these assumptions might end up yielding very approximate results.