Advertisement
hiddenGem

SIR Simulation

Jun 29th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.80 KB | None | 0 0
  1. %% SIR Simulation
  2. % Susceptible, Infected, and Resistant Simulation
  3. % Defines model parameters, time vector, and preallocates
  4. % vectors for the three populations, and defines initial conditions
  5.  
  6. clc, clear
  7. Beta = 0.3;
  8. mu = 0.1;
  9. dt = 1;
  10. t = 0:1:600;
  11. S = zeros(1, 601);
  12. I = zeros(1, 601);
  13. R = zeros(1, 601);
  14. BetaT = zeros(1, 601);
  15.  
  16. BetaT(1:end) = Beta;
  17. N = 8000000;
  18. R(1) = 0;
  19. I(1) = 1;
  20. S(1) = N-I(1);
  21. stop_length = length(t)-1;
  22.  
  23. for i = 1:stop_length
  24.     S(i+1) = ((-BetaT(i)*I(i)*S(i))/N)*dt+S(i);
  25.     I(i+1) = (((BetaT(i)*I(i)*S(i))/N)-(mu*I(i)))*dt+I(i);
  26.     R(i+1) = (mu*I(i))*dt+R(i);
  27. end
  28.  
  29. hold on
  30. plot(t, S)
  31. plot(t, I)
  32. plot(t, R)
  33. legend('Susceptible Counts', 'Infected Counts', 'Resistant Counts', 'Location', 'best')
  34. ylabel('Counts')
  35. xlabel('Time(days)')
  36. title('SIR Counts vs. Days')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement