"Index in position 1 exceeds array bounds (must not exceed 1)." Error

2 ビュー (過去 30 日間)
Abdullahi Geedi
Abdullahi Geedi 2019 年 5 月 22 日
コメント済み: madhan ravi 2019 年 5 月 22 日
Hi
I've been given a program that calculates the activity coefficients gamma) and the activity of each component in a mixture. Except i can't run it without getting this error:
Error in TestingSubprograms (line 18)
[gamma,a]=ACTIVITY_WILSON(MW,rhoL,BIP,T,x)
The function is:
function [gamma,a]=ACTIVITY_WILSON(MW,rhoL,BIP,T,x)
%This program calculates the activity coefficients (gamma) and the
%activities (a) of each component of a mixture of c components using the
%Wilson model.
%INPUT PARAMETERS: MW: vector (1xc) reporting the molecular weights of the
%c components; rhoL, vector (1xc) reporting the liquid density of the c
%pure components at temperature T; BIP is a matrix cxc reporting the energy
%interaction parameters (BIP(i,j)=lambda_ij-lambda_ii, J/mol). The energy
%interaction parameters are temperature independent; T: temperature of the
%system; x vector (1xc) reporting the mole fractions of the components of
%the mixture.
%OUTPUT PARAMETERS: gamma: vector 1xc reporting the activity
%coefficients of the components of the mixture; a: vector 1xc reporting the
%activities of the components of the mixture.
%Unless otherwise stated, all input/output parameters are expressed
%according to MKS.
R=8.314;
c=length(x);
%Molar volumes of the pure liquid components composing the mixture
VL=1./((rhoL*1000)./MW);
%Lambda terms (dimensionless) of the Wilson formula
for i=1:c
for j=1:c
Lambda(i,j)=(VL(j)/VL(i))*exp(-BIP(i,j)/(R*T));
end
end
for i=1:c
for j=1:c
A=sum(x.*Lambda(j,:));
C(j)=x(j)*Lambda(j,i)/A;
end
lngamma(i)=1-log(sum(x.*Lambda(i,:)))-sum(C);
gamma(i)=exp(lngamma(i));
a(i)=gamma(i)*x(i);
end
end
The input i'm using is :
x=[0.1 0.9];
MW=[60.09 100.16];
rhoL=[803 802];
T=303.15;
BIP=[196.250 386.133];
Any help would be appreciated. Thanks

採用された回答

KSSV
KSSV 2019 年 5 月 22 日
編集済み: KSSV 2019 年 5 月 22 日
Problem is with your BIP. It shoule be cXc matrix i.e it shoule be 2X2 for your inputs. You have entered it as 1X2, so the error.
BIP=[196.250 386.133;196.250 386.133];
Or change these lines:
for i=1:c
for j=1:c
Lambda(i,j)=(VL(j)/VL(i))*exp(-BIP(i,j)/(R*T));
end
end
to
for i=1:c
for j=1:c
Lambda(i,j)=(VL(j)/VL(i))*exp(-BIP(j)/(R*T));
end
end
  2 件のコメント
Abdullahi Geedi
Abdullahi Geedi 2019 年 5 月 22 日
Greatly appreacited. It works :D
madhan ravi
madhan ravi 2019 年 5 月 22 日
Also Lambda is not preallocated

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeThermal Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by