How to assign indicies of a function imput vector

1 vue (au cours des 30 derniers jours)
Sean Wu
Sean Wu le 7 Oct 2012
I'm trying to write a script to model a SIR epidemic. Matlab is giving me an error (not enough input arguments) when trying to define variables (S, I, R,..) as entries in the function input vector N (S=N(1), etc...).
Here's the script:
function result=SIR_Model( t, N)
%define probabilities
qi=0.005;
lamda=0.1;
gammaS=0.1;
gammaM=0.009;
pl=0.045;
pj=0.005;
qr=qi/lamda;
S=N(1);
I=N(2);
R=N(3);
Sg=N(4);
Ig=N(5);
Rg=N(6);
%Enter equations
dR=qr*I;
dI=qi*Sg*Ig-qr*I;
dS=-qi*Sg*Ig;
dRg=qr*Ig-pl*(Rg+qr*Ig)+pj*((R-Rg)+qr*(I-Ig));
dIg=qi*Sg*Ig-qr*Ig-pl*(Ig+qi*Sg*Ig)+(1-qr)*pj*(I-Ig);
dSg=-qi*Sg*Ig-pl*(Sg-qi*Sg*Ig)+pj*(S-Sg);
result=[dR, dI, dS, dRg, dIg, dSg];
%use odeXXx to solve DiffEQ
ODE45(SIR_Model, [0,2000], [999,1,0,0,0,0])
  3 commentaires
Sean Wu
Sean Wu le 7 Oct 2012
Sorry, was calling it wrong. Here're the errors:
ode45(@SIR_Model, [0,1000], [999, 1, 0,0,0,0])
Error using feval
Undefined function 'SIR_Model' for input arguments of type 'double'.
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn,
...
Sean Wu
Sean Wu le 7 Oct 2012
This fixed the errors:
N=[999,1,0,0,0,0]
ode45(@SIR_Model, [0 1000],N)
Thanks for your help

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Oct 2012
Change
ODE45(SIR_Model, [0,2000], [999,1,0,0,0,0])
to
ode45(@SIR_Model, [0,2000], [999,1,0,0,0,0])

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by