Two CSTR GMC PI FunctionFile
Two CSTR GMC PI FunctionFile
%Solves for Volume, Temperaure and the integral of the error for each. This
%file calculates the apparently continuous response and MV values for the
%tank under PI control. The MV is not sent to the main file and is
%therefore recalculated in that file.
%This file is used with ODE45 in the main file where it can obtain the PV
%and integral of the error values.
%========================================================================
function xdot = Two_CSTR_GMC_PI_FunctionFile(t,x)
%x(1)=h
%x(2)=V
%x(3)=T
%x(4)=C
%x(5)=IeV Integral of Volume error
%x(6)=IeT Integral of Temperature error
%x(7)=h2
%x(8)=V2
%x(9)=T2
%x(10)=C2
%x(11)=IeV Integral of Volume error
%x(12)=IeT Integral of Temperature error
Tcin2=Tcins2;
SPV2=SPVs2;
SPT2= SPTs2;
elseif t>steptime
Fo2=Fos2+dFo2;
Tin=Tins+dTin;
Cin=Cins+dCin;
Tcin=Tcins+dTcin;
SPV=SPVs+dSPV; %Setpoint change
SPT=SPTs+dSPT; %Setpoint change
Tcin2=Tcins2+dTcin2;
SPV2=SPVs2+dSPV2; %Setpoint change
SPT2=SPTs2+dSPT2; %Setpoint change
end
if t<=Frstep
Fr=0;
else
Fr=Fo2*ratio;
end
%NOTE:Implements any changes to the system
%=========ERROR VALUES=============================================
eV=SPV-x(2); %Calculate error in height
eT=SPT-x(3); %Calculate error in temp
%=========SYSTEM OF ODEs===========================================
%TANK 1
Tc=( ((Ua*x(3)) + (mc*Cpc*Tcin))/(Ua + mc*Cpc) );
rate=-(K0*exp(-(E_R)/x(3)) )*x(4)*x(2);
cool=mc*Cpc*(Tc-Tcin);
xdot(1)=(1/A)*(Fin + Fr - Fo ); %dh/dt
xdot(2)=(Fin + Fr - Fo); % dV/dt
xdot(3)=(1/x(2))*( (DH*rate) + (Fin*Tin) + (Fr*x(9)) - (Fo*x(3)) - (cool/pCp) -
(x(3)*xdot(2)) ); %dT/dt
xdot(4)=(1/x(2))*( rate + (Fin*Cin) + (Fr*x(10)) - (Fo*x(4)) - (x(4)*xdot(2)));
%dC/dt
xdot(5)=eV; %dIeV/dt
xdot(6)=eT; %dIeT/dt
%TANK 2
Tc2=( ((Ua2*x(9)) + (mc2*Cpc2*Tcin2))/(Ua2 + mc2*Cpc2) );
rate2=-(K02*exp(-(E_R2)/x(9)) )*x(10)*x(8);
cool2=mc2*Cpc2*(Tc2-Tcin2);