MATLAB: Subscript indices must either be real positive integers or logicals.

debug

I am running this code an keep hitting this error when running the code. It occurs in line 36. The suggestions said it is matrix or vector related so i have indexed and called any variable as a constant yet it still occurs.
Pc = 2.74e6;
Tc = 530.3;
count=0;
yellow=0;
T = [100:.1:1000];
Pr = [0.02, 0.50, 1.0, 2.0];
P = Pc.*Pr;
V = 1:length(T);
acen = .333;
R = 8.3145;
b = 0.0778*R*Tc/Pc;
Cp_IG = (1:length(T));
colors = ['y' 'm' 'r' 'c'];
colorindx = 1;
hold on;
for Puse = P
n = 1;
Cp = 1:length(T);
yellow=yellow+1;
for Tuse = T;
a =3.243943838*(1.858281421-0.3727046432e-1*sqrt(Tuse))^2 ;
Vest1 = R*Tuse/Puse;
Vest2 = R*Tuse/(Puse+(a/(Vest1*(Vest1 + b)+b*(Vest1-b))))+b;
while abs((Vest1-Vest2))/Vest1 > .0001
Vest1 = Vest2;
Vest2 = R*Tuse/(Puse+(a/(Vest1*(Vest1 + b)+b*(Vest1-b))))+b;
end
t=abs(Tuse);
V(n) = Vest2;
v=abs(Vest2)
ts=sqrt(t);
count=count+1
if v>.00014;
z= -t*(8.314/(v-0.1251897785e-3)+(.1209032931*(1.858281421-0.3727046432e-1*sqrt(t)))/((v(v+0.1251897785e-3)+0.1251897785e-3)*sqrt(t)))^2/(-8.314*t/(v-0.1251897785e-3)^2+3.243943838*(1.858281421-0.3727046432e-1*sqrt(t))^2*(v+0.1251897785e-3)/(v(v+0.1251897785e-3)+0.1251897785e-3)^2)+t*(8.314000000*ln(v-0.1251897785e-3)-(.40274*(sqrt(t)*atan(89.3763*v+0.55945e-2)-49.8594*atan(89.3763*v+0.55945e-2)))/sqrt(t))-12.253+.8642*t-0.6289e-3*t^2+1.836000000*10^(-7)*t^3;
x= 0;
c= 0;
Cp(n)=z+x+c;
else
Cp(n)=0;
end;
n = n+1;
end;
semilogy(T, Cp, colors(colorindx));
colorindx = colorindx+1;
end;

Best Answer

  • replace line 36 with the following line:
    z= -t * (8.314 / ( v - 0.1251897785e-3) + (.1209032931 * (1.858281421 - 0.3727046432e-1 * sqrt(t))) / ((v * (v + 0.1251897785e-3) + 0.1251897785e-3) * sqrt(t)))^2 / (-8.314 * t / (v - 0.1251897785e-3)^2 + 3.243943838 * (1.858281421 - 0.3727046432e-1 * sqrt(t))^2 * (v + 0.1251897785e-3) / (v * (v+0.1251897785e-3)+0.1251897785e-3)^2)+t*(8.314000000*log(v-0.1251897785e-3)-(.40274*(sqrt(t)*atan(89.3763*v+0.55945e-2)-49.8594* atan(89.3763*v+0.55945e-2)))/sqrt(t))-12.253+.8642*t-0.6289e-3*t^2+1.836000000*10^(-7)*t^3;
    you were making few syntax mistakes in it