I am getting error with"Matrix dimensions must agree" for following code,please let me know where I am doing wrong?

1 view (last 30 days)
function xdot = cstr11(t,x)
global u
global qif
% Input (1)
% Coolant Flow rate
Qc = u;
% States (2)
% Concentration of A in the reactor (mol/L)
T = x(1,1)
% Temperature of reactor fluid (deg K)
CA = x(2,1)
% Process Parameters
% Product flow rate lit/min
qif = 100;
% Input product concentration mol/lit
cif = 1;
% Input temperature K
% Coolant Temperature K
% Container volume lit
% Activation energy term K
% Reaction rate constant 1/min
% % % Plant constant
k1=1.44e13; %K lit/min/mol
k2=0.01; %1/lit
% Plant constant (Manimozhi)
% % k1=1.44*10^13; %K lit/min/mol
% % k2=1; %1/lit
% % k3=700;%lit/min
% State equations
xdot(1,1)=qif*(tif-T)/v + k1*CA*(exp(-EoverR/T)) + k2*Qc*(1-(exp(-k3/Qc)))*(tcf-T);
xdot(2,1)=qif*(cif-CA)/v - k0*CA*(exp(-EoverR/T));
Command Window error message for cstr11(0,[20;100]) is Error using / Matrix dimensions must agree.
Error in cstr11 (line 45) xdot(1,1)=qif*(tif-T)/v + k1*CA*(exp(-EoverR/T)) + k2*Qc*(1-(exp(-k3/Qc)))*(tcf-T);
Please let me know where I am doing wrong? Awaiting your response. Thank You.

Accepted Answer

Alexandra Harkai
Alexandra Harkai on 29 Nov 2016
The problem is here:
Looks like Qc gets its value from global variable u which seems to be a non-scalar. So it can't perform the division you ask for. If you want an element-wise division, you can use
to mutliply with the matrix inverse of Qc.
Alexandra Harkai
Alexandra Harkai on 29 Nov 2016
Even though Qc is defined in the main function you set Qc = u in this cstr11 function so Qc will be whatever u is (for the scope of this function).

Sign in to comment.

More Answers (0)


Find more on Startup and Shutdown 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!