Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # SIR-Model-odeint.py
- # Juhani Kaukoranta 07.03.2020
- from scipy.integrate import odeint #diffyht
- import numpy as np # nopeat vektorit, matriisit
- import matplotlib.pyplot as plt #plottaus
- # diffyhtälöryhmän sirmodel määrittely
- def sirmodel(y,t):
- b = 1.0/2 #parametrit
- k = 1.0/3
- s, i, r = y # kolme funktiota
- dydt = [-b*s*i, b*s*i - k*i, k*i] # derivaatat dy/dt
- return dydt
- # alkuarvot
- y0 = [1, 1.27e-6, 0]
- # aikaväli 151 päivää, välillä 0...150,
- t = np.linspace(0,150,151)
- # ratkaisu
- sol = odeint(sirmodel,y0,t)
- # plottaukset s,i,r väreillä r,g,b
- plt.title('Epidemian kulku')
- plt.plot(t, sol[:,0], 'b', label = 's=susceptible')
- plt.plot(t, sol[:,1], 'g' ,label = 'i=infected')
- plt.plot(t, sol[:,2], 'r' ,label = 'r=recovered')
- plt.legend(loc='best')
- plt.xlabel('t = päivä')
- plt.ylabel('suht osuus')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment