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