How to assign indicies of a function imput vector
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Walter Roberson
on 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])
0 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!