Message Boards Message Boards

SIR model - Avoid NDSolve problem

Posted 4 years ago

Hello, i am trying to implement a SIR model(for covirus simulation) as a learning example of Wolfram Mathematica. But my model dont work, and gives me erros i can't understand(NDSolve::dvnoarg: The function i appears with no arguments. and other in the plot). Can anyone help. This is what i am workin on, the model program:

s0 = 0.09; i0 = 0.01; r0 = 0
trans = 3.2; recov = 0.02
tmax = 20
Clear[s, i, r]
eqn = {s'[t] == -trans*s[t]*i[t], 
  i'[t] == trans*s[t]*i[t] - recov*i[t], r'[t] == recov*i[t], 
  s[0] == s0, i[0] == i0, r[0] == r0}

sol = NDSolve[eqn, {s, i, r}, {t, 0, tmax}]

Plot[{i[t]} /. sol, {t, 0, 100}]
POSTED BY: Rodrigo Cordeiro
2 Replies

You are right, i didn't know i need the ; after each assigment. It is now working. Thanks a lot.

POSTED BY: Rodrigo Cordeiro

Your code should work. Make sure you have ; after each assignment:

s0 = 0.09; i0 = 0.01; r0 = 0;
trans = 3.2; recov = 0.02;
tmax = 20;

ok

POSTED BY: Shenghui Yang
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract