Indices in discrete mass and temperature balance
2 views (last 30 days)
Show older comments
Hello all,
I'm trying to model a plug-flow reactor where mass and temperature are changing over the z-axis. Therefore, I have 2 equations, dC/dz (concentration) and dT/dz (temperature), and I have them in discrete form such that the next point can be calculated on the basis of the updated values of both T and C.The part of the code concerning this system of equations that I currently have is given below. Consider all constants (AR,q,k0) and initial conditions (CEO(end) and T) to be fine and given. The problem I'm getting is that in the Temp(n+1) line it states: 'Subscript indices must either be real positive integers or logicals'. However, CEO2(2) does give a value, while all indices are the same. Can anyone see what the issue is here? Thanks in advance!
n = 1;
i = 20;
f = @(z,CEO2,Temp) (-AR/q)*k0*(exp(-Ea/(R*Temp)))*B0*CEO2;
g = @(z,CEO2,Temp) (AR/(q*rho*cp))*-dH*k0*(exp(-Ea/(R*Temp)))*B0*CEO2;
dz = h/i
CEO2(1) = CEO*(end)*1000
Temp(1) = T;
z(1) = 0;
while (z(n) <= h)
CEO2(n+1) = CEO2(n) + dz*f(z(n), CEO2(n), Temp(n))
Temp(n+1) = Temp(n) + dz*g(z(n), CEO2(n), Temp(n))
z(n+1) = z(n) + dz
n = n+1;
end
0 Comments
Answers (1)
Image Analyst
on 29 Nov 2019
It's well discussed in the FAQ: https://matlab.fandom.com/wiki/FAQ#.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!