function dxdt  = Room(u)
%MVs=[QH1, QH2, Qac, m_in]'
%d=Tin;
%x=[T, Tfl]

%MVs:
%QH1= heated water [kJ/s]
%QH2= electric heating [kJ/s]
%QAC= air conditioning [kJ/s]
%m_in= ventilation

%Disturbance:
%Tin= outdoor temperature that goes through ventilation

%States:
%T= indoor temperature; x1
%Tfl= floor temperature; x2

%Other calculated values:
%Q= heat to the room [kW]
%QHfl= hot water that heats-up the floor [kJ/s] kW

% %Parameters
% m=200;          %mass of air in the room [kg]
% Cp=1;           %Cp of air [kJ/(kg k]
% Ufl=10;         %heat transfer coefficient for floor [W/m^2K]
% Afl=50;         %area of floor [m^2]
% mfl=660;        %mass of floor [kg]
% Cpfl=1;         %Cp of floor - concrete [kJ/(kg k] 
% %Disturbance
% Tin0=21;        %°C / going from -10 to 30°C
% %Nominal values
% QH10=0;         %at steady-state, no need of heating water
% QH20=0;         %at steady-state, no need of electric heating
% QAC0=0;         %at steady-state, no need of air conditioning
% m_in0=0.4;      %mass flow for ventilation; kg/s
% 
% Qhfl0=0;        %at steady-state, no heat transfer through the floor
% T0=21;          %room temperature, °C

%% Data extraction
%States:
T=u(1);
Tfl=u(2);

%MVs
QHW=u(3);  %hot water
QEH=u(4);  %electric heating
QAC=u(5);  %AC
m_in=u(6); %air 

%Parameters
m=u(7);             %mass of air in the room [kg]
Cp=u(8);            %Cp of air [kJ/(kg k]
Ufl=u(9);           %heat transfer coefficient for floor [W/m^2K]
Afl=u(10);          %area of floor [m^2]
mfl=u(11);          %mass of floor [kg]
Cpfl=u(12);         %Cp of floor - concrete [kJ/(kg k] 

%Disturbance
Tin=u(13);

%%  Model
Qfl=Ufl*Afl*(Tfl-T);
Q=Qfl+QEH-QAC;

dTdt=(m_in*Cp*(Tin-T)+Q)/(m*Cp);    %rate of change of room temperature
dTfldt= (QHW-Qfl)/(mfl*Cpfl);        %rate of change of floor temperature

dxdt = [dTdt;dTfldt];

end

