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

Najeem Afolabi
Najeem Afolabi 2020년 12월 21일
편집: Najeem Afolabi 2020년 12월 21일
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

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 21일

0 개 추천

X(:, i) = C2(:,3);

댓글 수: 1

Najeem Afolabi
Najeem Afolabi 2020년 12월 21일
편집: Najeem Afolabi 2020년 12월 21일
Yes! Thank you very much had no idea why it wasn't working.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

태그

질문:

2020년 12월 20일

편집:

2020년 12월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by