Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

4 views (last 30 days)
Kemal Faza Hastadi
Kemal Faza Hastadi on 18 May 2022
Answered: KSSV on 18 May 2022
Hello my code was performing fine and giving result when the Vt(1) value below 38000, but when it above that value it gave me warning.
Warning: Failure at t=2.362286e-02. Unable to meet integration tolerances without reducing the step size below the
smallest value allowed (8.392525e-17) at time t.
> In ode23s (line 401)
In Single (line 69)
and then it gave me a red text for error as
Unable to perform assignment because the indices on the left side are not compatible with the size of the right
side.
Error in Single (line 81)
resid1(1:1001,1)=ya(:,1);
I am having hard time to understand because it was running well and giving me result while i change the value of the Vt(1) above 30000 ish then it doesnt work. Thank you for any help.
Thank you.
clear all; clc; close all;
global tubediam tubeamt catdiam voidfrac catdens U transferT Fin val val1 TotMol Ymeoh Pin ya Tcalc t Fi2 resid1 o ya1 myield ftotal wcat1 conv tconv tconv1 ya1 ya2 ya3 ya4 ya5 meoh
answer = {'24077.37','225','40','63.33334','31.66667','5','0','0','0.16','0.032','0.032','0.032','0.032','220.00','4.57','4.30','0.1','0.38'};
val=zeros(1,22);
for i=1:18
val(i) = str2num(answer{i});
end
Tin = (273.15 + val(2)); %K
transferT = (273.15 + val(14)); %K
U = 300; %J/s.m^2.K
Pin = val(3); %bar
val(19) = 0.015; %m, ID of single catalyst tube
val(20) = 1190; %kg/m^3, catalyst pellent density, note bed density = catdens*(1-voidfrac)
val(21) = 0.005; %m, catalyst pellet diameter
val(22) = 0.285; %bed void fraction
Vt=zeros(1,10);
Vt(1)=40000;
Vt(2)=1;
Vt(3)=1;
Vt(4)=1;
Vt(5)=1;
Vt(6)=0.000176715;
Vt(7)=0.000176715;
Vt(8)=0.000176715;
Vt(9)=0.000176715;
Vt(10)=0.000176715;
tubediam = val(19); %ID of catalyst tube
tubeamt = 1;
catdens = val(20); %kg/m3
catdiam = val(21); %m
voidfrac = val(22); %bed void frac
tubelength = val(9); %m
FtotIn= Vt(1)/22414;
fco=(val(5)*FtotIn)/100;
fh2=(val(4)*FtotIn)/100;
fco2=(val(6)*FtotIn)/100;
fn2=(val(7)*FtotIn)/100;
fch4=(val(8)*FtotIn)/100;
fc1oh=0;
fh2o=0;
Area=Vt(6);
Fin=[fh2;fco;fco2;fc1oh;fh2o;fn2;fch4];
Fin=Fin';
ein = [0, 0]; % mol/s
Wcat = tubeamt*catdens*(1-voidfrac)*tubelength*Area; %kg, total mass catalyst
Wspan = (0:Wcat/1000:Wcat);
%Wspan = Wspan';
wcat1(1:1001,1)=Wspan;
yin = [Tin, Pin, ein];
Bprop = [tubediam,tubeamt,tubelength,catdiam,voidfrac,catdens,Wcat,U,transferT,Area];
options = odeset('RelTol',1e-30,'AbsTol',1e-40);
[W, ya] = ode23s('v1meohODEs', wcat1, yin, [], Bprop, Fin, options);
T = ya(:,1);
P = ya(:,2);
e1 = ya(:,3);
e2 = ya(:,4);
F(:,1) = Fin(1) - 3*e1 - e2; %H2
F(:,2) = Fin(2) + e2; %CO
F(:,3) = Fin(3) - e1 - e2; %CO2
F(:,4) = Fin(4) + e1; %MeOH
F(:,5) = Fin(5) + e1 + e2; %H2O
F(:,6) = Fin(6); %N2 (inert)
F(:,7) = Fin(7); %CH4 (inert)
resid1(1:1001,1)=ya(:,1);
resid1(1:1001,2)=F(:,4);
resid1(1:1001,3)=F(:,1); %h2
resid1(1:1001,4)=F(:,2); %co
resid1(1:1001,5)=F(:,3); %CO2
resid1(1:1001,6)=F(:,6); %N2
resid1(1:1001,7)=F(:,7); %CH4
resid1(1:1001,8)=F(:,5); %H2O
conv(1:1001,1)=-(((resid1(1:1001,4)+resid1(1:1001,5))-((fco+fco2)))/(fco+fco2));
ya1=ya;
tconv=((resid1(1,4)+resid1(1,5))-((resid1(1001,4)+resid1(1001,5))))/(resid1(1,4)+resid1(1,5));

Accepted Answer

KSSV
KSSV on 18 May 2022
The error is simple, you are trying to save wrong number of elements then the LHS is intialized for.
A = zeros(5,5) ; % A is 5x5 matrix intitialized
A(1,:) = rand(1,5) ; % no error, 5 elements can be saved in first row
A(3,:) = rand(1,6) ; % error, you cannot save six elements
Unable to perform assignment because the size of the left side is 1-by-5 and the size of the right side is 1-by-6.
Like wise in your case, in the line:
resid1(1:1001,1)=ya(:,1);
the dimensions of LHS and RHS are different. If you are not sure of the dimensions, save them into a cell array.
A = cell(1,3) ;
A{1} = rand(1,10) ;
A{2} = rand(1,3) ;
A{3} = rand(5) ;

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!