MATLAB Answers

## Why am i getting "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side"

Asked by Chidera Agu

### Chidera Agu (view profile)

on 10 May 2019
Latest activity Answered by Raj

### Raj (view profile)

on 10 May 2019
Accepted Answer by Raj

### Raj (view profile)

function ydot=problem4data(W,X)
fa0=5; %mol/s
fb0=2*fa0;%mol/s
fi=2*fa0; %mol/s
ca0=2; %mol/dm^3
T1=325; %K
Ta=300; %K
T2=305;%K
Cpa= 20;%cal/molK
Cpb=Cpa;
Cpc=Cpa;
E=25; %kcal/mol
R=1.987*.001;%kcal/molK
Cpi=18; %cal/molK
Ua=320; %cal/s.m^3.K
Hrx= -20; %Kcal/mol
k2=.0002; %dm^6/kg.mol.s
alpha=.000115; %kg^-1
Cpsum=Cpa+Cpb+Cpi;
x=[0:0.1:1];%assumption
T=T1+((x.*(-Hrx))./(Cpsum));
Kc2=1000;
Kc1=Kc2.*exp((Hrx./R).*((1./T2)-(1./T)));
k1=k2.*exp((E./R).*((1./Ta)-(1./T)));
y1=1;%assumption
xenum=((3.*Kc1)./4)- sqrt(((3.*Kc1)./4)-((2.*Kc1).*((Kc1./4)-1)));%numerator xe equation
xedenom=2.*((Kc1./4)-1);%denominator xe equation
xe=xenum./xedenom;
pb= 1400; %kg/m^3
ra=-((k1.*ca0.*(T./T1).*y1).^2).*((1-x).*(2-x)-((4*x.^2)./Kc1));
rae=-((k1.*ca0.*(T./T1).*y1).^2).*((1-xe).*(2-xe)-((4*xe.^2)/Kc1));
Tnum=(Ua./pb).*(Ta-T)+(ra.*Hrx);
Tdenom=(fa0+fb0+fi).*(Cpsum);
ydot(1)=(-ra)./fa0;
ydot(2)=-rae./fa0;
ydot(3)=Tnum./Tdenom;
ydot(4)=(-alpha./(2.*y1)).*(T./T1);
ydot=ydot';
end

Chidera Agu

on 10 May 2019
x=X(1)
xe=X(2)
T=X(3)
Y=X(4)
y=p0/p
KSSV

### KSSV (view profile)

on 10 May 2019
What is W and X?? Inputs to the function.
Chidera Agu

### Chidera Agu (view profile)

on 10 May 2019
W ranges from 0 to 1000
X is what i just decided to use to represent x,xe,T,and y. (dx/dW, dT/dW, dy/dW)

Sign in to comment.

## 1 Answer

Answer by Raj

### Raj (view profile)

on 10 May 2019
Accepted Answer

You must be getting error at line number 34 in your code. That's because your 'ra' is a 1x11 double type matrix which (after dividing by fa0) you are tying to assign to a single element of ydot. Again in the next line you are trying to assign 'rae' which is a 1x11 complex double type matrix to single element of ydot.
Try changing your code like this:
ydot(1,:)=(-ra)./fa0;
ydot(2,:)=-rae./fa0;
ydot(3,:)=Tnum./Tdenom;
ydot(4,:)=(-alpha./(2.*y1)).*(T./T1);
This will give you a ydot matrix of 11x4 complex double type matrix (after the transpose) in which your third and fourth columns will have repeated real values. you can extract the values out of ydot as per your requirement in the script where you are calling this function.

#### 0 Comments

Sign in to comment.