Index exceeds the number of array elements (1).
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Im struggling with this code, the problem occurs in line 40
lnphi=-log(z-B)+(b(i)*(z-1)/b)-((A/(2*sqrt(2)*B))*((2*sum_A(i)/sum_a)-(b(i)/b))*log((z+(1+sqrt(2)*B))/(z+(1-sqrt(2)*B))));
Here's the full code, im trying to program the PRSV ecuation of state. Please help :)
function[phi]= prsv(T,P,Tc,Pc,w,k1,x)
nrosust=length(Tc);
R=8.314772;
for i=1:nrosust
k0(i)=0.378893+1.4897153*w(i)-0.17131848*w(i).^2+0.0196554*w(i).^3;
k(i)=k0(i)+k1(i)*(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;
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);
for i=1:nrosust
sum_A(i)=0;
for j=1:nrosust
sum_A(i)=sum_A(i)+x(j)*aij(i,j);
end
end
for i=1:nrosust
lnphi=-log(z-B)+(b(i)*(z-1)/b)-((A/(2*sqrt(2)*B))*((2*sum_A(i)/sum_a)-(b(i)/b))*log((z+(1+sqrt(2)*B))/(z+(1-sqrt(2)*B))));
phi(i)=exp(lnphi);
end
2 commentaires
per isakson
le 19 Mai 2021
>> prsv(1,2,3,4,5,6,7)
ans =
0.0085916 + 0.0013123i
What input data did you use to get this error?
Réponses (1)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!