function [xdot] = dynModel(t,x,par)
% dynamic Model, used in the NCO tracking simulations

%parametres
F =par.F;
CAin = par.CAin; 
CBin = par.CBin; 
Hrx = par.Hrx;
rho = par.rho;
tau = par.tau;


E1 = par.E1; 
E2 = par.E2;
Cp = par.Cp;
C1 = par.C1;
C2 = par.C2;

R  = par.R;
% States
CA = x(1);
CB = x(2);
T  = x(3);
% Input
Ti = par.u.Ti;
% change for the unexpected disturbance
if t >=par.dist3Time 
	E2=par.dist3factor*E2;
end

% load the expected disturbances
[CAin CBin]=scenario(t,par);

% kinetics:
k1 = C1*60*exp(-E1/R/T);
k2 = C2*60*exp(-E2/R/T);
r = (k1*CA-k2*CB);


CAdot = 1/tau*(CAin-CA)-r;
CBdot = 1/tau*(CBin-CB)+r;
Tdot  = 1/tau*(Ti-T)+(-Hrx)/(rho*Cp)*r;

xdot = [CAdot;CBdot;Tdot];
