what's wrong my code about ode model
10 views (last 30 days)
Show older comments
I write this code
function dydt = celldynamics(t, y, params)
%% Unpack the input variables
C = y(1);
A = y(2);
I = y(3);
E = y(4);
S = y(5);
%% Unpack the parameter values
k = params(1);
r_C = params(2);
r_max = params(3);
r_A = params(4);
delta_A = params(5);
r_I = params(6);
delta_I = params(7);
r_E = params(8);
Eprime = params(9);
beta = params(10);
gamma = params(11);
r_S = params(12);
Sprime = params(13);
Cprime = params(14);
%% Compute f(C)
f_C = min(r_C * (1 - C / Cprime), r_max);
%% 5Compute the derivatives
dCdt = f_C * C - k * C * E;
dAdt = r_A * C - delta_A * A;
dIdt = r_I * C * E - delta_I * I;
dEdt = -r_E * (E - Eprime) + beta * A * I * E * S - gamma * E * S;
dSdt = -r_S * (S - Sprime) - beta * A * I * E * S + gamma * E * S;
%% Pack the output variables into dydt
dydt = [dCdt; dAdt; dIdt; dEdt; dSdt];
end
but this code doesn't work
about line 4 ' C=y(1)'
and then say ' Insufficient input arguments.'
So how to modify that?
2 Comments
Torsten
on 1 Jun 2023
And how do you call this function ?
If you simply run the function with empty input arguments for t, y and params, you have "Insufficient input arguments".
Accepted Answer
Walter Roberson
on 1 Jun 2023
Moved: Walter Roberson
on 1 Jun 2023
When you press the green Run button to run the code, should MATLAB:
- (A) look in the calling function to see whether it happends to define variables t and y and params and if so use those, but if the calling function does not define any of those variables, declare an error?; OR
- (B) look in the calling function to see whether it happends to define variables t and y and params and if so use those, and if not look inside the function that called that, and so on, continually looking in the caller until it finds variables t and y and params or discovers that no function defines them? If so then should the search for any given variable stop as soon as it is found, or should the search continue until a context is found that defines all of the variables at the same time?; OR
- (C ) only look in the base workspace, and if the base workspace does not define the variables then declare an error?; OR
- (D) only look in the global workspace? OR
- (E) examine all of the code in the function, and if anything in the code checks how many variables were passed or checks whether any variables were missing, then decide that this function was deliberately designed to work with the possibility of missing variables, and so not do any of the searching described in (A) to (D) -- only do that kind of searching if the code appears to not check for missing parameters ? OR
- (F) Not do any checking about how good the code is, and not do any searching in other workspaces for variables: if the code flow turns out in practice to need a variable that the user did not pass in, then an error should be given ?
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!