I keep getting the error "Undefined function or variable". What is wrong with this ODE example?
Afficher commentaires plus anciens
% SIR.m % % Imlements a SIR infection model % dS/dt = -beta SI % dI/dt = beta SI - delta I % dR/dt = delta I % % Inputs: % t - Time variable: not used here because our equation % is independent of time, or 'autonomous'. % x - Independent variable: this contains three % populations (S, I, and R) % Output: % dx - First derivative: the rate of change of the populations
function dx = SIR(t,x)
dx = [0;0;0];
beta = 0.0003;
delta = 1;
dx(1) = -beta * x(1) * x(2); dx(2) = beta * x(1) * x(2) - delta * x(2); dx(3) = delta *x(2);
options = odeset('RelTol', 1e-4, 'NonNegative', [1 2 3]);
[t,x] = ode('SIR', [0 10], [1000 1 0], options);
plot(t,x);
legend('S','I','R')
Réponse acceptée
Plus de réponses (1)
Torsten
le 23 Août 2017
Try
function main
options = odeset('RelTol', 1e-4, 'NonNegative', [1 2 3]);
[t,x] = ode45(@SIR, [0 10], [1000; 1; 0], options);
plot(t,x);
legend('S','I','R')
function dx = SIR(t,x)
dx = [0;0;0];
beta = 0.0003;
delta = 1;
dx(1) = -beta * x(1) * x(2);
dx(2) = beta * x(1) * x(2) - delta * x(2);
dx(3) = delta *x(2);
Best wishes
Torsten.
1 commentaire
Nora Rosvoll Finstad
le 23 Août 2017
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!