How to solve error with Index exceeds the number of array elements (1). Error in line 35

1 次查看(过去 30 天)
clear all
rlength =10; %meter
dx = 0.1;
Numdata = rlength/dx;
%constant value
Cpf=0.707;
Cpg=0.719;
f=1.0;
H=-26000;
R=1.987;
S1=10;
S2=0.78;
U=500;
W=26400;
N0=701.2;
%initial Temperature and mole of nitrogen
Tf(1)=600;
Tg(1)=600;
N2(1)=700;
%Find k values
k1=1.78954*10^4*exp(-20800/R*Tg);
k2=2.5714*10^16*exp(-47400/R*Tg);
%find partial pressure
pN2=(286*N2/(2.598*N0)+(2*N2));
pH2=3*pN2;
pNH3=(286*((2.23*N0)-(2*N2)))/((2.598*N0)+(2*N2));
for n=1:1:Numdata
%Process
Tf(n+1)=Tf(n)+dx*((U*S1/W*Cpf)*(Tg(n)-Tf(n)));
Tg(n+1)=Tg(n)+dx*(-(U*S1/W*Cpg)*(Tg(n)-Tf(n))+(-H*S2/W*Cpg)*(f*(k1*pN2(n)*(pH2(n))^1.5/pNH3(n)-k2*pNH3(n)/(pH2(n))^1.5)));
N2(n+1)=N2(n)+dx*(-(f*(k1*pN2(n)*(pH2(n))^1.5/pNH3(n)-k2*pNH3(n)/(pH2(n))^1.5)));
end
Index exceeds the number of array elements. Index must not exceed 1.
for n = 1:1:Numdata+1
%convert length
xi(n) = (n-1)*dx;
end
%show figure
figure
plot(xi,Tf,'-r'),...
ylabel('Temperature(K)'),title('Feed gas'),grid
xlabel('Reactor Length (m)')
figure
plot(xi,Tg,'-b'),...
ylabel('Temperature(K)'),title('Product gas'),grid
xlabel('Reactor Length(m)')
figure
plot(xi,N2,'-g'),...
ylabel('Temperature(K)'),title('mole og nitrogen'),grid
xlabel('Reactor Length(m)')

回答(1 个)

DGM
DGM 2022-1-6
You're trying to access pN2(n), pNH3(n), etc, for n>1. These parameters are scalars.
for n=1:1:Numdata
%Process
Tf(n+1)=Tf(n)+dx*((U*S1/W*Cpf)*(Tg(n)-Tf(n)));
Tg(n+1)=Tg(n)+dx*(-(U*S1/W*Cpg)*(Tg(n)-Tf(n))+(-H*S2/W*Cpg)*(f*(k1*pN2(n)*(pH2(n))^1.5/pNH3(n)-k2*pNH3(n)/(pH2(n))^1.5)));
N2(n+1)=N2(n)+dx*(-(f*(k1*pN2(n)*(pH2(n))^1.5/pNH3(n)-k2*pNH3(n)/(pH2(n))^1.5)));
end
  3 个评论
DGM
DGM 2022-1-6
If those parameters are supposed to be defined as vectors, you'll have to define them as vectors. I don't know what they're supposed to be or what these calculations are doing at a concept level. If there's an error in the math, I wouldn't know.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by