FUNCTION FILE
function [rate_out] = COMPREAC(t,x)% Example COMPREAC
%COMPLEX REACTION SCHEME BETWEEN FORMALDEHYDE AND SODIUM PARA PHENOL SULPHONATE%
%Second order rate constants, m3/kmol s%
K1=0.16;K2=0.05;K3=0.15;K4=0.14; K5=0.03;K6=0.058;K7=0.05;K8=0.05; %The concentration of the species are first assigned in the vector format
CA=x(1);CB=x(2);CC=x(3);CD=x(4);CF=x(5);CG=x(6); %Kinetic rates, kmol/m3 s%
R1= K1*CA*CB; R2= K2*CA*CC; R3= K3*CC*CD ; R4= K4*CB*CD ; R5= K5*CC*CC ; R6= K6*CC*CB ; R7= K7*CA*CG ; R8= K8*CA*CF; %Batch mass balances%
dCAdt= -R1-R2-R7-R8;dCBdt= -R1-R4-R6 ; dCCdt= R1-R2-R3-2*R5-R6 ; dCDdt= R2-R3-R4;dCEdt= R3+R8; dCFdt= R4+R5+R7-R8; dCGdt= R6-R7; RA=dCAdt;RB=dCBdt;RC=dCCdt;RD=dCDdt;RE=dCEdt;RF=dCFdt;RG=dCGdt; % The output of the function reaction rates are saved in vector format
rate_out=[RA; RB; RC; RD; RE; RF; RG]; end %Initial concentrations, kmol/m3}
C0= [0.15 0.1 0 0 0 0 0];
RUN FILE
% Time span
tspan=[0 1000]; % Run ODE solver
[t,x]=ode15s(@COMPREAC,tspan, C0); %Graph Plot
plot(t,x); xlabel('Time[s]'); ylabel('CA,CB,CC,CD,CE,CF,CG [kmol/m3 ]'); legend('RA','RB','RC','RD','RE','RF','RG');
Best Answer