8
$\begingroup$

This may be more that my math is messed up than my Mathematica, but I can't seem to figure it out. I am trying to use NDSolve to find solutions to an S-I-R model. The code I've done so far is

b = 0.18; k = 0.14;
system = {s'[t] == -b s[t] i[t], i'[t] == b s[t] i[t] - k i[t], 
   r'[t] == k i[t], s[0] == 1, i[0] == .007, r[0] == 0};
sol = NDSolve[system, {s, i, r}, t]
Plot[Evaluate[{s[t], i[t]} /. sol], {t, 0, 100}]

This seems to almost work, but the InterpolatingFunctions are strange compared to what I would expect to get. Am I doing something wrong in the code? Any advice is appreciated.

$\endgroup$
1
  • 3
    $\begingroup$ In NDSolve you hve just t while it should be {t, 0, 100}. $\endgroup$
    – corey979
    Commented Nov 28, 2016 at 22:45

1 Answer 1

8
$\begingroup$

According to comments made by Corey979

b = 0.18; k = 0.14;
system = {s'[t] == -b s[t] i[t], i'[t] == b s[t] i[t] - k i[t], 
   r'[t] == k i[t], s[0] == 1, i[0] == .007, r[0] == 0};
sol = NDSolve[system, {s, i, r}, {t, 0, 100}]
Plot[Evaluate[{s[t], i[t]} /. sol], {t, 0, 100}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you very much, everyone. Specifying the range of NDSolve has fixed the problem. $\endgroup$
    – MattW
    Commented Nov 29, 2016 at 0:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.