Array dimensions not consistent
Show older comments
Could some one please help me spot how my array dimensions are not consistent?
function dcdt = diffcstrvalid2(t, C)
k1 = 10;
k2 = 5;
CA0 = 0.3;
CR0 = 0;
CS0 = 0;
tau = 0.3;
%Rate Equations
rA = -k1 * C(1)-k2* C(1);
rR = k1 * C(1);
rS = k2* C(1);
%differential equations
dcdt = [ (CA0-C(1))/tau -(-rA);
(CR0-C(2))/tau+rR ;
(CS0-C(3))/tau + rS];
end
initCon = [0.3, 0, 0];
% Residence times
t = [0, 0.3]; %s
%ODE SOLVER
[t2, C2] = ode45(@diffcstrvalid2, t, initCon, []);
%PLOT CSTR
figure (3)
plot(t2, C2 )
grid on
xlabel('tau [s]')
ylabel('concentration [mol/L]')
legend('c_A', 'c_R', 'c_S')
crcao2 = C2(:,2)./0.3;
cscao2 = C2(:,3)./0.3;
xa2 = 1 - C2(:,1)/0.3;
k1tau2 = 10.*t2;
figure (4)
plot( k1tau2, crcao2,'x', k1tau2, cscao2,'x', k1tau2, xa2, 'x')
grid on
xlabel('k1tau [s]')
ylabel('C/CAO, XA' )
legend('c_R', 'c_S', 'XA')
2 Comments
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
This is an invalid syntax. You can put functions in a script file, but you have to put them at the bottom.
I doubt this is the actual solution, so I won't put it in an answer yet:
%a few extra parentheses solve the error
dcdt = [ (CA0-C(1))/(tau -(-rA));
(CR0-C(2))/(tau+rR) ;
(CS0-C(3))/(tau + rS)];
Also note that mlint is warning you that t isn't used in diffcstrvalid2. Is this intentional?
Najeem Afolabi
on 8 Dec 2020
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!