jukaukor

SIR-Model-Euler.py

Mar 8th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. # SIR-Model-Euler.py
  2. # katso https://www.maa.org/press/periodicals/loci/joma/the-sir-model-for-spread-of-disease-the-differential-equation-model
  3. # Juhani Kaukoranta 08.03.2020
  4.  
  5. import numpy as np # nopeat vektorit, matriisit
  6. import matplotlib.pyplot as plt #plottaus
  7. def SIR(x,s,i,r,delta_t,n):
  8. b = 1.0/3 # parametri, infektoituneella keskim 3 kontaktia päivässä
  9. k = 1.0/7 # parametri, infektion kesto keskim 7 päivää
  10. for j in range (0, n):
  11. s[j+1] = s[j] - b* s[j]*i[j]*delta_t
  12. i[j+1] = i[j] + (b*s[j]*i[j] - k*i[j])*delta_t
  13. r[j+1] = r[j] + k*i[j]*delta_t
  14. return s,i,r # palauttaa käyrien s,i,r arvot
  15.  
  16. def Plottaukset(x,s,i,r):
  17. plt.title('Epidemian kulku')
  18. plt.plot(x, s, 'b', label = 's=susceptible')
  19. plt.plot(x, i, 'g' ,label = 'i=infected')
  20. plt.plot(x, r, 'r' ,label = 'r=recovered')
  21. plt.legend(loc='best')
Advertisement
Add Comment
Please, Sign In to add comment