필터 지우기
필터 지우기

Index exceeds the number of array elements (1).

조회 수: 1 (최근 30일)
Bruce Lich
Bruce Lich 2021년 5월 19일
편집: Bruce Lich 2021년 5월 19일
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
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?
Bruce Lich
Bruce Lich 2021년 5월 19일
편집: Bruce Lich 2021년 5월 19일
Hi! When every input is a scalar, it works just fine. The problem is when i try it with vectors as inputs (for mixes).
i.e. this one:
(note that T and P are global parameters, they are always scalars, whilst the rest are not unless its a pure substance)
[phi]= prsv(800,1000*1000,[647.1 512.6],[22055*1000 8097*1000],[0.345 0.564],[-0.06635 -0.16816],[0.3 0.7])

댓글을 달려면 로그인하십시오.

답변 (1개)

per isakson
per isakson 2021년 5월 19일

카테고리

Help CenterFile Exchange에서 Desktop에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by