{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Script to support Exercise 2.2.8, modeling yeast population growth.\n", "\n", "#Times at which yeast population was measured\n", "times = [i for i in range(0,18)];" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Yeast population (millions) at each time\n", "data = [9.6, 18.3, 29, 47.2, 71.1, 119.1, 174.6, 257.3, 350.7, 441, 513.3, 559.7, 594.8, 629.4, 640.8, 651.1, 655.9, 659.6];" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Plot the raw data versus time. Call the plot \"plot1\".\n", "pdata = list(zip(times,data))\n", "plt1 = scatter_plot(pdata)\n", "show(plt1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Given that u(0) = 9.6, the solution to the logistic equation with intrinsic growth rate \"r\" and carrying capacity \"K\" is\n", "def u(t,r,K):\n", " return K/(1+exp(-r*t)*(K/9.6-1))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Take a guess r = 1 and K = 600, plot, compare to the data\n", "var('t');\n", "plt2 = plot(u(t,1.0,600.0),(t,0,17),color='red')\n", "pp = plt1+plt2;\n", "pp.axes_labels(['Time (hours)','Population'])\n", "show(pp)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Perhaps we can do better..." ] } ], "metadata": { "kernelspec": { "display_name": "SageMath 9.2", "language": "sage", "name": "sagemath" }, "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.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }