How to solve 'Index number exceeds number of array elements(1)'
조회 수: 2 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
Alan Stevens
2021년 11월 9일
You don't update XSOL, so when ct is 2, XSOL(ct) doesn't exist.
댓글 수: 6
Alan Stevens
2021년 11월 9일
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')
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!