EXPERIMENT
EXPERIMENT
EXPERIMENT
SOLUTION:
function stiff_ode_solver()
c0 = [1; 1; 0];
tspan = [0 50];
[t, C] = ode15s(@ode_func, tspan, c0);
figure;
plot(t, C(:, 1), 'r', t, C(:, 2), 'g', t, C(:, 3), 'b');
xlabel('Time');
ylabel('Concentration');
legend('c1', 'c2', 'c3');
title('Solution of Stiff ODEs');
end
function dCdt = ode_func(t, C)
k1 = 0.013;
k2 = 1000;
k3 = 2500;
c1 = C(1);
c2 = C(2);
c3 = C(3);
dc1dt = -k1 * c1 - k2 * c1 * c3;
dc2dt = -k3 * c2 * c3;
dc3dt = -k1 * c1 - k2 * c1 * c3 - k3 * c2 * c3;
dCdt = [dc1dt; dc2dt; dc3dt];
end
2. The reaction A B takes place in two reactors in series. The reactors are well mixed but are not at a
steady state. The unsteady-state mass balance for each stirred tank reactor is shown
below:
where CA= 5 concentration of A at the inlet of the first reactor, C A1 = concentration of A at the outlet of the
first reactor (and inlet of the second), C A2 = concentration of A at the outlet of the second reactor, C B1 =
concentration of B at the outlet of the first reactor (and inlet of the second), C B2 = concentration of B in the
second reactor, t = residence time for each reactor, and k = the rate constant for reaction of A to produce B.
If CA0 is equal to 20, find the concentrations of A and B in both reactors during their first 10 minutes of
operation. Use k = 0.12/min and τ = 5 min and assume that the initial conditions of all the dependent
variables are zero. Plot CA1, CA2, CB1 and CB2 vs suitable time
interval. tau = 5;
pi = 5;
SOLUTION: CA0 = 5;
dCA1dt = 1/tau * (CA0 -
function reactor_simulation() CA1) - k * CA1;
dCB1dt = -1/tau * CB1 + k
k = 0.1;
* CA1;
tau = 5;
dCA2dt = 1/pi * (CA1 -
pi = 5;
CA2) - k * CA2;
CA0 = 5;
dCB2dt = 1/tau * (CB1 -
tspan = [0 10];
CB2) + k * CA2;
y0 = [0; 0; 0; 0];
dydt = [dCA1dt; dCB1dt;
[t, Y] = ode45(@ode_func, tspan, y0)
dCA2dt; dCB2dt];
figure;
end
subplot(2,1,1);
plot(t, Y(:,1), 'r', t, Y(:,3), 'b');
xlabel('Time (min)');
ylabel('Concentration (mol/L)');
legend('CA1', 'CA2');
title('Concentration of A in Reactors');
subplot(2,1,2);
plot(t, Y(:,2), 'g', t, Y(:,4), 'm');
xlabel('Time (min)');
ylabel('Concentration (mol/L)');
legend('CB1', 'CB2');
title('Concentration of B in Reactors');
end
function dydt = ode_func(t, y)
CA1 = y(1);
CB1 = y(2);
CA2 = y(3);
CB2 = y(4);
k = 0.12;