How to solve 'Index number exceeds number of array elements(1)'
1 回表示 (過去 30 日間)
古いコメントを表示
Siti Humaira Mohd Jasni
2021 年 11 月 9 日
コメント済み: Alan Stevens
2021 年 11 月 9 日
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!