Subscript indices must either be real positive integers or logicals.

1 visualización (últimos 30 días)
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')

Respuestas (1)

Matt Fig
Matt Fig el 6 de Dic. de 2012
Editada: Matt Fig el 6 de Dic. de 2012
In that line you are indexing k and a as if they were variables. you need to insert a * in two spots. You have 'a(' instead of 'a*(' and the same for k.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by