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

1 view (last 30 days)
I'm struggling with this problem, and don't know how to fix it, please help :)
I'm programing the PRSV ecuation of state for a multicomponent system.
I tried with the command [z]= prsv(800,1000*1000,[647.1 512.6],[22055*1000 8097*1000],[0.345 0.564],[-0.06635 -0.16816],[0.5 0.5],0) and that error shows up, i know it has something to do with the matrix size but dont know what specifically.
function[z]= prsv(T,P,Tc,Pc,w,k1,x,kij)
nrosust=length(Tc);
R=8.314772;
for i=1:nrosust
k0(i)=0.378893+1.4897153*w-0.17131848*w.^2+0.0196554*w.^3;
k(i)=k0(i)+k1*(1+(T/Tc(i))^0.5)*(0.7-(T/Tc(i)));
alpha(i)=(1+k(i)*(1-((T/Tc(i))^0.5)))^2;
a(i)=(0.457235*(R^2*Tc(i).^2/Pc(i)))*alpha(i);
b(i)=0.07779607*(R*Tc(i)/Pc(i));
end
sum_a=0;
for i=1:nrosust
for j=1:nrosust
aij(i,j)=(a(i)*a(j))^0.5*(1-kij(i,j));
sum_a=sum_a+x(i)*x(j)*aij(i,j);
end
end
b=sum(x.*b);
A=sum_a*P/(R*T)^2;
B=b*P/(R*T);
Pol=[1 -1+B A-3*B^2-2*B -A*B+B^2+B^3];
Z=roots(Pol);
z=max(Z);

Accepted Answer

the cyclist
the cyclist on 18 May 2021
In this line:
k0(i)=0.378893+1.4897153*w-0.17131848*w.^2+0.0196554*w.^3;
w is a 2-element vector, and you are trying to assign it to a single element of k0.
  1 Comment
Bruce Lich
Bruce Lich on 18 May 2021
Edited: Bruce Lich on 18 May 2021
Thanks! I changed it to this, and now it does work:
k0(i)=0.378893+1.4897153*w(i)-0.17131848*w(i).^2+0.0196554*w(i).^3;

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!