Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON HELP! See example code! I am not even sure where to begin so any step is helpful! Posting the full problem and example this

PYTHON HELP! See example code! I am not even sure where to begin so any step is helpful! Posting the full problem and example this time!

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

EXAMPLE CODE FOR REFERENCE:

image text in transcribed

image text in transcribed

THANK YOU

Viral infections are one the main causes of disease in humans. Along with bacteria and parasite infections, viral infections are caused by the introduction of a microscopic organism" into our bodies. Sometimes these viruses live in our bodies throughout our lifetime with little damage, sometimes, they quickly kill us. We would like to build a model for how viruses infected the cells of our body. We will consider an infection in which our immune system is able to clear the virus. Since winter is coming, consider this to be the influenza virus. How do viruses work? We need to understand a bit about this in order to build our model. The most important feature is that viruses cannot reproduce on their own - that is what they need you for. Your body, to a virus, is simply a factory for making and spreading more of them. If virions were writing the history books, humans would simply be their maternity ward. The way this works is that virions enter your cells, where there is a factory at work to keep the cell functioning, and they give all of the factory workers new instructions. A factory that was making cars, once the virions enter, is now making laptops, or, in this case, rather than keeping the cell alive and healthy, the machinery of the cells makes more virions. For every virion that enters a cellthat cell might make hundreds of new virions, leading to a population explosion. Your body will need to quickly mount an immune response to keep this under control. What compartments might we need? (Look at the picture above.) . Target cells; these are the healthy cells the virion might enter Infected cell; these cells produce new virions, and might die over time Virion population, the number of virions at any given time during the infection What parameters will we need? rate at which cells become infected: this reduces the value of T and increases the value of the production rate of new virions, which increases the value of V . rate at which infected cells die rate at which virions degrade and leave the system Viral Kinetics (VK) Model A simple model is then: =-BTV, di = BTV - 81, di = pl - V. Time to write some code! dr Using this template, fill in your code below for the VK model given above. Here it is again, so that you don't need to keep scrolling up and down: =-BTV, dt = BTV - 81, =pl - rv. Step 1: Setting up the ODES The comparmental model is given to you, and it has already been converted to ODEs in the form odeint wants (see the equations above), you just need to complete the remaining steps. Step 2: Define the derivatives function [ ]: # STEP 2: define the function that contains the derivatives def derivscy, t, beta, delta, p, r): # unpack List of incoming variables # use variables to compute derivatives on the right-hand-side of the above equations # example: dTdt = # return the derivatives in a List by changing the "pass" to "return" along with the correct List pass In [ ]: # STEP 3: define the initial conditions target_e = 4e8 infected_0 = 0.0 virions_0 = 1.0 # Here we put them all into a list so that they can be passed to odeint yo = [target_o, infected_e, virions_@] Step 4: Define interval over which we want a solution Think about how long you run to run your model for and choose a time range. In [ ]: # STEP 4: add time array here Step 5: Define the parameters of the model Again, since you might not have a good sense for what some reasonable choices might be, we've provided some as a starting point for your exploration. In [ ]: # STEP 5: define model parameters here beta = le-5 delta = 4.0 p = le-2 r = 1 Step 6: Call odeint to get a solution. ]: # STEP 6: pass everything to odeint, store the solution, and unpack it # into a useful set of Lists/arrays for Later use # Make sure to pass _all_ of the model parameters from Step 5 as a tuple to "args" Step 7: Visualize Results Make a quad plot, using subplot, that contains: target cell population versus time viral load versus time infected cell population versus time . a 3D plot of V versus T and I Make sure to have everything labeled, titled, grids and legends as appropriate. ]: # STEP 7: use the results for something; here, plot the solutions # This initializes a figure object fig = plt.figure(figsize=(15,8)) # Make sure to call this last. This command resizes the spaces between your plots to try to avoid overlap. pit.tight_layout() IMPORTANT IMPORT COMMANDS import matplotlib.pyplot as plt From mpl_toolkits.mplot3d import Axes 3D import numpy as np matplotlib inline Note that the Scipy Library is needed for odeint From scipy.integrate import odeint **# CODE FOR ODE SOLUTION FOR NON-LINEAR OSCILLATOR STEP 2: define your ODE system of equations def deriv_funciy, t, freq): # unpack List coming in that contains current values position = y[@] velocity = y[1] # the right-hand-side of the ODE system of equations deriv_1 = velocity deriv_2 = -freq*82 * np.sin(position) # send back the derivatives return [deriv_1, deriv_2] STEP 3: setup wp the initial conditions # STEP 3: setup up the entral conditions X_0 = 3.0 # initial position V_0 = 0.5 # initial velocity yo = [x_@, v_0] # initial condition, in a List # STEP 4: define time steps to use time_grid = np.linspace(e, 18., 1990) # time grid # STEP 5: define the parameters of your model frequency = 4.0 # we make it a global variable # STEP 6: solve the equations and access the solution solve the Odes (finally!) by giving odeint the derivative function, initial # conditions and the grid over which we want a solution solution = odeint(deriv_func, yo, time_grid, args=(frequency,)) # note the syntax of this call to odeint, especially the "args" # unpack the solution into its parts pos = solution[:, ] # what does this slicing mean? vel = solution[:, 1] # STEP 7: process your results (here, into visualization) # Let's see what we got! so much suspense! plt. subplot(211) plt.plot(time_grid, pos, label='position') plt.plot(time_grid, vel, label='velocity') plt.grid) plt.xlabel('time') plt.ylabel('position & velocity') plt.title('Numerical Solution of the Non-linear Oscillator Equations) plt.legend(loc='best') # plot the solution in phase space, which means plotting the variables versus # each other rather than versus time plt.subplot(212) plt.plot(pos,vel) plt.grid() plt.ylabel('velocity') plt.xlabel('position') plt.title('Non-Linear Oscillator in Phase Space') plt. tight_layout) Viral infections are one the main causes of disease in humans. Along with bacteria and parasite infections, viral infections are caused by the introduction of a microscopic organism" into our bodies. Sometimes these viruses live in our bodies throughout our lifetime with little damage, sometimes, they quickly kill us. We would like to build a model for how viruses infected the cells of our body. We will consider an infection in which our immune system is able to clear the virus. Since winter is coming, consider this to be the influenza virus. How do viruses work? We need to understand a bit about this in order to build our model. The most important feature is that viruses cannot reproduce on their own - that is what they need you for. Your body, to a virus, is simply a factory for making and spreading more of them. If virions were writing the history books, humans would simply be their maternity ward. The way this works is that virions enter your cells, where there is a factory at work to keep the cell functioning, and they give all of the factory workers new instructions. A factory that was making cars, once the virions enter, is now making laptops, or, in this case, rather than keeping the cell alive and healthy, the machinery of the cells makes more virions. For every virion that enters a cellthat cell might make hundreds of new virions, leading to a population explosion. Your body will need to quickly mount an immune response to keep this under control. What compartments might we need? (Look at the picture above.) . Target cells; these are the healthy cells the virion might enter Infected cell; these cells produce new virions, and might die over time Virion population, the number of virions at any given time during the infection What parameters will we need? rate at which cells become infected: this reduces the value of T and increases the value of the production rate of new virions, which increases the value of V . rate at which infected cells die rate at which virions degrade and leave the system Viral Kinetics (VK) Model A simple model is then: =-BTV, di = BTV - 81, di = pl - V. Time to write some code! dr Using this template, fill in your code below for the VK model given above. Here it is again, so that you don't need to keep scrolling up and down: =-BTV, dt = BTV - 81, =pl - rv. Step 1: Setting up the ODES The comparmental model is given to you, and it has already been converted to ODEs in the form odeint wants (see the equations above), you just need to complete the remaining steps. Step 2: Define the derivatives function [ ]: # STEP 2: define the function that contains the derivatives def derivscy, t, beta, delta, p, r): # unpack List of incoming variables # use variables to compute derivatives on the right-hand-side of the above equations # example: dTdt = # return the derivatives in a List by changing the "pass" to "return" along with the correct List pass In [ ]: # STEP 3: define the initial conditions target_e = 4e8 infected_0 = 0.0 virions_0 = 1.0 # Here we put them all into a list so that they can be passed to odeint yo = [target_o, infected_e, virions_@] Step 4: Define interval over which we want a solution Think about how long you run to run your model for and choose a time range. In [ ]: # STEP 4: add time array here Step 5: Define the parameters of the model Again, since you might not have a good sense for what some reasonable choices might be, we've provided some as a starting point for your exploration. In [ ]: # STEP 5: define model parameters here beta = le-5 delta = 4.0 p = le-2 r = 1 Step 6: Call odeint to get a solution. ]: # STEP 6: pass everything to odeint, store the solution, and unpack it # into a useful set of Lists/arrays for Later use # Make sure to pass _all_ of the model parameters from Step 5 as a tuple to "args" Step 7: Visualize Results Make a quad plot, using subplot, that contains: target cell population versus time viral load versus time infected cell population versus time . a 3D plot of V versus T and I Make sure to have everything labeled, titled, grids and legends as appropriate. ]: # STEP 7: use the results for something; here, plot the solutions # This initializes a figure object fig = plt.figure(figsize=(15,8)) # Make sure to call this last. This command resizes the spaces between your plots to try to avoid overlap. pit.tight_layout() IMPORTANT IMPORT COMMANDS import matplotlib.pyplot as plt From mpl_toolkits.mplot3d import Axes 3D import numpy as np matplotlib inline Note that the Scipy Library is needed for odeint From scipy.integrate import odeint **# CODE FOR ODE SOLUTION FOR NON-LINEAR OSCILLATOR STEP 2: define your ODE system of equations def deriv_funciy, t, freq): # unpack List coming in that contains current values position = y[@] velocity = y[1] # the right-hand-side of the ODE system of equations deriv_1 = velocity deriv_2 = -freq*82 * np.sin(position) # send back the derivatives return [deriv_1, deriv_2] STEP 3: setup wp the initial conditions # STEP 3: setup up the entral conditions X_0 = 3.0 # initial position V_0 = 0.5 # initial velocity yo = [x_@, v_0] # initial condition, in a List # STEP 4: define time steps to use time_grid = np.linspace(e, 18., 1990) # time grid # STEP 5: define the parameters of your model frequency = 4.0 # we make it a global variable # STEP 6: solve the equations and access the solution solve the Odes (finally!) by giving odeint the derivative function, initial # conditions and the grid over which we want a solution solution = odeint(deriv_func, yo, time_grid, args=(frequency,)) # note the syntax of this call to odeint, especially the "args" # unpack the solution into its parts pos = solution[:, ] # what does this slicing mean? vel = solution[:, 1] # STEP 7: process your results (here, into visualization) # Let's see what we got! so much suspense! plt. subplot(211) plt.plot(time_grid, pos, label='position') plt.plot(time_grid, vel, label='velocity') plt.grid) plt.xlabel('time') plt.ylabel('position & velocity') plt.title('Numerical Solution of the Non-linear Oscillator Equations) plt.legend(loc='best') # plot the solution in phase space, which means plotting the variables versus # each other rather than versus time plt.subplot(212) plt.plot(pos,vel) plt.grid() plt.ylabel('velocity') plt.xlabel('position') plt.title('Non-Linear Oscillator in Phase Space') plt. tight_layout)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions