Error in ode45 (line 115) odeargumen​ts(FcnHand​lesUsed, solver_name, ode, tspan, y0, options, varargin);

3 vues (au cours des 30 derniers jours)
%%parameters
C = 1; %concentration of contaminant
O = 1; %concentration of oxygen
B = 1; %concentration of microorganism
Do = 0.2; %diffusivity constant
Dc = 0.2; %diffusivity constant
v = 1; %velocity
Ko = 0.1; %half-saturation constant of oxygen
Kc = 0.1; %half-saturation constant of the substrate
Kd = 0.125; %degradation constant
Yc = 0.125; %mass of bacteria
dx = 0.2; %spatial space
dt = 0.002; %time interval
mu = 0.1; %viscosity
delta = 1;
%%equation used
%%d(C)/d(t) = delta(Dc*delta*C-vC)- mu*B/Yc*(C/C+Kc)*(O/O+Ko)
%%d(O)/d(t) = delta(Do*delta*C-vC)- mu*B/Yc*(C/C+Kc)*(O/O+Ko)
%%d(B)/d(t) = mu*B*(C/C+Kc)*(c/c+Kc)-Kd*B
f = @(t,a) [delta(Dc*delta*C-vC)- mu*B/Yc*(C/C+Kc)*(O/O+Ko); -delta(Do*delta*C-vC)- mu*B/Yc*(C/C+Kc)*(O/O+Ko); mu*B*(C/C+Kc)*(c/c+Kc)-Kd*B; ];
xt0 = [0.323,10,9];
[tspan,a] = ode45(f,[0 50],xt0);
figure
plot(tspan,a(:,1),tspan,a(:,2),tspan,a(:,3))
xlabel('time')
ylabel('Concentration(mg/l)')

Réponses (1)

Walter Roberson
Walter Roberson le 28 Jan 2023
delta = 1;
That is a numeric scalar. Valid indices for it are numeric 1, logical true, logical false, and the empty vector. Any index for delta that does not evaluate to one of those will be out of range.
f = @(t,a) [delta(Dc*delta*C-vC)- mu*B/Yc*(C/C+Kc)*(O/O+Ko); -delta(Do*delta*C-vC)- mu*B/Yc*(C/C+Kc)*(O/O+Ko); mu*B*(C/C+Kc)*(c/c+Kc)-Kd*B; ];
Dc*delta*C-vC is not evaluating to 1 or the empty array, and so you have index out of range.
Reminder: there are very few programming languages that support implied multiplication, as it introduces too many ambiguities. For example is x(3) intended to indicate x being indexed at 3, or is it intended to indicate that x is being multiplied by an expression that happens to have been stated in parentheses? If 3x is considered to mean that x is to be multiplied by 3 then is x3 intended to indicate a different variable name or to indicate that x is being multiplied by 3?

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by