Index exceeds the number of array elements (1).
조회 수: 1 (최근 30일)
이전 댓글 표시
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
per isakson
2021년 5월 19일
>> prsv(1,2,3,4,5,6,7)
ans =
0.0085916 + 0.0013123i
What input data did you use to get this error?
답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!