Exemplo n.º 1
0
def corona(Istart,trans_rate,reco_rate,population,days):
    Sstart=1-Istart
    Rstart=0
    t=np.linspace(1,days,days)
    
    
    def sol(c,t):
        s,i,r=c
        S=-s*i*trans_rate
        I=trans_rate*s*i-reco_rate*i
        R=reco_rate*i
        
        return [S,I,R]
    
   # def new_cases(y,p,d):
   #     y_=np.diff(y,1)*p
   #     y_[y_<0]=0
   #     x_=np.linspace(1,d-1,d-1)
   #     return x_,y_
    
    Sol=od(sol,[Sstart,Istart,Rstart],t)
    
    df=pd.DataFrame({'Days':np.arange(days),'Suspect':Sol[:,0],'Infected':Sol[:,1],'Recovered':Sol[:,2]})
    
    return df
Exemplo n.º 2
0

### Define the two 1st order ODEs from the second order ODE derived on paper.
def derivs(phi, N):  # return derivatives of the array phi
    a = 0.5
    b = -3.0
    c = -6.0
    return np.array([
        phi[1], a * phi[1]**3 + b * phi[1] + (phi[1]**2) / phi[0] + c / phi[0]
    ])


### Provide initial conditions and N-space interval to solve ODE
Nfolds = np.linspace(0.0, 59.0, 10000)
PhiInit = np.array([15.0, 0.0])
phis = od(derivs, PhiInit, Nfolds)

### Plot of the solution in phi from the ODE
plt.figure()
plt.plot(Nfolds, phis[:, 0], 'b-',
         linewidth=0.25)  # phi solution is 1st column of phis
#plt.title(r'A plot of $\phi[N]$ vs. N from $V = \frac{1}{2}m^{2}\phi^{2}$.', y=1.02)
plt.xlabel('No. of e-folds, N', fontsize=12)
plt.ylabel(r'Scalar field, $\phi[N]$ (dimensionless)', fontsize=12)
plt.xlim([0.0, 60.0])
plt.ylim([-1.0, 15.0])
plt.grid('on')
plt.savefig("PhiNPlt.pdf", dpi=2000, bbox_inches='tight')
plt.close()

### Plot of ln(rho) against the no. of e-folds
    a = 0.5
    b = -3.0
    c = 0.5
    d = -3.0
    return np.array([
        phi[1],
        a * phi[1]**3 + b * phi[1] + (c * phi[1]**2) / phi[0] + d / phi[0]
    ])


### Provide initial conditions and N-space interval to solve ODE
Nend = 75.0
Nfolds = np.linspace(0.0, Nend, 50000)
phiStart = 12.173
PhiInit = np.array([phiStart, -1e-5])
phis = od(derivs, PhiInit, Nfolds)
print phis[-1, 0]

### Plot of the solution in phi from the ODE
plt.figure()
plt.plot(Nfolds, phis[:, 0], 'b-',
         linewidth=0.25)  # phi solution is 1st column of phis
plt.title(r'A plot of $\phi[N]$ vs. N from $V = \frac{1}{2}m^{2}\phi^{2}$.',
          y=1.02)
plt.xlabel('No. of e-folds, N', fontsize=12)
plt.ylabel(r'Scalar field, $\phi[N]$ (dimensionless)', fontsize=12)
plt.xlim([0.0, Nend])
plt.ylim([-1.0, phiStart + 1])
plt.grid('on')
plt.savefig("PhiNPlt.pdf", dpi=2000, bbox_inches=0)
plt.close()