For Loop plot and zeros function

7 visualizaciones (últimos 30 días)
Najeem Afolabi
Najeem Afolabi el 20 de Dic. de 2020
Editada: Najeem Afolabi el 21 de Dic. de 2020
Having problems with my for loop plot at the bottom of the code. I'm trying to plot the 3rd column in C2 for the different values of the paramater k2. I think the problem is in the way I use the zeros function. I set the number of rows as height of C1 which is just calculating the same thing but for one value of the parameter k2 so I assumed it would be the same for C2. I'm trying to plot C2(:,3) for each k2 value that is. Can someone please help?
clear all; close all;
clc
%Initial Concentrations
CA0 = 0.13; %mol/L
CB0 = 0.1; %mol/L
Qoa = 0.0005; %L/s
Qob = 0.0005; %L/s
Q1 = Qob + Qoa;
CA1 = Qoa*CA0/Q1; %mol/L
CB1 = Qob*CB0/Q1; %mol/L
CC1 = 0;
CD1 = 0;
initCon = [CA1, CB1, CC1, CD1];
V = 10*10^-3;
k2 = 1;
%Residence Time
tau = V/Q1;
% Volume
tauRange = [0,tau]; %s
%ODE SOLVER
[tauRange, C1] = ode45(@diffpfr, tauRange, initCon, [], k2);
%PLOT PFR
figure (1)
plot(tauRange, C1,'Linewidth',1)
grid on
xlabel('Residence Time [s]')
ylabel('concentration [mol/L]')
legend('C_A', 'C_B', 'C_C', 'C_D')
%YIELD PROFILE
CcCao = C1(:,3)./CA0;
figure (2)
plot(tauRange, CcCao,'Linewidth',0.5)
grid on
xlabel('t_e_n_d')
ylabel('C_C/C_A_0')
% YIELD PLOT for 3 ratios
k2s = [10, 5 , 1];
X = zeros(height(C1), length(k2s));
for i = 1:numel(k2s)
[tauRange2, C2] = ode45(@diffpfr, tauRange, initCon, [], k2s(i));
X(i) = C2(:,3);
end
  1 comentario
Najeem Afolabi
Najeem Afolabi el 21 de Dic. de 2020
Editada: Najeem Afolabi el 21 de Dic. de 2020
Here's the function that I used
function dcdv = diffpfr(tau, C, k2)
k1 = 100;
%Rate Equations
rA = -k1 * C(1)^2*C(2) - k2* C(1)*C(2);
rB = rA;
rC = k1 * C(1)^2*C(2);
rD = k2* C(1)*C(2);
%differential equations
dcdv = [ rA;
rB;
rC;
rD];
end

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Dic. de 2020
X(:, i) = C2(:,3);
  1 comentario
Najeem Afolabi
Najeem Afolabi el 21 de Dic. de 2020
Editada: Najeem Afolabi el 21 de Dic. de 2020
Yes! Thank you very much had no idea why it wasn't working.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by