%*********************************************
%***Simulacion de un reactor semicontinuo***
%**********************************************

clear 


y_initial=[1 100 0.001 0.001 0.001]; %volumen, conc LA, conc LE, conc K, conc BP 
t_start = 0;						%	h
t_final = 9;						%	h
tspan = [t_start t_final];
[t,y] = ode45('semicstr',tspan,y_initial);


r1=y(:,4)./y(:,1).*y(:,2)./y(:,1); %kmol/m3h
r2=0.1*y(:,4)./y(:,1).*y(:,4)./y(:,1); %kmol/m3h

sel=r1./(r1+r2);

subplot(2,2,1),
plot(t,y(:,1)),
title('volumen del reactor'),
xlabel('time (h)'),
ylabel('V (m3)')
subplot(2,2,2),
plot(t,y(:,5)./y(:,1)),
title('C_BP'),
xlabel('time (h)'),
ylabel('BP (kmol/m3)')
subplot(2,2,3),
plot(t,y(:,2)./y(:,1)),
title('C_LA'),
xlabel('time (h)'),
ylabel('C_LA (kmol/m3)')
subplot(2,2,4),
plot(t,y(:,3)./y(:,1)),
title('C_LE'),
xlabel('time (h)'),
ylabel('C_LE (kmol/m3)')
figure
plot(t,y(:,4)./y(:,1)),
title('C_K'),
xlabel('time (min)'),
ylabel('C_K (kmol/m3)')
figure
plot(t,sel),
pause
close all