For Loop plot and zeros function
10 views (last 30 days)
Show older comments
Najeem Afolabi
on 20 Dec 2020
Edited: Najeem Afolabi
on 21 Dec 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
Accepted Answer
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!