フィルターのクリア

How to assign indicies of a function imput vector

2 ビュー (過去 30 日間)
Sean Wu
Sean Wu 2012 年 10 月 7 日
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 件のコメント
Sean Wu
Sean Wu 2012 年 10 月 7 日
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 2012 年 10 月 7 日
This fixed the errors:
N=[999,1,0,0,0,0]
ode45(@SIR_Model, [0 1000],N)
Thanks for your help

サインインしてコメントする。

採用された回答

Walter Roberson
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 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by