% REBOILER.M %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Reboiler model

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

holdup = x(3);
x = x(1:2);




if (flag == 1)
    L_in = u(1);
    x_in = u(2:3);
    V_out = u(4);
    B = u(5);
    
    % Derivatives
    dm = L_in - V_out - B;
    y = termo(x',3);
    dx = (L_in * (x_in - x) - V_out * (y' - x)) / holdup;
    sys = dx;
elseif (flag == 3)
    % Measurements
    [y] = termo(x',3);
    sys = y;
end