Hello everyone, I hope y'all are well.
I have an urgent task that must do in 8 hours from now.
This task needs an expert with mathematics related to differential equations and coding in python for a simple problem.
I attracted task as an image.
https://drive.google.com/open?id=13aH4pF...GYSrgyowEj
I prefer this code format.
I have an urgent task that must do in 8 hours from now.
This task needs an expert with mathematics related to differential equations and coding in python for a simple problem.
I attracted task as an image.
https://drive.google.com/open?id=13aH4pF...GYSrgyowEj
I prefer this code format.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint def microbes(phi, kappa, mu, L = 1024 , Nx = 1024 ,Nt = 1201 ,T = 600 ,display = False ): """ Question 2.2 Simulate microbe competition model Input: phi,kappa,mu: model parameters Nx: Number of grid points in x Nt: Number of time steps T: Timespan for simulation is [0,T] Display: Function creates contour plot of f when true Output: f,g: Nt x Nx arrays containing solution """ #generate grid L = 1024 x = np.linspace( 0 ,L,Nx) dx = x[ 1 ] - x[ 0 ] dx2inv = 1 / dx * * 2 def RHS(y, t, k, r, phi, dx2inv): n = y.size / / 2 f = y[:n] g = y[:n] #Compute 2nd derivatives d2f = (f[ 2 :] - 2 * f[ 1 : - 1 ] + f[: - 2 ]) * dx2inv d2g = (g[ 2 :] - 2 * g[ 1 : - 1 ] + g[: - 2 ]) * dx2inv #Construct RHS R = f / (f + phi) dfdt = d2f + f[ 1 : - 1 ] * ( 1 - f[ 1 : - 1 ]) - R[ 1 : - 1 ] * g[ 1 : - 1 ] dgdt = d2g - r * k * g[ 1 : - 1 ] + k * R[ 1 : - 1 ] * g[ 1 : - 1 ] dy = np.zeros( 2 * n) dy[ 1 :n - 1 ] = dfdt dy[n + 1 : - 1 ] = dgdt #Enforce boundary conditions a1,a2 = - 4 / 3 , - 1 / 3 dy[ 0 ] = a1 * dy[ 1 ] + a2 * dy[ 2 ] dy[n - 1 ] = a1 * dy[n - 2 ] + a2 * dy[n - 3 ] dy[n] = a1 * dy[n + 1 ] + a2 * dy[n + 2 ] dy[ - 1 ] = a1 * dy[ - 2 ] + a2 * dy[ - 3 ] return dy rho = mu / kappa F = rho * phi / ( 1 - rho) G = ( 1 - F) * (F + phi) y0 = np.zeros( 2 * Nx) #initialize signal y0[:Nx] = F y0[Nx:] = G + 0.01 * np.cos( 10 * np.pi / L * x) + 0.01 * np.cos( 20 * np.pi / L * x) t = np.linspace( 0 ,T,Nt) #compute solution print ( "running simulation..." ) y = odeint(RHS,y0,t,args = (kappa,rho,phi,dx2inv),rtol = 1e - 6 ,atol = 1e - 6 ) f = y[:,:Nx] g = y[:,Nx:] print ( "finished simulation" ) if display: plt.figure() plt.contour(x,t,f) plt.xlabel( 'x' ) plt.ylabel( 't' ) plt.title( 'Contours of f' ) return f,g def newdiff(f,h): """ Question 2.1 i) Input: f: array whose 2nd derivative will be computed h: grid spacing Output: d2f: second derivative of f computed with compact fd scheme """ d2f = np.zeros_like(f) #modify as needed #Coefficients for compact fd scheme alpha = 9 / 38 a = ( 696 - 1191 * alpha) / 428 b = ( 2454 * alpha - 294 ) / 535 c = ( 1179 * alpha - 344 ) / 2140 return d2f #modify as needed def analyzefd(): """ Question 2.1 ii) Add input/output as needed """ return None #modify as needed def dynamics(): """ Question 2.2 Add input/output as needed """ return None #modify as needed if __name__ = = '__main__' : x = None #Add code here to call functions above and #generate figures you are submitting |