Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import numpy as np import matplotlib.pyplot as plt import scipy.integrate import scipy.optimize ############## Problem 1 ################ ## Part a # Define x(t) below # Define

image text in transcribed

image text in transcribed

import numpy as np

import matplotlib.pyplot as plt

import scipy.integrate

import scipy.optimize

############## Problem 1 ################

## Part a

# Define x(t) below

# Define x'(t) below. I did this one for you.

xprime = lambda t: 11*(-1/12*np.exp(-t/12) + np.exp(-t))/6

# You need to do something to find the *maximum* using the *minimization*

# algorithms. How can you define a new anonymous function to make this work?

# Hint: you can define one anonymous function from another!

# Example: We use scipy.optimize.fsolve to find zeros of a function. For instance, if

example = lambda t: t*(t-1)

# We know that there are two zeros: one at t=0 and one at t=1. We can find the

# zero at t=1 by choosing a guess close to 1.

# The syntax is scipy.optimize.fsolve(anonymous_function, guess)

example_root = scipy.optimize.fsolve(example, 1)

print('The root near x=1 of our example is = ', example_root) # Note that this

# is an array. To get the answer I have to index.

xprime = lambda t: 5/3*(np.exp(-t/2)-1/12*np.exp(-t/24));

t_max = scipy.optimize.fsolve(xprime, 2)

x = lambda t: 10/3*(np.exp(-t/24)-np.exp(-t/2));

x_max = x(t_max)

A1 = [t_max, x_max]

print (A1)

min_x = lambda t: -10/3*(np.exp(-t/24)-np.exp(-t/2));

t_max = scipy.optimize.fminbound(min_x, 0, 12)

x_max = -min_x(t_max)

A2 = [t_max, x_max]

print (A2)

t = np.linspace(0, 10, 1000)

y = x(t)

plt.plot(t, y)

plt.show()

## Part b

1. A seminal breakthrough in HIV treatment was the use of multiple-drug combination therapy. The idea behind the therapy is that multiple drugs, introduced to the body at specific times, fight the virus off better than one drug alone. A key step in the development of multiple-drug therapy is determining the best time to take the next drug. One way this is done is to take the next drug when the previous drug is at its maximum in the body (and beginning to decrease from there). Drug absorption and elimination in the body is modeled using compartmental models. Consider a model whose solution is given by x(t)=611(et/12et), where x(t) is the amount of the drug in the body at time t. Assume that we want to administer the next drug when x(t) is at its maximum. We call this time tmax in what follows. Recall that we have only talked about minimizing functions so you will have to restate the problem as a minimization problem. (a) Find tmax and the maximum of the function x(t) by taking the derivative (by hand) and using scipy. optimize.fsolve to solve the resulting equation (see an example of how to use this in the Homework 4 template), with an initial guess of x0=1.5, to find the root of x(t). First save x(1.5) to the variable A1 to make sure you have x(t) defined correctly. Then save tmax to the variable A2 and the maximum of x(t) to the variable A3. Note: scipy. optimize.fsolve returns an array, make sure you get the single number out of that array for your answers here. (b) Use scipy.optimize.fminbound with the interval [0,10] to find tmax and the maximum of x(t). Create an array with 2 elements: tmax in the first component and the maximum in the second component. Save this array to the variable A4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions