Index exceeds the number of array elements
Afficher commentaires plus anciens
clear
C1(1)= 10; %mol/L
V_tank = 1.0; %m^3
V1(1)= 0.0004167; %m^3/s
C_target(1) = 6; %mol/L
V2_stst = 0.0001278; %m^3/s
k= 2.5*(10^-5); %1/Ms
dt= 1; %s
t_max = 2; %h
i_max = floor(t_max*3600/dt);
n= zeros(1,10000);
C1(1) = C1(1) *1000; % mol/L to mol/m^3
C_target(1) = C_target(1) * 1000; % mol/L to mol/m^3
t = 0.0:dt:(i_max-1)*dt; %s
for i=1:1:i_max-1
V1(i+1)=V1(1);
C1(i+1)=C1(1);
n(i+1)=n(i)+(C1(i)*V1(i)-n(i)/V_tank*(V1(i)+V2_stst)-(k*V_tank*C_target(i)))*dt;
end
It says that there is an error in the line :
n(i+1)=n(i)+(C1(i)*V1(i)-n(i)/V_tank*(V1(i)+V2_stst)-(k*V_tank*C_target(i)))*dt;
After getting the error once, I included the line :
n= zeros(1,10000);
But it still says there is an error.
How do I fix this?
Réponses (1)
the cyclist
le 21 Mar 2021
You have defined C_target as a scalar (i.e. a single value), but you try to access it in the for loop with
C_target(i)
so when i==2, you are trying to access an element that does not exist.
Catégories
En savoir plus sur Dates and Time dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!