function dy_dt = proceso(t,y)

global area g SP F_setp Kc taui onoff F_in1 F_in2 area_mix CA_in1 CB_in2 ...
area_salida setp_cb SP_m F_setpm Kc_m taui_m onoff SP_h Kc_h taui_h ratio ... 
k K0 EA T R rho SP_r

h=y(1);
sumerr=y(2);
h_m=y(3);
ca=y(4);  %kmol
cb=y(5);  %kmol
sumerr_m=y(6);
sumerr_h=y(7);
V=y(8);
NA=y(9);  %kmol
NB=y(10);  %kmol
NC=y(11);
ND=y(12);
sumerr_r=y(13);

if t>15 CA_in1=200;
end
if t>30 CB_in2=300;
end
if t>45 F_in1=6;
end

%*******MIXER***********
setp_cb=ca*SP_m/(1-SP_m);%kmol
F_in2=Kc_m*(setp_cb - cb)+onoff*Kc_m/taui_m*sumerr_m;%m3/min
if F_in2<0
    F_in2=0;
end
F_outm=F_setpm-Kc_h*(SP_h-h_m)-onoff*Kc_h/taui_h*sumerr_h; %m3/min

%*******TANQUE***********
F_in=F_setp+Kc*(SP-h)+onoff*Kc/taui*sumerr; %m3/min
F_out=ratio*F_outm;%m3/min

%******REACTOR**************
Rate(1) = K0(1)*exp(-EA(1)/(R*T))*(NB/V)*(NC/V) ;
Rate(2) = K0(2)*exp(-EA(2)/(R*T))*(NB/V)*(ND/V);%kmol/min*m3
%Balance global
F_outr=2-Kc*(SP_r-V)-onoff*Kc/taui*sumerr_r;


%*******TANQUE odes***********
dh_dt=1/area*(F_in-F_out); %m/min
derr_dt = SP - h;	%m

%*******MIXER odes ***********
dhm_dt=(F_in1+F_in2-F_outm)/area_mix;   %m/min
dca_dt=CA_in1*F_in1-F_outm*ca/((area_mix*h_m));  %kmol/min
dcb_dt=CB_in2*F_in2-F_outm*cb/((area_mix*h_m));       %kmol/min
derrm_dt = setp_cb - cb;	%kmol
derrh_dt = SP_h-h_m;	%kmol

%******REACTOR odes**************
dV_dt = (F_out*rho + F_outm*rho -(F_outr*rho) -Rate(1)*V - Rate(2)*V)/rho;%kmol/min
%Balance a componentes
dNB_dt = F_outm*ca/((area_mix*h_m)) -Rate(1)*V-Rate(2)*V -(NB/V)*F_outr;%kmol/min
dNC_dt = F_outm*cb/((area_mix*h_m)) -Rate(1)*V -(NC/V)*F_outr;%kmol/min
dND_dt = Rate(1)*V - Rate(2)*V -(ND/V)*F_outr ;%kmol/min
dNA_dt = Rate(2)*V-(NA/V)*F_outr;%kmol/min
derrr_dt = SP_r-V;	%m

%**********************************************************************************

dy_dt(1)=dh_dt;
dy_dt(2)=derr_dt;
dy_dt(3)=dhm_dt;
dy_dt(4)=dca_dt;
dy_dt(5)=dcb_dt;
dy_dt(6)=derrm_dt;
dy_dt(7)=derrh_dt;
dy_dt(8)=dV_dt;
dy_dt(9)=dNA_dt;
dy_dt(10)=dNB_dt;
dy_dt(11)=dNC_dt;
dy_dt(12)=dND_dt;
dy_dt(13)=derrr_dt;
dy_dt=dy_dt';

%**************






