For Loop plot and zeros function

6 Ansichten (letzte 30 Tage)
Najeem Afolabi
Najeem Afolabi am 20 Dez. 2020
Bearbeitet: Najeem Afolabi am 21 Dez. 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 Kommentar
Najeem Afolabi
Najeem Afolabi am 21 Dez. 2020
Bearbeitet: Najeem Afolabi am 21 Dez. 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 21 Dez. 2020
X(:, i) = C2(:,3);
  1 Kommentar
Najeem Afolabi
Najeem Afolabi am 21 Dez. 2020
Bearbeitet: Najeem Afolabi am 21 Dez. 2020
Yes! Thank you very much had no idea why it wasn't working.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by