% TKP4140 - Autumn19.
% This function defines the system of ordinary differential equations (ODE)
function  dxdt = SysODE(x,u,d,p)
% The order of the argument corresponds to the order in which 
% you connect the signals to the Interpreted Matlab Fcn in Simulink 
% x-states; u-inputs; d-disturbances; p-model parameters

% ==========MODEL PARAMETERS============================
    
A = p(1); % [m^2]    
        
        
%======Derivatives: WRITE YOUR DIFFERENTIAL EQUATIONS HERE =======
 
q1=u(1); 
q2=u(2);

caf=d(1); 
k=d(2);

h=x(1); 
ca=x(2);


%Write the differential equations
dxdt(1) = (q1-q2)/A;
dxdt(2) = ((caf-ca)*q1/(A*h)) - k*ca^2;

dxdt = dxdt(:); % system of differential equations as vertical vector       
        
end

