% ACCUM.M %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Accumulator model

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

holdup = x(4);

q_in = u(1);
x_in = u(2:4);
q_out = u(5);

if (flag == 1)
    % Derivatives
    
    dm = q_in - q_out;
    dx = q_in * (x_in - x(1:3))/holdup;
    sys = dx;
elseif (flag == 3)
    % Measurements
    
    sys = x;
end