필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
%% am encountering difficulty with my codes below and I will be pasting the
%the function file and the input parameters to run them with.
%%
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
%%
x= Varying from 0 to 1;
MW=[46.0684 18.0153];
rhoL=[785 997];
BIP=[1972.2 ; 3700.1];
%%
Please help me find what am doing wrong . thank you but please comment if there is something am doing wrong with the way i ask because I never got replies before now.
  댓글 수: 1
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 5월 4일
편집: KALYAN ACHARJYA 2019년 5월 4일
How to format the question, read here? Well formatting question get answer quickly.

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

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 5월 4일
편집: KALYAN ACHARJYA 2019년 5월 4일
Save the following function file>Save as : ACTIVITY_WILSON.m file name
function [gamma,a]=ACTIVITY_WILSON(MW,rhoL,BIP,T,x)
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
Now call the above function from different Matlab scripts file:
%%
x=0.2; % Any value 0 to 1
MW=[46.0684 18.0153];
rhoL=[785 997];
BIP=[1972.2; 3700.1];
T=30; % Hopefully this is tempature, set accordingly
[gamma,a]=ACTIVITY_WILSON(MW,rhoL,BIP,T,x)
Result
gamma =
1.358311135425136e+04
a =
2.716622270850272e+03
Suggested: To undestand function call, read here

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by