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

2 views (last 30 days)
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?

Accepted Answer

Alan Stevens
Alan Stevens on 9 Nov 2021
You don't update XSOL, so when ct is 2, XSOL(ct) doesn't exist.
  6 Comments
Alan Stevens
Alan Stevens on 9 Nov 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')

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by