How to assign indicies of a function imput vector
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2012 年 10 月 7 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!