Assuming that you have the reaction rate expression and the stoichiometry of the reaction, the following steps can be followed to simulate a batch reactor exercise in MATLAB:
For example, consider the following reversible reaction - A + B ⇌ C, with the following rate expression:
k1 = 0.1; k2 = 0.05; R = 10; rA = -k1C_A^2 + k2C_B*C_C/R; % rate expression stoichiometry = [-1 -1 1]; % stoichiometry of the reaction
Define the initial concentrations of the reactants and products, the total time of the simulation and the time step size for the ODE solver.
C_A0 = 2; C_B0 = 2; C_C0 = 0; % initial concentrations t_final = 50; % total simulation time dt = 0.01; % time step size
Define the ODE function that calculates the rate of change of the concentrations based on the rate expression and stoichiometry.
function dCdt = odeFunc(t,C,k1,k2,R) % rate expression for A + B <-> C rA = -k1C(1)^2 + k2C(2)C(3)/R; % stoichiometry of the reaction stoichiometry = [-1 -1 1]; dCdt = stoichiometryrA'; end
Solve the ODEs numerically using the ode45 function, which is an ODE solver in MATLAB.
[t,C] = ode45(@(t,C) odeFunc(t,C,k1,k2,R), [0 t_final], [C_A0 C_B0 C_C0]);
Plot the time evolution of the concentrations of the reactants and products.
figure() plot(t,C(:,1),'r-',t,C(:,2),'b-',t,C(:,3),'g-') xlabel('Time [s]') ylabel('Concentration [mol/L]') legend('A','B','C')
This will give you a plot of the time evolution of the concentrations of the reactants and products in the batch reactor.
gistlibby LogSnag