Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Urgent] build code
#1
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.

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
Reply
#2
Is there someone who could solve this task?
I really need this, urgent task, if you do this, it is really fantastic.
Please help me if you are python and mathematic expert.
Reply
#3
Couple issues. We don't do your homework, rather can help you sort out errors.
Second, your code is hard to decipher as it is "unpythonic". Properly designed python program use variable names that are descriptive.
Couple obvious things - your first function is called with a lot of parameters but returns nothing, despite the comments. You also accept L as a parameter with a default value of 1024, but you then ignore that and just assign L the value of 1024. No matter, it does not get passed back anyway.
Line 78 is a return that is not inside a function. That will cause an error.

So, what have you done with the code, what errors are you getting?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation Python Homework (Urgent help needed!!) chickenseizuresalad 6 4,296 Oct-11-2021, 01:59 AM
Last Post: Underscore
Exclamation urgent , Python homework alm 2 2,313 May-09-2021, 11:19 AM
Last Post: Yoriz
  urgent I got a syntax errors alm 2 5,877 Feb-28-2021, 02:54 PM
Last Post: alm
Heart Urgent homework help needed Medou 4 2,733 Nov-24-2020, 09:28 AM
Last Post: buran
  Bifid Genkey (Urgent) Laura123 2 2,054 Mar-09-2020, 08:09 PM
Last Post: micseydel
  Python Homework Help *Urgent GS31 2 2,589 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Need help! Please! Urgent! foxylen 1 2,300 Feb-27-2019, 05:50 PM
Last Post: buran
  (Not urgent) IDLE issue with methods vinfer12 5 3,964 Mar-22-2018, 09:00 PM
Last Post: Gribouillis
  Machine Learning Antivirus [Urgent] Echoo0o 4 4,901 Jul-28-2017, 01:57 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020