How to solve 'Index number exceeds number of array elements(1)'

2 visualizaciones (últimos 30 días)
function substrate_glucose()
% Effect of carbon sources on the growth of Lactoccus lactis. Ibrahim et. al (2010)
% Parameters
u = 0.57 ; % specific growth rate h-1
y = 0.52 ; % cell yield coefficient (g/g)
s = 5.12 ; % substrate utilization
% Initial Value
x0 = 0.3 ; % Initial cell concentration (g/L)
XSOL(1) = x0 ; % Store initial value in solution vector
X = x0 + y*s ; % Calculated maximum X
s0 = 10 ; % Initial carbon source
SSOL(1) = s0 ; % Store initial value of s
% Time information
dt = 1 ; % Time step
TFinal = 8 ; % Final simulation time
t=0 ; % Initialize time to zero
tVec(1) =0; % store first time-value
% Solve equation/ March forward in time
ct = 1 ; % counter
while t < TFinal
% Euler's time-step
SSOL(ct+1) = SSOL(ct) - dt*u*(1/y)*(XSOL(ct)*(1-XSOL(ct)/X));
% Store time-value
tVec(ct+1) = t + dt;
% Update counter and time
t = t+dt ;
ct = ct+1 ;
end
got error in SSOL(ct+1) = SSOL(ct) - dt*u*(1/y)*(XSOL(ct)*(1-XSOL(ct)/X)); where it exceeds the number of array elements (1).
Can someone please help me?

Respuesta aceptada

Alan Stevens
Alan Stevens el 9 de Nov. de 2021
You don't update XSOL, so when ct is 2, XSOL(ct) doesn't exist.
  6 comentarios
Siti Humaira Mohd Jasni
Siti Humaira Mohd Jasni el 9 de Nov. de 2021
ct = 1 ; % counter
for ct = 1 : TFinal-1
XSOL(ct+1) = XSOL(ct) + dt*u*XSOL(ct)*(1-XSOL(ct) / X);
end
while t < TFinal
SSOL(ct+1) = SSOL(ct) - dt*u*(1/y)*XSOL(ct);
end
I did it like this but it still have error at SSOL(ct+1) = SSOL(ct) - dt*u*(1/y)*XSOL(ct);
index exceed the number of arrays.
Alan Stevens
Alan Stevens el 9 de Nov. de 2021
Like this:
% Effect of carbon sources on the growth of Lactoccus lactis. Ibrahim et. al (2010)
% Parameters
u = 0.57 ; % specific growth rate h-1
y = 0.52 ; % cell yield coefficient (g/g)
s = 5.12 ; % substrate utilization
% Initial Value
x0 = 0.3 ; % Initial cell concentration (g/L)
XSOL(1) = x0 ; % Store initial value in solution vector
X = x0 + y*s ; % Calculated maximum X
s0 = 10 ; % Initial carbon source
SSOL(1) = s0 ; % Store initial value of s
% Time information
dt = 1 ; % Time step
TFinal = 8 ; % Final simulation time
t=0 ; % Initialize time to zero
tVec(1) =0; % store first time-value
% Solve equation/ March forward in time
ct = 1 ; % counter
ct = 1 ; % counter
for ct = 1 : TFinal-1
XSOL(ct+1) = XSOL(ct) + dt*u*XSOL(ct)*(1-XSOL(ct) / X);
SSOL(ct+1) = SSOL(ct) - dt*u*(1/y)*XSOL(ct);
% Store time-value
tVec(ct+1) = t + dt;
% Update counter and time
t = t+dt ;
ct = ct+1 ;
end
subplot(2,1,1)
plot(tVec,XSOL),grid
xlabel('t'), ylabel('XSOL')
subplot(2,1,2)
plot(tVec,SSOL),grid
xlabel('t'), ylabel('SSOL')

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by