## Subscript indices must either be real positive integers or logicals.

Steven

### Steven (view profile)

さんによって質問されました 2012 年 12 月 6 日
I'm writing code for a class project, and I keep getting this error in line 32(The Cv(i) = line) and I'm not sure why.
function outputValue=Cp(P)
Pc=4550;
Tc=654;
a = 2971.0065;
b = .092968;
k = .7135;
R = 8.314;
Ai=112.057;
Bi=-0.8324;
Ci=0.002865;
Di=-0.000003;
v = [];
T = [300:1:650];
Cp = [];
Cpi = [];
Cv = [];
dPdT = [];
dPdV = [];
for t = length(T)
A = (a.*P)./(R.^2.*t.^2);
B = (P.*b)./(R.*t);
Z = [1 -(1-B) (A-3.*B-2.*B) -(A.*B-B.^2-B.^3)];
r =roots(Z);
G = real(max(r));
V = (G.*R.*t)./P;
v = [v V];
end
for i = 1:length(T)
Cpi(i) = Ai + Bi.*T(i) + Ci.*T(i).^2 + Di.*T(i).^3;
dPdT(i) = (R./(v(i)-b))-((a.*(1+k.*(1-(T(i)./Tc).^.5)).^2)./(v(i).^2+2.*v(i).*b-b.^2));
dPdV(i) = -((R.*T(i))./(v(i)-b).^2)+(a.*(1+k.*(1-(T(i)./Tc).^.5)).^2)./(v(i).^2+2.*v(i).*b-b.^2).^2;
Cv(i) = (Cpi(i)-3.*R.*T(i)) + T(i).*((0.3535533906.*a.*k.^2.*atanh((0.3535533906.*(2.*v(i)+2.*b))./b)./(T(i).*Tc.*b))+((0.3535533906.*a(1+k(1-1.*(T(i)./Tc).^0.5)).*k.*atanh((0.3535533906.*(2.*v(i)+2.*b))./b))./((T(i)./Tc).^(3./2).*Tc.^2.*b)));
Cp(i) = Cv(i) - (T.*v(i).*(dPdT(i)).^2)./dPdV(i);
end
plot(Cp,T,'-g')

#### 0 件のコメント

サインイン to comment.

2012 年 12 月 6 日