function dxdt = equations(t,x,u,d,tintp,par,var) 

%Parameters
UAfr = par.UAfr;
UAro = par.UAro; 
mCpf = par.mCpf; 
mCpr = par.mCpr; 
mr = par.mr; 
%P = par.P;

%Inputs and disturbances
% qhf = u(1);         
% qhr = u(2);
To = d(1);
min = d(2);

%To = 273

Tf = x(1);
Tr = x(2);
%J =x(3);

qhf1 = u(1:length(tintp),1); 
qhr1 = u(length(tintp)+1:end,1); 

qhf = interp1(tintp,qhf1,t');
qhr = interp1(tintp,qhr1,t');

% min1 = d(:,1);
% min = interp1(tintp,min1,t);
P1 = par.P;

P = interp1(tintp,P1,t');

%Floor
dxdt(1) = (qhf/mCpf)-(UAfr/mCpf)*(Tf-Tr);
%Room
dxdt(2) = (qhr/mCpr)+(UAfr/mCpr)*(Tf-Tr)-(UAro/mCpr)*(Tr-To)...
    +(min/mr)*(To-Tr);
%Cost function
dxdt(3) = P.*(qhf+qhr);
% dxdt(3) = P.*(qhf+qhr)^2;
% dxdt(3) = P.*(0.4(qhf+qhr)^+(qhf+qhr));
%       Floor    Room
dxdt = [dxdt(1) dxdt(2) dxdt(3)]';