Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168730
Image: ubuntu2004
import scipy.integrate import matplotlib.pyplot as plt import numpy time_step=0.05 time_end=70.0 omegaK=0 # contacts of iU with sE omegaU=0 # contacts of iK with sE phi=.2154/4 # rate of education gamma=.0336 # rate of becoming aware of infection #initial starting populations iU0 = 2/21*.69*100 sU0 = 19/21*.75*100 sE0 = 19/21*100*.25 iK0 = 2/21*100*.31 N0 = 100 betaK=0 # contacts of iK with sU betaU=N0*.001 # contacts of iU with sU BR=0.0241 DRiU = .63*.0222 DRsU = .37*.0222 DRsE = .37*.0222 DRiK = .63*.0222 # First, define the function that takes the previous time populations # and returns the new populations def differential_eqs(previous_state,t): sU,sE,iU,iK,N = previous_state # susceptible uneducated sU_new = (-betaK ) * (iK) * (sU) - (betaU) * (iU) * (sU) - phi * sU - (DRsU * sU) +(BR * N * .90) #susceptible educated sE_new = (-omegaK ) * (iK) * (sE) - (omegaU ) * (iU) * (sE) + phi * sU - (DRsE*sE) #infected unknown iU_new = (betaK ) * (iK) * (sU) + (betaU) * (iU) * (sU) - (phi + gamma) * iU - (BR * N * .10) - (DRiU * iU) #infected known iK_new = (omegaK ) * (iK) * (sE) + (omegaU ) * (iU) * (sE) + (phi + gamma) * iU + (2*(BR *N * .10)) - DRiK *iK # total pop N_new = iK + iU + sE + sU #print sU + sE + iU + iK #print N_new return sU_new, sE_new, iU_new, iK_new, N_new # Now solve the differential equations to get the actual populations start_populations = (sU0, sE0, iU0, iK0, N0) time_range=[0.0..time_end, step=time_step] populations = scipy.integrate.odeint(differential_eqs,start_populations,time_range) # Extract the data for each group of people susceptible_U = populations[:,0] # first column susceptible_E = populations[:,1] # second column infected_U = populations[:,2] # third column infected_K = populations[:,3] #fourth column total_pop = populations[:,4] #Plot the results plt.figure() plt.plot(susceptible_U, '-g', label='Susceptible - Uneducated') plt.plot(susceptible_E, '-b', label='Susceptible - Educated') plt.plot(infected_U, '-r', label='Infected Unknown') plt.plot(infected_K, '-y', label='Infected Known') plt.legend() plt.title('S-I Model with Education') plt.xlabel('Time') plt.ylabel('population') plt.axis([0,70,-2,N0]) plt.savefig('test.png')
import scipy.integrate import matplotlib.pyplot as plt import numpy time_step=0.05 time_end=70.0 omegaK=0 # contacts of iU with sE omegaU=0 # contacts of iK with sE phi=.2154/4 # rate of education gamma=.0336 # rate of becoming aware of infection #initial starting populations iU0 = 2/21*.69*100 sU0 = 19/21*.75*100 sE0 = 19/21*100*.25 iK0 = 2/21*100*.31 N0 = 100 betaK=0 # contacts of iK with sU betaU=N0*.001 # contacts of iU with sU BR=0.0241 DRiU = .63*.0222 DRsU = .37*.0222 DRsE = .37*.0222 DRiK = .63*.0222 # First, define the function that takes the previous time populations # and returns the new populations def differential_eqs(previous_state,t): sU,sE,iU,iK,N = previous_state # susceptible uneducated sU_new = (-betaK ) * (iK) * (sU) - (betaU) * (iU) * (sU) - phi * sU - (DRsU * sU) +(BR * N * .90) #susceptible educated sE_new = (-omegaK ) * (iK) * (sE) - (omegaU ) * (iU) * (sE) + phi * sU - (DRsE*sE) #infected unknown iU_new = (betaK ) * (iK) * (sU) + (betaU) * (iU) * (sU) - (phi + gamma) * iU - (BR * N * .10) - (DRiU * iU) #infected known iK_new = (omegaK ) * (iK) * (sE) + (omegaU ) * (iU) * (sE) + (phi + gamma) * iU + (2*(BR *N * .10)) - DRiK *iK # total pop N_new = iK + iU + sE + sU #print sU + sE + iU + iK #print N_new return sU_new, sE_new, iU_new, iK_new, N_new # Now solve the differential equations to get the actual populations start_populations = (sU0, sE0, iU0, iK0, N0) time_range=[0.0..time_end, step=time_step] populations = scipy.integrate.odeint(differential_eqs,start_populations,time_range) # Extract the data for each group of people susceptible_U = populations[:,0] # first column susceptible_E = populations[:,1] # second column infected_U = populations[:,2] # third column infected_K = populations[:,3] #fourth column total_pop = populations[:,4] percent_sU = susceptible_U/total_pop*100 percent_sE = susceptible_E/total_pop*100 percent_iU = infected_U/total_pop*100 percent_iK = infected_K/total_pop*100 #Plot the results plt.figure() plt.plot(percent_sU, '-g', label='Susceptible - Uneducated') plt.plot(percent_sE, '-b', label='Susceptible - Educated') plt.plot(percent_iU, '-r', label='Infected Unknown') plt.plot(percent_iK, '-y', label='Infected Known') plt.legend() plt.title('Population Percentage') plt.xlabel('Time') plt.ylabel('percent population') plt.axis([0,70,0,100]) plt.savefig('test.png')
import scipy.integrate import matplotlib.pyplot as plt import numpy time_step=0.05 time_end=70.0 omegaK=0 # contacts of iU with sE omegaU=0 # contacts of iK with sE phi=.2154/4 # rate of education gamma=.0336 # rate of becoming aware of infection #initial starting populations iU0 = 2/21*.69*100 sU0 = 19/21*.75*100 sE0 = 19/21*100*.25 iK0 = 2/21*100*.31 N0 = 100 betaK=0 # contacts of iK with sU betaU=N0*.001 # contacts of iU with sU BR=0.0241 DRiU = .63*.0222 DRsU = .37*.0222 DRsE = .37*.0222 DRiK = .63*.0222 # First, define the function that takes the previous time populations # and returns the new populations def differential_eqs(previous_state,t): sU,sE,iU,iK,N = previous_state # susceptible uneducated sU_new = (-betaK ) * (iK) * (sU) - (betaU) * (iU) * (sU) - phi * sU - (DRsU * sU) +(BR * N * .90) #susceptible educated sE_new = (-omegaK ) * (iK) * (sE) - (omegaU ) * (iU) * (sE) + phi * sU - (DRsE*sE) #infected unknown iU_new = (betaK ) * (iK) * (sU) + (betaU) * (iU) * (sU) - (phi + gamma) * iU - (BR * N * .10) - (DRiU * iU) #infected known iK_new = (omegaK ) * (iK) * (sE) + (omegaU ) * (iU) * (sE) + (phi + gamma) * iU + (2*(BR *N * .10)) - DRiK *iK # total pop N_new = iK + iU + sE + sU #print sU + sE + iU + iK #print N_new return sU_new, sE_new, iU_new, iK_new, N_new # Now solve the differential equations to get the actual populations start_populations = (sU0, sE0, iU0, iK0, N0) time_range=[0.0..time_end, step=time_step] populations = scipy.integrate.odeint(differential_eqs,start_populations,time_range) # Extract the data for each group of people susceptible_U = populations[:,0] # first column susceptible_E = populations[:,1] # second column infected_U = populations[:,2] # third column infected_K = populations[:,3] #fourth column total_pop = populations[:,4] susceptible = susceptible_U + susceptible_E infected = infected_U + infected_K percent_s = susceptible/total_pop*100 percent_i = infected/total_pop*100 #Plot the results plt.figure() plt.plot(percent_s,percent_i) plt.title('Percent SI phase portrait') plt.xlabel('Percent Susceptible (educated and uneducated)') plt.ylabel('Percent Infected (know and unknown)') plt.axis([0,100,0,100]) plt.savefig('test.png')
import scipy.integrate import matplotlib.pyplot as plt import numpy time_step=0.05 time_end=70.0 omegaK=0 # contacts of iU with sE omegaU=0 # contacts of iK with sE phi=.2154/4 # rate of education gamma=.0336 # rate of becoming aware of infection #initial starting populations iU0 = 2/21*.69*100 sU0 = 19/21*.75*100 sE0 = 19/21*100*.25 iK0 = 2/21*100*.31 N0 = 100 betaK=0 # contacts of iK with sU betaU=N0*.001 # contacts of iU with sU BR=0.0241 DRiU = .63*.0222 DRsU = .37*.0222 DRsE = .37*.0222 DRiK = .63*.0222 # First, define the function that takes the previous time populations # and returns the new populations def differential_eqs(previous_state,t): sU,sE,iU,iK,N = previous_state # susceptible uneducated sU_new = (-betaK ) * (iK) * (sU) - (betaU) * (iU) * (sU) - phi * sU - (DRsU * sU) +(BR * N * .90) #susceptible educated sE_new = (-omegaK ) * (iK) * (sE) - (omegaU ) * (iU) * (sE) + phi * sU - (DRsE*sE) #infected unknown iU_new = (betaK ) * (iK) * (sU) + (betaU) * (iU) * (sU) - (phi + gamma) * iU - (BR * N * .10) - (DRiU * iU) #infected known iK_new = (omegaK ) * (iK) * (sE) + (omegaU ) * (iU) * (sE) + (phi + gamma) * iU + (2*(BR *N * .10)) - DRiK *iK # total pop N_new = iK + iU + sE + sU #print sU + sE + iU + iK #print N_new return sU_new, sE_new, iU_new, iK_new, N_new # Now solve the differential equations to get the actual populations start_populations = (sU0, sE0, iU0, iK0, N0) time_range=[0.0..time_end, step=time_step] populations = scipy.integrate.odeint(differential_eqs,start_populations,time_range) # Extract the data for each group of people susceptible_U = populations[:,0] # first column susceptible_E = populations[:,1] # second column infected_U = populations[:,2] # third column infected_K = populations[:,3] #fourth column total_pop = populations[:,4] susceptible = susceptible_U + susceptible_E infected = infected_U + infected_K #Plot the results plt.figure() plt.plot(susceptible,infected) plt.title('SI phase portrait') plt.xlabel('Susceptible (educated and uneducated)') plt.ylabel('Infected (know and unknown') plt.axis([0,100,0,250]) plt.savefig('test.png')
import scipy.integrate import matplotlib.pyplot as plt import numpy time_step=0.05 time_end=70.0 omegaK=0 # contacts of iU with sE omegaU=0 # contacts of iK with sE phi=.2154/4 # rate of education gamma=.0336 # rate of becoming aware of infection #initial starting populations iU0 = 2/21*.69*100 sU0 = 19/21*.75*100 sE0 = 19/21*100*.25 iK0 = 2/21*100*.31 N0 = 100 betaK=0 # contacts of iK with sU betaU=N0*.001 # contacts of iU with sU BR=0.0241 DRiU = .63*.0222 DRsU = .37*.0222 DRsE = .37*.0222 DRiK = .63*.0222 # First, define the function that takes the previous time populations # and returns the new populations def differential_eqs(previous_state,t): sU,sE,iU,iK,N = previous_state # susceptible uneducated sU_new = (-betaK ) * (iK) * (sU) - (betaU) * (iU) * (sU) - phi * sU - (DRsU * sU) +(BR * N * .90) #susceptible educated sE_new = (-omegaK ) * (iK) * (sE) - (omegaU ) * (iU) * (sE) + phi * sU - (DRsE*sE) #infected unknown iU_new = (betaK ) * (iK) * (sU) + (betaU) * (iU) * (sU) - (phi + gamma) * iU - (BR * N * .10) - (DRiU * iU) #infected known iK_new = (omegaK ) * (iK) * (sE) + (omegaU ) * (iU) * (sE) + (phi + gamma) * iU + (2*(BR *N * .10)) - DRiK *iK # total pop N_new = iK + iU + sE + sU #print sU + sE + iU + iK #print N_new return sU_new, sE_new, iU_new, iK_new, N_new # Now solve the differential equations to get the actual populations start_populations = (sU0, sE0, iU0, iK0, N0) time_range=[0.0..time_end, step=time_step] populations = scipy.integrate.odeint(differential_eqs,start_populations,time_range) # Extract the data for each group of people susceptible_U = populations[:,0] # first column susceptible_E = populations[:,1] # second column infected_U = populations[:,2] # third column infected_K = populations[:,3] #fourth column total_pop = populations[:,4] educated = infected_K + susceptible_E uneducated = susceptible_U + infected_K percent_educated = educated/total_pop*100 percent_uneducated = uneducated/total_pop*100 #Plot the results plt.figure() plt.plot(percent_educated,percent_uneducated) plt.title('Education phase portrait') plt.xlabel('Educated') plt.ylabel('Uneducated') plt.axis([0,60,0,100]) plt.savefig('test.png')