필터 지우기
필터 지우기

Index in position 1 exceeds array bounds

조회 수: 1 (최근 30일)
Chinaemerem Valentine Nwobi
Chinaemerem Valentine Nwobi 2019년 5월 21일
I am trying to run a script with a sub function file and enclosed are the function files and the input data but it keeps saying"Index in position 1 exceeds array bounds. please look at my scripts to know what am doing wrong.
%%
first function
function [gamma,a]=ACTIVITY_WILSON(MW,rhoL,BIP,T,Z)
R=8.314;
c=length(Z);
% 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(Z.*Lambda(j,:));
C(j)=Z(j)*Lambda(j,i)/A;
end
lngamma(i)=1-log(sum(Z.*Lambda(i,:)))-sum(C);
gamma(i)=exp(lngamma(i));
a(i)=gamma(i)*Z(i);
end
end
%% main function file to be called
%
function[PB,Ybub]=PB_VLE_Wilson(Z,C,MW,rhoL,T,BIP)
% this is a function that calculates the bubble point using the wilson
% activity coeefficient model.
c=length(Z);
for i=1:c
Psi=exp((C(i,1))+(C(i,2)/T)+(C(i,3)*log(T))+(C(i,4)*T^C(i,5)));
[gamma,~]=ACTIVITY_WILSON(MW,rhoL,BIP,T,Z);
PB=sum(Psi.*Z*gamma);
Ybub=Psi.*gamma/PB;
end
%% Input parameters
Z=[0.1 0.9];
C1=[88.134 153.23];
C2=[-8498.6 -10055];
C3=[-9.0766 -19.488];
C4=[8.330e18 1.6426e5];
C5=[6 2];
C = [C1' C2' C3' C4' C5'];
BIP=[196.2500 386.1330];
MW=[60.09 100.16];
rhoL=[803 802];
T=353.15;
P=0.4e5;
[PB,Ybub]=PB_VLE_Wilson(Z,C,MW,rhoL,T,BIP)
  댓글 수: 3
Adam
Adam 2019년 5월 21일
Use the debugger - the simplest way to find out what is wrong in so many cases. In particular the option to Stop/pause on errors. It puts you right at the error allowing you to investigate on command line by looking at the sizes and contents, types, etc of the relevant variables. It usually takes less time than it does to navigate to Matlab Answers and post a question, let alonoe wait for an answer!
Chinaemerem Valentine Nwobi
Chinaemerem Valentine Nwobi 2019년 5월 22일
thank you!

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by