% Dynamic variation of CSTR temperature
function [Xdot] = test(t,X)

k10 =17e11; %h-1
EbyR = 9000; %K

Q= 9.5; %m3/h
Volume = 1.25; %m3
CpA = 120;%J/mol/K
CpB = 60;
CpC = 60;
CpI = 100;

Fain = 20000;% mol/h
Fbin = 200000;
Fiin = 33000;

Ca0 = Fain/Q;
Cb0 = Fbin/Q;
Ci0 = Fiin/Q;

Tin = 300;%K

delH = -85000; %J/molA reacted

SumFjCpJ = Fain * CpA + Fbin * CpB + Fiin * CpI;

% First four equations represent the mole balances for propylene oxide
% (X(1)), Water (X(2)) , Propylene glycol (X(3)) and Methanol (X(4)) and
% the fifth equation represents energy balance for the CSTR

Xdot= [-(k10*exp(-EbyR./X(5))*X(1))+((Ca0-X(1))*(Q/Volume));...
    -(k10*exp(-EbyR./X(5))*X(1))+((Cb0-X(2))*(Q/Volume));...
    (k10*exp(-EbyR./X(5))*X(1))+((-X(3))*(Q/Volume));...
    ((Ci0-X(4))*(Q/Volume));...
    (-(SumFjCpJ*(X(5)-Tin))+(-delH)*(((k10*exp(-EbyR./X(5)))*X(1)*Volume)))/(Volume*(CpA*X(1)+CpB*X(2)+CpC*X(3)+CpI*X(4)))];

end