\n", "✅ **Put Your Name Here**\n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Day {} {}-Class Assignment: A Conceptual Review of Ordinary Differential Equations (ODE) and Compartmental Models\n", "\n", "**Learning Goals:**\n", "* *Students are learning about some computational tool, and Learning about the basics of functional programming in Python and computational tools (i.e., variables and types, functions, simple data structures, strings, lists, tuples)*: Learning how to write a program that uses `odeint` to solve differential equations\n", "* *Students are thinking about modeling as a practice*: Formulating differential equations and reasoning mathematics from the construction of the model\n", "* *Manipulate, analyze, and visualize datasets and use this data to evaluate models (Students are using datasets to verify a model)*: Visualize results of `odeint` solutions\n", "* *Identify salient features of a system that can be codified into a model*: Deciding what parameters to include in the equations and values for those parameters\n", "* *Gain insight into physical, biological, and social systems through the use of computational algorithms and tools*: Physical Sciences (Newton's Law of Cooling, Half-Life), Biological Sciences (Viral Kinetics)\n", "* *Write programs to solve common problems in a variety of disciplines, multidisciplinary content*\n", "* *Be able to take results from a scientific computing problem and present it both verbally and in writing*: Describe the mathematics behind the model they are constructing\n", "* *Have an understanding of basic numerical methods and be able to use them to solve problems*: Learning about compartmental models and ODE solvers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# What is an ODE?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An ODE is a concept from Differential Equations (Calc IV), but we are going to explain in the context of mathematics you have seen before. An ODE, put simply, is a way of describing change. This should sound a lot like a mathematical concept that you have discussed previously, which is **slope**. A differential equation is a mathematical formulation of a slope. Let's look at an example. If I were to show you the following: $$\\frac{dy}{dx} = 2x$$ you may think that you're staring at something that doesn't make a lot of sense. But let's look more closely at this. This is saying that the *change in y with respect to x*, $\\frac{dy}{dx}$, is equal to *twice the value of x*. Can you think of a function that has a slope of $2x$ (think back to rules of taking a derivative!). The answer we are looking for is $y(x) = x^2$. How did we get that? Well, let's walk through the math of taking the derivative:\n", "$$ y = x^2$$\n", "Differential both sides, and don't forget the chain rule for taknig derivatives\n", "$$ dy = 2 x^{2-1} dx$$\n", "Now lets \"divide\" by $dx$ (this is the sort of thing mathematicians hate)\n", "$$ \\frac{dy}{dx} = 2 x $$.\n", "By taking the derivative, we were able to obtain our original equation. We know what you're thinking, this is just a simple example where we knew the answer and we were able to work backwards. And sure, that very well may be true, so let's be a little more purposeful about this." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, let's define our ODE as a function. One of the many ways that Python functions can be used is as a literal translation between mathematical representations and computational representations. Let's also define what we know our answer will be so that we can do a comparison at the end." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def dydx(x):\n", " return 2*x\n", "\n", "def fx(x):\n", " return x**2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can check to make sure that these two equations describe the same thing by working backwards. We are starting from a description of how a function changes and we want to work backwards. Let's think of this in the context of motion. If we know where we are standing and how we are going to take a step, we can figure out where we are going to next. Another way of saying this is if we can describe how we are walking, we can trace out a path from point to point. We take wherever we are now, add \"a step\" (how far we are going to walk and in which direction), then add that to where we are now. The result will be our new location. The same works for differential equations. We pick where we start (or where we start is given to us). This is what is called an initial condition. For the sake of simplicity, let's assume that we start at the origin. We know how our function changes, or how we are going to take a step mathematically speaking, $\\frac{dy}{dx}$, so, we can use that information to figure out where we will be next. First, we need to describe the path we want to walk. There's an older expression which is, \"Walking is as simple as getting from point $a$ to point $b$\". So, let's define a point $a$ and a point $b$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a = 0\n", "b = 5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are going to start at 0 and take some number of steps to get to 5 distance units. The number of steps determines what kind of solution we are going to get. Let's define $N$ to be how many steps we want to take to cover that distance, and $h$ to be the distance we will cover per step. For now, let's let $N=2$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "N = 2\n", "h = (b-a)/N" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, we are starting at the origin and we are going to take steps. For the sake of relating this to the mathematics, the step occurs in $x$ and $y$, but we know that the change in $y$ is equal to $2x$ from our equation, which we defined a few cells ago. So, to figure out our new values of $x$ and $y$, we will take whatever our position is now, the one we reached at the end of the previous step, and add to it. In $x$, we will just add how big our step is, $h$. But, $y$ changes based on what $x$ is, so we have to add $h \\frac{dy}{dx}$. You may be wondering why we multiply by $h$. You can think of this as $\\frac{dy}{dx}$ tells us where to step, but $h$ tells us how big of a step to take. Let's run this and see the results." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = [0]\n", "y = [0]\n", "\n", "for i in range(N):\n", " xnew = x[-1] + h\n", " ynew = y[-1] + h*dydx(xnew)\n", " y.append(ynew)\n", " x.append(xnew)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.title(\"Solution to dy/dx\")\n", "plt.ylabel(\"f(x)\")\n", "plt.xlabel(\"x\")\n", "plt.plot(x,y, \"go--\", linewidth = 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We broke our path up into two steps, $N=2$. So we see two distinct lines on the graph. But, we showed in the beginning that this should look like $x^2$. But this doesn't look like $x^2$. We can plot the two on top of one another to show the difference." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.title(\"Solution to dy/dx versus known solution\")\n", "plt.ylabel(\"f(x)\")\n", "plt.xlabel(\"x\")\n", "plt.plot(x,y, \"go--\", linewidth = 2)\n", "plt.plot(range(b+1), [fx(i) for i in range(b+1)], \"r-\", linewidth = 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The issue is we took big steps. Let's rerun all of the above code now but with a larger number of steps, $N=10$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a = 0\n", "b = 5\n", "N = 10\n", "h = (b-a)/N\n", "\n", "x = [0]\n", "y = [0]\n", "\n", "for i in range(N):\n", " xnew = x[-1] + h\n", " ynew = y[-1] + h*dydx(xnew)\n", " y.append(ynew)\n", " x.append(xnew)\n", " \n", "plt.title(\"Solution to dy/dx versus known solution\")\n", "plt.ylabel(\"f(x)\")\n", "plt.xlabel(\"x\")\n", "plt.plot(x,y, \"go--\", linewidth = 2)\n", "plt.plot(range(b+1), [fx(i) for i in range(b+1)], \"r-\", linewidth = 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is much closer! If we continue to increase $N$, the solution will continue to get better until we reach a point where increasing $N$ only makes the program run slowly." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a = 0\n", "b = 5\n", "N = 30\n", "h = (b-a)/N\n", "\n", "x = [0]\n", "y = [0]\n", "\n", "for i in range(N):\n", " xnew = x[-1] + h\n", " ynew = y[-1] + h*dydx(xnew)\n", " y.append(ynew)\n", " x.append(xnew)\n", " \n", "plt.title(\"Solution to dy/dx versus known solution\")\n", "plt.ylabel(\"f(x)\")\n", "plt.xlabel(\"x\")\n", "plt.plot(x,y, \"go--\", linewidth = 2)\n", "plt.plot(range(b+1), [fx(i) for i in range(b+1)], \"r-\", linewidth = 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What can we take away from all of this? Differential equations are a way of describing how something changes. Here, we plotted a function and a description of how a function changes, and if we make good choices about how to work backwards, we can show that the two are equivalent. The point here is not to show that we can \"solve\" and ODE (show what the function whose change we have described looks like), but to show that **a differential equation is simply a description of change**. What we choose to do with that description from there is up to us." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How do we formulate these?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The goal is to describe change! When we use ODE's to model a phenomenon, we are forming a descirption of the way in which the system changes, either over time or space, and using that to guide our models. You **will not** be expected to write differential equations on your own from scratch on any exam. This is just meant as an example for how to go about the process and where these differential equations come from. \n", "\n", "The example that we are going to work with here is the [half-life equation](https://en.wikipedia.org/wiki/Half-life). Some of you may have seen this in Chemistry, Physics, or Math classes before. Before we jump into the equation, let's talk about what a half-life is. Some substances are radioactive, this means that their nuclei are unstable, and over time, they will decay into other substances. These substances emit energy in the process in the form of radiation. Not all radioactive substances glow bright green like in the movies though. Most look like normal everyday items. In fact, you may be surprised how many [foods alone are radioactive](https://www.thoughtco.com/common-naturally-radioactive-foods-607456)! When a substance that is radioactive decays, it doesn't waste away or rot. The atoms just turn into other atoms. For instance, [Uranium-238 decays into Lead](https://en.wikipedia.org/wiki/Uranium-238#Radium_series_(or_uranium_series)) over a long period of time. The atoms of one element becoming atoms of another element. **Half-life** is the amount of time it takes **50%** of a substance to radioactively decay.\n", "\n", "So, what does this have to do with differential equations? We can describe how the amount of a substance changes over time by thinking about *change*.\n", "\n", "For every half-life, the amount of material decreases by a factor of 0.5. This seems like a tempting place to start. If we know how many half lives have gone by, then we can figure out how much radioactive material we have left. This is the concept behind [Carbon dating](https://en.wikipedia.org/wiki/Radiocarbon_dating). The problem is, every substance has its own half-life, so we would need to know something about the material before we tried formulating the model, which is not a good thing to rely on, especially in a research context where you will, more than likely, be discovering new ideas, materials, or concepts! \n", "\n", "What we can say is that the *change* in the amount of radioactive material depends on how much we have left. What do we mean by that, well, let's look at the following image." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![graph](https://images.duckduckgo.com/iu/?u=https%3A%2F%2Fd2gne97vdumgn3.cloudfront.net%2Fapi%2Ffile%2Fp3WIICHQtil2nUdHqCKx&f=1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "At $t=0$, we have 100% of our radioactive material left. After one half-life, half of the atoms decay into a new element. So we lose 50% after the first half-life. After the second half-life, the amount remaining drops to 25%, which means we lost 25%. The next half-life, we lose 12.5%. As more of the substance begins to decay over time, less of it *can* decay each half-life. That's to say, whatever amount of material we have now determines how much we can lose after the next half-life. If we are at 50% of the original material, we can't lose 35%. We **have** to lose up to 25%. As more of the substance decays, the **rate at which it decays slows down** (lose a smaller percentage of the total substance each half-life), or the slope becomes less steep and flattens out. The first half-life we lost 50% of the total original material, then 25%, then 12.5%, and if we continued we would lose 6.25%, 3.125%, etc.\n", "\n", "We can write this in mathematical terms! Let's say that we want to show how the amount of radioactive material, $N$, changes with time, $\\frac{dN}{dt}$ (which reads the change in $N$ per change in time). We know that the amount of material is decreasing, so $\\frac{dN}{dt} < 0$, and we know that it depends on how much stuff we have left. In math, we would say that the rate of change of $N$ is inversely (negative, decreasing) proportional to the amount we have left, $\\frac{dN}{dt} \\propto -N$. *BUT* we also mentioned that the half-life depends on the material we are discussing, so while we know that we lose 50% of whatever is left *after each half-life*, we don't know how quickly those losses occur. For some atoms like Carbon-14 have half-lives of 5,730 years while elements like Nitrogen-12 has a half-life of $11\\times10^{-3}$ seconds. So, each material has some constant that describes how quickly these losses occur, or how the substance *changes*. Since we can't know this for every material and may not know it for wahetever we are researching, we put a constant, $k$, in as a placeholder, which captures the dependence on the material. We could have labeled this any variable we wanted, but we chose $k$ for this example. You could call this variable $x$, $q$, $steve$, whatever you want. What's important is that you understand *what it's representing* not how its represented. The final differential equation is $$\\frac{dN}{dt} = -k N$$.\n", "\n", "We did it! We wrote a differential equation and we didn't have to take any Calc IV! Let's review what we did\n", "* We did some research about the model we are using and discussed its behavior (i.e. What is a half-life?; What does it do to the atoms in the material?; etc.)\n", "* We described how the system would change with time (i.e. The amount we can lose depends on how much we have left, so the change in $N$ depends on how much of the original $N$ is left)\n", "* We determined whether the change was an increase or a decrease (Amount of material is decreasing, so there has to be a negative sign)\n", "* We figured out what we didn't know (The rate at which something decays, the constant that we added in to account for differences in materials)\n", "\n", "When you look at differential equations in the future, you should keep this in mind and try and \"read\" the equation to understand what it's saying about the system." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Compartmental Model\n", "\n", "When several ODE's are used to describe a system with multiple interactions, we call it a compartmental model. The name is meant to refer to the fact that there are different states that something in the model can exist in. These states are refered to as compartments. Let's look at an ODE model and discuss it together." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![image](http://www.frontiersin.org/files/Articles/32842/fmicb-03-00319-HTML/image_m/fmicb-03-00319-g001.jpg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Viral Infections\n", "\n", "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. \n", "\n", "We would like to build a model for how viruses infect the cells of our body. We will consider an infection in which our immune system is able to clear the virus (we have all experienced a Michigan winter and know what this is like, getting sick and seemingly never getting over it). \n", "\n", "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 us for. Our bodies, to a virus, are simply a factory for making and spreading more of them. 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. \n", "\n", "What compartments, or states, might we need to build this model? (Look at the picture above.)\n", "* **T**arget cells: These are the healthy cells in our bodies that viruses attack and use to replicate.\n", "* **I**nfected cell: Infected cells are cells that have their normal cellular function suspended to create more of the virus, which may lead to the cell dying.\n", "* **V**irion population: How much of the virus is in our body.\n", "\n", "What parameters will we need?\n", "* The rate at which cells become infected, $\\beta$, which reduces the value of T and increases the value of I.\n", "* The production rate of new virions, $p$, which increases the value of V.\n", "* The rate at which infected cells die, $\\delta$, which decreases the value of I.\n", "* The rate at which the immune systems can clear virions, $r$, which decreases the value of V.\n", "\n", "\n", "### Viral Kinetics (VK) Model\n", "\n", "One of the simple models we could formulate is as follows:\n", "\n", "$$\\frac{dT}{dt} = -\\beta TV,$$ \n", "\n", "$$\\frac{dI}{dt} = \\beta TV - \\delta I,$$ \n", "\n", "$$\\frac{dV}{dt} = pI - rV.$$\n", "\n", "Models like this are called \"viral kinetics\" models, or **VK** for short.\n", "\n", "How did we get these equations? Lets break each one down.\n", "\n", "* $\\frac{dT}{dt} = -\\beta TV$: We know that the number of healthy cells in the body, $T$, gets reduced by the virus as more cells are infected and repurposed to making more of the virus. Since the change in the healthy cells is that they are decreased in number, then the rate of change must be negative. The rate at which that happens is unknown though, so we assign it a constant to account for what we don't know. The rate of change depends on the product of $T$ and $V$ because it depends on how much of both are present. If there are a lot of healthy cells and a very small number of virions, then the infection may spread quickly because there are a lot fo healthy cells for the virus to attack. On the contrary, if there are a lot of virions are almost no healthy cells left, then the speed of the spread of the virus is reduced because there isn't as much more the virus to attack. Since it matters how the virus *and* the healthy cells interact, then we express the rate of change in terms of the product of the two.\n", "\n", "* $\\frac{dI}{dt} = \\beta TV - \\delta I$: Whatever healthy cells get infected by the virus have to become infected cells, so this contains the same term as the above equation, but now positive because we are talking about the infected cells. These cells can die though, so we include a term that describes the rate at which the infected cells die due to loss of normal cellular function. This should look a lot like the half-life example we talked through previously!\n", "\n", "* $\\frac{dV}{dt} = pI - rV$: The infected cells create new virions, so we see there is a term in the equation that describes how the change in the amount of virus in the body is proportional to how many infected cells there are pumping out new virions. The second term is just like the pervious equation and our half-life example.\n", "\n", "Now, we have three equations here, not one equation. That's okay! The only thing that changes is we have two extra lines to include when we define our function. Having more than one equation doesn't change what you do, only how you do it. The steps will still be the same!\n", "\n", "The real question is, how do we model these equations? How do we reach a solution? What is the end result of all of this work?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To solve an ODE model in this course, we will use the `odeint` library. This library solves ODE's using very accurate and powerful algorithms. At this point we will not discuss `odeint`'s algorithms but, rather, use the built-in method as a tool for solving problems. You can always look for more insight into how the function operates.\n", "\n", "Most mathematical libraries follow a simple format: you pass something in and it passes something back to you. A very simple example is `sin(x)`; you send it `x` and it gives you back `sin(x)` using some unknown-to-us algorithm. However, there are libraries that follow a different format because they involve us defining functions. In this case we need to tell Python what that function is before it can help us. In the case of ODE's, we need to somehow give Python our ODE's and then tell `odeint` to solve those. This is handled with `odeint` in the following seven-step process:\n", "1. Express your model in terms of ODE's (changes are equal to gains minus losses with appropriate interactions between compartments or states).\n", "2. Define a function (using `def`) that accepts the current values of the variables and the parameters and computes the derivatives of the ODE model with them.\n", "3. Set up the initial conditions for your ODE model (where are we starting from, how much of the initial \"stuff\" do we have for each compartment).\n", "4. Decide how many steps you would like to take to get the solution (how quickly are we going to step from here to the next point?; How long will the simulation run for?).\n", "5. Define any parameters that appear in your model and give them values (estmates based on assumptions, ideas for researching new behavior, etc.).\n", "6. Call the `odeint` library and pass as arguments the name of your function and initial conditions.\n", "7. Process your results.\n", "\n", "Follow along with the example below to see how to use `odeint` to solve these differential equations." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 1: Express your model in terms of ODE's.\n", "\n", "The comparmental model is given to you, and it has already been converted to ODE's. Use method described in half-life example for how to go about this process." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### STEP 2: Define a function (using `def`) that accepts the current values of the variables and the parameters and computes the derivatives of the ODE model with them." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from scipy.integrate import odeint\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def ODEs(current_values, t):\n", " ##What are the current values of each compartment\n", " target = current_values[0]\n", " infected = current_values[1]\n", " virion = current_values[2]\n", " \n", " ##Calculate the rates of change of each compartment using our mathematical expressions and return\n", " ##Each equation in our model gets its own calculation!\n", " dTdt = -beta*target*virion\n", " dIdt = (beta*target*virion) - (delta*infected)\n", " dVdt = (p*infected) - (r*virion)\n", " return [dTdt, dIdt, dVdt]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### STEP 3: Set up the initial conditions for your ODE model." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "target_0 = 4e8 ##400,000,000 Healthy cells to start\n", "infected_0 = 0.0 ##No Infected Cells\n", "virions_0 = 1.0 ##One virion starts the infection\n", "initial_values = [target_0, infected_0, virions_0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### STEP 4: Decide how many steps you would like to take to get the solution." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "time = np.linspace(0, 10., 1000) ##Simulation takes place over 10 days broken into 1000 intervals, each\n", " ##iteration is 1/100th of a day, or about ~15 minutes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### STEP 5: Define any parameters that appear in your model and give them values." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "beta = 1e-5 ##rate at which healthy cells become infected due to the virus\n", "delta = 7.0 ##rate at which cells die due to loss of cellular function\n", "p = 1e-2 ##rate at which infected cells create a new virion\n", "r = 1 ##rate at which virions are killed by the immune system" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### STEP 6: Call the `odeint` library and pass as arguments the name of your function and initial conditions." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sol = odeint(ODEs, initial_values, time)\n", "T = sol[:, 0]\n", "I = sol[:, 1]\n", "V = sol[:, 2]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### STEP 7: Process your results." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def make_plot(xdata, ydata, style = \"gp-\", \n", " series = \"\", ylabel = \"y\", xlabel = \"Time\"):\n", " plt.figure(figsize = (6,4))\n", " plt.plot(xdata, ydata, style)\n", " plt.title(\"{} of x vs. Time\".format(series))\n", " plt.ylabel(ylabel)\n", " plt.xlabel(xlabel)\n", " plt.grid(True)\n", "make_plot(time, T, series = \"Target Cell Population\", ylabel = \"Target Cell Pop.\", style = \"g-\")\n", "make_plot(time, I, series = \"Infected Cell Population\", ylabel = \"Infected Cell Pop.\", style = \"r-\")\n", "make_plot(time, V, series = \"Virion Population\", ylabel = \"Virion Pop.\", style = \"k-\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Your Turn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have worked through a lot together in this assignment. Now it is your turn. Use the above instruction and examples to help you find a solution to the following problem. Newton's Law of cooling states the following: $$\\frac{dT}{dt} = -k(T - T_{env}).$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Question:** Describe the system that you think this equation is modeling. If you get stuck, it's more than okay to Google this model and do some research. This is how science happens in the real-world!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "✎ Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Question:** Like we did in the half-life example, describe what this equation means in words. A sentence or two should suffice. For example: \"The change in the amount of radioactive material decreases in an amount that depends on the half-life of the material and how much of the material is left. Since we don't know what the half-life of the material is, we put a constant, $k$, in to represent that there's some parameter in our model.\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "✎ Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Do this:** Follow the same steps we did with the Viral Kinetic model to get a solution to this differential equation. You are going to have to pick some parameters and initial conditions. For example, you could try and model how a hot bowl of soup sitting at 90 $^{\\circ C}$ cools off when placed in a cooler, which is at 5 $^{\\circ C}$. Try and choose your length of time and $k$ constant to get a solution that conveys something about the underlying model. You should make a plot of your result to show your solution makes sense and it should look something *like* the following ![cooling](https://images.duckduckgo.com/iu/?u=http%3A%2F%2Flukepoirier.files.wordpress.com%2F2010%2F02%2Fnewton2121.jpg&f=1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "##Put your code here!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python [default]", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.4" } }, "nbformat": 4, "nbformat_minor": 2 }