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!