I'm trying to solve a system of SIR differential equations with Mathematica.
My code is:
DSolve[
{S'[t] == -0.0005 S[t] i[t],
i'[t] == 0.0005*S[t] i[t] - 0.1 i[t],
R'[t] == 0.1 i[t],
S[0] == 1500, i[0] == 1, R[0] == 0},
{S[t], i[t], R[t]}, t]
However, when I evaluate the above, the solver goes on and on forever. Investigating I found this code on another question on Math Stack exchange:
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}]
`
Can somebody explain why this code runs and my code takes forever?
DSolve[]
tries to look for a symbolic solution, which takes more effort that a numerical integration like what is done byNDSolve[]
. Do you really need a symbolic solution? $\endgroup$