% TANK.M %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Tank model

function [sys,dm] = tank(t,x,u,flag)

holdup = x(3);

L = u(1);
D = u(2);
V_in = u(3);
x_in = u(4:5);

if (flag == 1)
    % Derivatives
    
    dm = V_in - L - D;
    dx = (V_in * (x_in - x(1:2)))/holdup;
    sys = dx;
elseif (flag == 3)
    % Measurements
    
    sys = x;
end