FUNCTION FILE (First File)function [rate_out] = BATCOM(t,x)TC = 190 ; %Reactor temperature, C
R = 8.31434; %Gas constant, kJ/kmol K
%Arrhenius constant, 1/s
A1= 5.78052E+10 ; A2 = 3.92317E+12;A3 = 1.64254E+4 ;A4 = 6.264E+8 ;%Activation energy, kJ/kmol
Ea1 = 124670 ; Ea2 = 150386 ;Ea3 = 77954 ;Ea4 = 111528 ;%The concentration of the species are first assigned in the vector format
CA=x(1);CB=x(2);CC=x(3);CD=x(4);%Reactor temperature, Kelvin
TK=R*(TC+273); %Reaction rate constants, 1/s (k=Ae^(Ea/T);NB..R has been factored at TK)
k1= A1*exp(-Ea1/TK); k2=A2*exp(-Ea2/TK) ;k3=A3*exp(-Ea3/TK) ;k4=A4*exp(-Ea4/TK) ; k5=2.16667E-04 ;%Reaction rates, kmoles/m3 s}
dCAdt =-(k1+k2)*CA; dCBdt=k1*CA-k3*CB;dCCdt=k2*CA-k4*CC;dCDdt=k3*CB-k5*CD;%Mass balances
rA=dCAdt; rB=dCBdt;rC=dCCdt;rD=dCDdt;% The output of the function reaction rates are saved in vector format
rate_out=[rA; rB; rC; rD ];endRUN FILE(2nd file)% Define initial concentrations
C0= [1 0 0 0 ];% Time span
tspan=[0 1000];% Run ODE solver
[t,x]=ode15s(@BATCOM,tspan, C0);%Graph Plot
plot(t,x);xlabel('Time[s]');ylabel('Concentration[kmol/m3]');legend('CA','CB','CC','CD');
MATLAB: Please good people out there, i need help with how to vary a parameter in this code. In the case i want to vary TC from 180 to 220. How do i factor that into this code? Thank you very much for your help!!
constant varyparameter varytemperature vary
Best Answer