{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "slideshow": { "slide_type": "skip" } }, "outputs": [ ], "source": [ "import numpy as np\n", "import plotly.graph_objects\n", "from IPython.display import display, YouTubeVideo, HTML\n", "#from ipywidgets import interactive_output, VBox, HBox, IntSlider, SelectionSlider\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "slideshow": { "slide_type": "skip" } }, "outputs": [ ], "source": [ "mydefault = plotly.graph_objects.layout.Template()\n", "mydefault.layout.xaxis.showgrid = False\n", "mydefault.layout.yaxis.showgrid = False\n", "mydefault.layout.xaxis.showline = True\n", "mydefault.layout.yaxis.showline = True\n", "mydefault.layout.yaxis.linewidth = 2\n", "mydefault.layout.xaxis.ticks = \"outside\"\n", "mydefault.layout.yaxis.ticks = \"outside\"\n", "mydefault.layout.hovermode = False\n", "mydefault.layout.dragmode = \"pan\"\n", "mydefault.layout.scene.hovermode = False\n", "mydefault.layout.xaxis.showspikes = False\n", "mydefault.layout.yaxis.showspikes = False\n", "mydefault.layout.scene.xaxis.showspikes = False\n", "mydefault.layout.scene.yaxis.showspikes = False\n", "mydefault.layout.scene.zaxis.showspikes = False\n", "plotly.io.templates[\"mydefault\"] = mydefault\n", "plotly.io.templates.default = \"mydefault\"\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": { }, "output_type": "execute_result" } ], "source": [ "%%html\n", "\n", "" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "slideshow": { "slide_type": "skip" } }, "outputs": [ ], "source": [ "def transformation_matrix(M):\n", " columns = []\n", " for evalue, evecs, mult in M.eigenvectors_right():\n", " if evalue.imag() < 0:\n", " continue\n", " if evalue.imag():\n", " for evec in evecs:\n", " u = vector(RDF, [a.real() for a in evec])\n", " v = vector(RDF, [a.imag() for a in evec])\n", " columns.append(u)\n", " columns.append(v)\n", " else:\n", " for v in evecs:\n", " columns.append(vector(RDF, v))\n", " return column_matrix(columns)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "slideshow": { "slide_type": "skip" } }, "outputs": [ ], "source": [ "def make_block_diagonal(M):\n", " dim = M.dimensions()[0]\n", " blocks = []\n", " i = 0\n", " while i < dim:\n", " size = 2 if (i+1 < dim and M[i,i+1] != 0) else 1\n", " blocks.append(M[i:i+size,i:i+size])\n", " i += size\n", " return block_diagonal_matrix(*blocks)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "slideshow": { "slide_type": "skip" } }, "outputs": [ ], "source": [ "def round_complex(z, digits):\n", " if z.imag_part():\n", " return round(z.real_part(), digits) + round(z.imag_part(), digits) * I\n", " return round(z, digits)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "slideshow": { "slide_type": "skip" } }, "outputs": [ ], "source": [ "def latex_vector(v, round=None):\n", " if round is None:\n", " result = column_matrix(v)\n", " else:\n", " result = column_matrix(RDF, v).round(round)\n", " result = latex(result).replace(\"left(\", \"left[\").replace(\"right)\", \"right]\")\n", " return LatexExpr(result)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "slideshow": { "slide_type": "skip" } }, "outputs": [ ], "source": [ "life_stages = LatexExpr(r\"\"\"\\left[ \\begin{array}{c}\n", " \\text{Eggs/hatchlings} \\\\\n", " \\text{Small juveniles} \\\\\n", " \\text{Large juveniles} \\\\\n", " \\text{Subadults} \\\\\n", " \\text{Novice breeders} \\\\\n", " \\text{1st-year remigrants} \\\\\n", " \\text{Mature breeders}\n", "\\end{array} \\right] = \"\"\")\n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false, "slideshow": { "slide_type": "skip" } }, "outputs": [ ], "source": [ "def discrete_linear_interactive(M, initial_state, **options):\n", " max_t = options.get(\"max_t\", 100)\n", " pre_text = options.get(\"pre_text\", \"\")\n", " post_text = options.get(\"post_text\", \"\")\n", " show_distribution = options.get(\"show_distribution\", False)\n", " font_size = options.get(\"font_size\", 18)\n", " fig_height = options.get(\"fig_height\", 250)\n", " solution = [vector(initial_state)]\n", " for t in range(max_t):\n", " solution.append(M * solution[-1])\n", "\n", " fig = plotly.graph_objects.FigureWidget()\n", " fig.layout.xaxis.visible = False\n", " fig.layout.yaxis.visible = False\n", " fig.layout.height = fig_height\n", " fig.layout.margin = dict(b=10, t=10, l=10, r=10)\n", " text = \"${}$\".format(pre_text + latex_vector(solution[0], round=2))\n", " fig.add_annotation(showarrow=False, font_size=font_size, x=0, y=1, \n", " xref=\"paper\", yref=\"paper\", xanchor=\"left\", yanchor=\"top\")\n", " annotation = fig.layout.annotations[-1]\n", "\n", " @interact(t=slider(0, max_t, 1, label=\"$t$\"))\n", " def update(t):\n", " text = pre_text + latex_vector(solution[t], round=2)\n", " if show_distribution:\n", " percentages = 100 * solution[t].normalized(1)\n", " text += r\" \\hspace{6em} \\text{Percentages: } \"\n", " text += latex_vector(percentages, 1)\n", " annotation.text = \"${}$\".format(text + post_text)\n", "\n", " return fig\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**A model of the worldwide population of loggerhead sea turtles**\n", "\n", "From the paper “A stage-based population model for loggerhead sea turtles and implications for conservation”, by Deborah Crouse, Larry Crowder, and Hal Caswell, published in the journal *Ecology*, 1987. \n", "\n", "Seven life stages: \n", "\n", "1. Hatchlings (less than 1 year old)\n", "1. Small juveniles (age 1–7 years)\n", "1. Large juveniles (age 8–15 years)\n", "1. Subadults (age 16–21 years)\n", "1. Novice breeders (age 22 years)\n", "1. First-year remigrants (age 23 years)\n", "1. Mature breeders (age 24–54 years)\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}C = \\left(\\begin{array}{rrrrrrr}\n", "0.0 & 0.0 & 0.0 & 0.0 & 127.0 & 4.0 & 80.0 \\\\\n", "0.6747 & 0.737 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0486 & 0.661 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0147 & 0.6907 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0518 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.8089\n", "\\end{array}\\right)\n", "\\end{math}" ], "text/plain": [ "C = \\left(\\begin{array}{rrrrrrr}\n", "0.0 & 0.0 & 0.0 & 0.0 & 127.0 & 4.0 & 80.0 \\\\\n", "0.6747 & 0.737 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0486 & 0.661 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0147 & 0.6907 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0518 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.8089\n", "\\end{array}\\right)" ] }, "execution_count": 10, "metadata": { }, "output_type": "execute_result" } ], "source": [ "C = matrix(RDF, [\n", " [0, 0, 0, 0, 127, 4, 80 ],\n", " [0.6747, 0.7370, 0, 0, 0, 0, 0 ],\n", " [0, 0.0486, 0.6610, 0, 0, 0, 0 ],\n", " [0, 0, 0.0147, 0.6907, 0, 0, 0 ],\n", " [0, 0, 0, 0.0518, 0, 0, 0 ],\n", " [0, 0, 0, 0, 0.8091, 0, 0 ],\n", " [0, 0, 0, 0, 0, 0.8091, 0.8089],\n", "])\n", "show(r\"C = \" + latex(C))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\text{Eigenvalues of $C$:}\n", "\\end{math}" ], "text/plain": [ "\\text{Eigenvalues of $C$:}" ] }, "execution_count": 11, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}-0.0884 + 0.1196i\n", "\\end{math}" ], "text/plain": [ "-0.0884 + 0.1196*I" ] }, "execution_count": 11, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}-0.0884 - 0.1196i\n", "\\end{math}" ], "text/plain": [ "-0.0884 - 0.1196*I" ] }, "execution_count": 11, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.2655\n", "\\end{math}" ], "text/plain": [ "0.2655" ] }, "execution_count": 11, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.3717\n", "\\end{math}" ], "text/plain": [ "0.3717" ] }, "execution_count": 11, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.7462 + 0.2131i\n", "\\end{math}" ], "text/plain": [ "0.7462 + 0.2131*I" ] }, "execution_count": 11, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.7462 - 0.2131i\n", "\\end{math}" ], "text/plain": [ "0.7462 - 0.2131*I" ] }, "execution_count": 11, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.945\n", "\\end{math}" ], "text/plain": [ "0.945" ] }, "execution_count": 11, "metadata": { }, "output_type": "execute_result" } ], "source": [ "show(LatexExpr(r\"\\text{Eigenvalues of $C$:}\"))\n", "for evalue in C.eigenvalues():\n", " show(round_complex(evalue, 4))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}T = \\left(\\begin{array}{rrrrrrr}\n", "-0.7768 & 0.0 & -0.57 & -0.471 & -0.0127 & -0.2951 & 0.2908 \\\\\n", "0.6219 & 0.0901 & 0.8155 & 0.8699 & -0.9345 & 0.0 & 0.943 \\\\\n", "-0.0384 & -0.012 & -0.1002 & -0.1461 & -0.0735 & 0.1838 & 0.1614 \\\\\n", "0.0007 & 0.0003 & 0.0035 & 0.0067 & 0.0106 & 0.0078 & 0.0093 \\\\\n", "-0.0 & -0.0003 & 0.0007 & 0.0009 & 0.0008 & 0.0003 & 0.0005 \\\\\n", "-0.001 & 0.001 & 0.0021 & 0.002 & 0.0009 & 0.0001 & 0.0004 \\\\\n", "0.001 & -0.0008 & -0.0031 & -0.0038 & -0.0007 & -0.0033 & 0.0026\n", "\\end{array}\\right)\n", "\\end{math}" ], "text/plain": [ "T = \\left(\\begin{array}{rrrrrrr}\n", "-0.7768 & 0.0 & -0.57 & -0.471 & -0.0127 & -0.2951 & 0.2908 \\\\\n", "0.6219 & 0.0901 & 0.8155 & 0.8699 & -0.9345 & 0.0 & 0.943 \\\\\n", "-0.0384 & -0.012 & -0.1002 & -0.1461 & -0.0735 & 0.1838 & 0.1614 \\\\\n", "0.0007 & 0.0003 & 0.0035 & 0.0067 & 0.0106 & 0.0078 & 0.0093 \\\\\n", "-0.0 & -0.0003 & 0.0007 & 0.0009 & 0.0008 & 0.0003 & 0.0005 \\\\\n", "-0.001 & 0.001 & 0.0021 & 0.002 & 0.0009 & 0.0001 & 0.0004 \\\\\n", "0.001 & -0.0008 & -0.0031 & -0.0038 & -0.0007 & -0.0033 & 0.0026\n", "\\end{array}\\right)" ] }, "execution_count": 12, "metadata": { }, "output_type": "execute_result" } ], "source": [ "T = transformation_matrix(C)\n", "show(r\"T = \" + latex(T.round(4)))" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false, "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\tilde{D} = \\left(\\begin{array}{rrrrrrr}\n", "-0.0884 & 0.1196 & -0.0 & 0.0 & 0.0 & -0.0 & 0.0 \\\\\n", "-0.1196 & -0.0884 & -0.0 & -0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.2655 & -0.0 & -0.0 & 0.0 & 0.0 \\\\\n", "-0.0 & -0.0 & 0.0 & 0.3717 & 0.0 & -0.0 & -0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.7462 & 0.2131 & 0.0 \\\\\n", "0.0 & -0.0 & 0.0 & -0.0 & -0.2131 & 0.7462 & -0.0 \\\\\n", "-0.0 & 0.0 & -0.0 & 0.0 & 0.0 & -0.0 & 0.945\n", "\\end{array}\\right)\n", "\\end{math}" ], "text/plain": [ "\\tilde{D} = \\left(\\begin{array}{rrrrrrr}\n", "-0.0884 & 0.1196 & -0.0 & 0.0 & 0.0 & -0.0 & 0.0 \\\\\n", "-0.1196 & -0.0884 & -0.0 & -0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.2655 & -0.0 & -0.0 & 0.0 & 0.0 \\\\\n", "-0.0 & -0.0 & 0.0 & 0.3717 & 0.0 & -0.0 & -0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.7462 & 0.2131 & 0.0 \\\\\n", "0.0 & -0.0 & 0.0 & -0.0 & -0.2131 & 0.7462 & -0.0 \\\\\n", "-0.0 & 0.0 & -0.0 & 0.0 & 0.0 & -0.0 & 0.945\n", "\\end{array}\\right)" ] }, "execution_count": 13, "metadata": { }, "output_type": "execute_result" } ], "source": [ "D = T.inverse()*C*T\n", "show(r\"\\tilde{D} = \" + latex(D.round(4)))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\tilde{D} = \\left(\\begin{array}{rr|r|r|rr|r}\n", "-0.0884 & 0.1196 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "-0.1196 & -0.0884 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.2655 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.3717 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.0 & 0.7462 & 0.2131 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & -0.2131 & 0.7462 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.945\n", "\\end{array}\\right)\n", "\\end{math}" ], "text/plain": [ "\\tilde{D} = \\left(\\begin{array}{rr|r|r|rr|r}\n", "-0.0884 & 0.1196 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "-0.1196 & -0.0884 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.2655 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.3717 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.0 & 0.7462 & 0.2131 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & -0.2131 & 0.7462 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.945\n", "\\end{array}\\right)" ] }, "execution_count": 14, "metadata": { }, "output_type": "execute_result" } ], "source": [ "show(r\"\\tilde{D} = \" + latex(make_block_diagonal(D.round(4))))" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\text{The absolute values of the eigenvalues:}\n", "\\end{math}" ], "text/plain": [ "\\text{The absolute values of the eigenvalues:}" ] }, "execution_count": 15, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| -0.0884 + 0.1196i | = 0.1488\n", "\\end{math}" ], "text/plain": [ "| -0.0884 + 0.1196i | = 0.1488" ] }, "execution_count": 15, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| -0.0884 - 0.1196i | = 0.1488\n", "\\end{math}" ], "text/plain": [ "| -0.0884 - 0.1196i | = 0.1488" ] }, "execution_count": 15, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.2655\n", "\\end{math}" ], "text/plain": [ "0.2655" ] }, "execution_count": 15, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.3717\n", "\\end{math}" ], "text/plain": [ "0.3717" ] }, "execution_count": 15, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| 0.7462 + 0.2131i | = 0.776\n", "\\end{math}" ], "text/plain": [ "| 0.7462 + 0.2131i | = 0.776" ] }, "execution_count": 15, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| 0.7462 - 0.2131i | = 0.776\n", "\\end{math}" ], "text/plain": [ "| 0.7462 - 0.2131i | = 0.776" ] }, "execution_count": 15, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.945\n", "\\end{math}" ], "text/plain": [ "0.945" ] }, "execution_count": 15, "metadata": { }, "output_type": "execute_result" } ], "source": [ "show(LatexExpr(r\"\\text{The absolute values of the eigenvalues:}\"))\n", "for evalue in C.eigenvalues():\n", " if evalue.imag() or evalue < 0:\n", " show(r\"|\" + latex(round_complex(evalue, 4)) + r\"| = \" + latex(round(abs(evalue), 4)))\n", " else:\n", " show(round(abs(evalue), 4))" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5010982595fe43efb678f81e642df50e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Interactive function .update at 0x7f208e921040> with 1 widget\n", " …" ] }, "execution_count": 16, "metadata": { }, "output_type": "execute_result" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "713c0708960d4899b13fad8314e60e79", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FigureWidget({\n", " 'data': [],\n", " 'layout': {'annotations': [{'font': {'size': 18},\n", " …" ] }, "execution_count": 16, "metadata": { }, "output_type": "execute_result" } ], "source": [ "state = vector([100.0] * 7)\n", "discrete_linear_interactive(C, state, pre_text=life_stages)\n" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "85713cba591548d799f935037bc278a7", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Interactive function .update at 0x7f208e921dc0> with 1 widget\n", " …" ] }, "execution_count": 17, "metadata": { }, "output_type": "execute_result" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7889e1b04c384ab8a1b8a7b735075a56", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FigureWidget({\n", " 'data': [],\n", " 'layout': {'annotations': [{'font': {'size': 18},\n", " …" ] }, "execution_count": 17, "metadata": { }, "output_type": "execute_result" } ], "source": [ "state = vector([100.0] * 7)\n", "discrete_linear_interactive(C, state, pre_text=life_stages, show_distribution=True)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**Protecting eggs, nests, and baby sea turtles**\n", "\n", "
\n", "\"A\n", "
Bald Head Island, NC
August, 2016
\n", "
\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**Protecting eggs, nests, and baby sea turtles**\n", "\n", "
\n", "\"Guide\n", "
Bald Head Island, NC
August, 2016
\n", "
\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**Protecting eggs, nests, and baby sea turtles**\n", "\n", "
\n", "\"Excavating\n", "
Bald Head Island, NC
August, 2016
\n", "
\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**Protecting eggs, nests, and baby sea turtles**\n", "\n", "
\n", "\"Unhatched\n", "
Bald Head Island, NC
August, 2016
\n", "
\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**Protecting eggs, nests, and baby sea turtles**\n", "\n", "
\n", "\"A\n", "
Bald Head Island, NC
August, 2016
\n", "
\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**Protecting eggs, nests, and baby sea turtles**\n", "\n", "
\n", "\"A\n", "
Bald Head Island, NC
August, 2016
\n", "
\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**What if we do everything we can to protect eggs, nests, and baby sea turtles?**\n", "\n", "(And what if that's all we do?) \n" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}C_2 = \\left(\\begin{array}{rrrrrrr}\n", "0.0 & 0.0 & 0.0 & 0.0 & 150.0 & 6.0 & 100.0 \\\\\n", "0.6747 & 0.737 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0486 & 0.661 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0147 & 0.6907 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0518 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.8089\n", "\\end{array}\\right)\n", "\\end{math}" ], "text/plain": [ "C_2 = \\left(\\begin{array}{rrrrrrr}\n", "0.0 & 0.0 & 0.0 & 0.0 & 150.0 & 6.0 & 100.0 \\\\\n", "0.6747 & 0.737 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0486 & 0.661 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0147 & 0.6907 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0518 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.8089\n", "\\end{array}\\right)" ] }, "execution_count": 18, "metadata": { }, "output_type": "execute_result" } ], "source": [ "C2 = matrix(RDF, [\n", " [0, 0, 0, 0, 150, 6, 100 ],\n", " [0.6747, 0.7370, 0, 0, 0, 0, 0 ],\n", " [0, 0.0486, 0.6610, 0, 0, 0, 0 ],\n", " [0, 0, 0.0147, 0.6907, 0, 0, 0 ],\n", " [0, 0, 0, 0.0518, 0, 0, 0 ],\n", " [0, 0, 0, 0, 0.8091, 0, 0 ],\n", " [0, 0, 0, 0, 0, 0.8091, 0.8089],\n", "])\n", "show(r\"C_2 = \" + latex(C2))" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**The difference between this matrix, $C_2$, and the original one, $C$:**" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false, "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}C_2 - C = \\left(\\begin{array}{rrrrrrr}\n", "0.0 & 0.0 & 0.0 & 0.0 & 23.0 & 2.0 & 20.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\n", "\\end{array}\\right)\n", "\\end{math}" ], "text/plain": [ "C_2 - C = \\left(\\begin{array}{rrrrrrr}\n", "0.0 & 0.0 & 0.0 & 0.0 & 23.0 & 2.0 & 20.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\n", "\\end{array}\\right)" ] }, "execution_count": 19, "metadata": { }, "output_type": "execute_result" } ], "source": [ "show(r\"C_2 - C = \" + latex(C2 - C))" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\text{Eigenvalues of $C_2$:}\n", "\\end{math}" ], "text/plain": [ "\\text{Eigenvalues of $C_2$:}" ] }, "execution_count": 20, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}-0.09492 + 0.12621i\n", "\\end{math}" ], "text/plain": [ "-0.09492 + 0.12621*I" ] }, "execution_count": 20, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}-0.09492 - 0.12621i\n", "\\end{math}" ], "text/plain": [ "-0.09492 - 0.12621*I" ] }, "execution_count": 20, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.3165 + 0.07173i\n", "\\end{math}" ], "text/plain": [ "0.3165 + 0.07173*I" ] }, "execution_count": 20, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.3165 - 0.07173i\n", "\\end{math}" ], "text/plain": [ "0.3165 - 0.07173*I" ] }, "execution_count": 20, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.7495 + 0.22485i\n", "\\end{math}" ], "text/plain": [ "0.7495 + 0.22485*I" ] }, "execution_count": 20, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.7495 - 0.22485i\n", "\\end{math}" ], "text/plain": [ "0.7495 - 0.22485*I" ] }, "execution_count": 20, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.95545\n", "\\end{math}" ], "text/plain": [ "0.95545" ] }, "execution_count": 20, "metadata": { }, "output_type": "execute_result" } ], "source": [ "show(LatexExpr(r\"\\text{Eigenvalues of $C_2$:}\"))\n", "for evalue in C2.eigenvalues():\n", " show(round_complex(evalue, 5))" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\tilde{D}_2 = \\left(\\begin{array}{rr|rr|rr|r}\n", "-0.09492 & 0.12621 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "-0.12621 & -0.09492 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.3165 & 0.07173 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & -0.07173 & 0.3165 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.0 & 0.7495 & 0.22485 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & -0.22485 & 0.7495 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.95545\n", "\\end{array}\\right)\n", "\\end{math}" ], "text/plain": [ "\\tilde{D}_2 = \\left(\\begin{array}{rr|rr|rr|r}\n", "-0.09492 & 0.12621 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "-0.12621 & -0.09492 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.3165 & 0.07173 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & -0.07173 & 0.3165 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.0 & 0.7495 & 0.22485 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & -0.22485 & 0.7495 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.95545\n", "\\end{array}\\right)" ] }, "execution_count": 21, "metadata": { }, "output_type": "execute_result" } ], "source": [ "T2 = transformation_matrix(C2)\n", "D2 = T2.inverse()*C2*T2\n", "show(r\"\\tilde{D}_2 = \" + latex(make_block_diagonal(D2.round(5))))" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\text{The absolute values of the eigenvalues:}\n", "\\end{math}" ], "text/plain": [ "\\text{The absolute values of the eigenvalues:}" ] }, "execution_count": 22, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| -0.0949 + 0.1262i | = 0.1579\n", "\\end{math}" ], "text/plain": [ "| -0.0949 + 0.1262i | = 0.1579" ] }, "execution_count": 22, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| -0.0949 - 0.1262i | = 0.1579\n", "\\end{math}" ], "text/plain": [ "| -0.0949 - 0.1262i | = 0.1579" ] }, "execution_count": 22, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| 0.3165 + 0.0717i | = 0.3245\n", "\\end{math}" ], "text/plain": [ "| 0.3165 + 0.0717i | = 0.3245" ] }, "execution_count": 22, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| 0.3165 - 0.0717i | = 0.3245\n", "\\end{math}" ], "text/plain": [ "| 0.3165 - 0.0717i | = 0.3245" ] }, "execution_count": 22, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| 0.7495 + 0.2249i | = 0.7825\n", "\\end{math}" ], "text/plain": [ "| 0.7495 + 0.2249i | = 0.7825" ] }, "execution_count": 22, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| 0.7495 - 0.2249i | = 0.7825\n", "\\end{math}" ], "text/plain": [ "| 0.7495 - 0.2249i | = 0.7825" ] }, "execution_count": 22, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.9554\n", "\\end{math}" ], "text/plain": [ "0.9554" ] }, "execution_count": 22, "metadata": { }, "output_type": "execute_result" } ], "source": [ "show(LatexExpr(r\"\\text{The absolute values of the eigenvalues:}\"))\n", "for evalue in C2.eigenvalues():\n", " if evalue.imag() or evalue < 0:\n", " show(r\"|\" + latex(round_complex(evalue, 4)) + r\"| = \" + latex(round(abs(evalue), 4)))\n", " else:\n", " show(round(abs(evalue), 4))" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5a1d8ee394da4ec5aa079e97c1ce9de7", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Interactive function .update at 0x7f2091aaca60> with 1 widget\n", " …" ] }, "execution_count": 23, "metadata": { }, "output_type": "execute_result" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d024671e55824ae1a49de318bc115a90", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FigureWidget({\n", " 'data': [],\n", " 'layout': {'annotations': [{'font': {'size': 18},\n", " …" ] }, "execution_count": 23, "metadata": { }, "output_type": "execute_result" } ], "source": [ "state = vector([100.0] * 7)\n", "discrete_linear_interactive(C2, state, pre_text=life_stages)\n" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "38bcf6f50a464ece8d78950b8111b06c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Interactive function .update at 0x7f208e90cf70> with 1 widget\n", " …" ] }, "execution_count": 24, "metadata": { }, "output_type": "execute_result" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c451177b2bb54d8dbb0aed7f88b6c57e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FigureWidget({\n", " 'data': [],\n", " 'layout': {'annotations': [{'font': {'size': 18},\n", " …" ] }, "execution_count": 24, "metadata": { }, "output_type": "execute_result" } ], "source": [ "state = vector([100.0] * 7)\n", "discrete_linear_interactive(C2, state, pre_text=life_stages, show_distribution=True)\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "# That didn't work. ☹\n", "\n", "
\n", "
\n", "\n", "**Conclusion, so far:** Protecting eggs, nests, hatchlings ***isn't enough*** by itself. \n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**What if, instead, we protect the juvenile turtles, and especially the older juveniles?**\n" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}C_3 = \\left(\\begin{array}{rrrrrrr}\n", "0.0 & 0.0 & 0.0 & 0.0 & 127.0 & 4.0 & 80.0 \\\\\n", "0.6747 & 0.747 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0531 & 0.7597 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0403 & 0.7289 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.071 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.8089\n", "\\end{array}\\right)\n", "\\end{math}" ], "text/plain": [ "C_3 = \\left(\\begin{array}{rrrrrrr}\n", "0.0 & 0.0 & 0.0 & 0.0 & 127.0 & 4.0 & 80.0 \\\\\n", "0.6747 & 0.747 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0531 & 0.7597 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0403 & 0.7289 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.071 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.8091 & 0.8089\n", "\\end{array}\\right)" ] }, "execution_count": 25, "metadata": { }, "output_type": "execute_result" } ], "source": [ "C3 = matrix(RDF, [\n", " [0, 0, 0, 0, 127, 4, 80 ],\n", " [0.6747, 0.7470, 0, 0, 0, 0, 0 ],\n", " [0, 0.0531, 0.7597, 0, 0, 0, 0 ],\n", " [0, 0, 0.0403, 0.7289, 0, 0, 0 ],\n", " [0, 0, 0, 0.0710, 0, 0, 0 ],\n", " [0, 0, 0, 0, 0.8091, 0, 0 ],\n", " [0, 0, 0, 0, 0, 0.8091, 0.8089],\n", "])\n", "show(r\"C_3 = \" + latex(C3))" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**The difference between this third matrix, $C_3$, and the original one, $C$:**" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false, "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}C_3 - C = \\left(\\begin{array}{rrrrrrr}\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.01 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0045 & 0.0987 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0256 & 0.0382 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0192 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\n", "\\end{array}\\right)\n", "\\end{math}" ], "text/plain": [ "C_3 - C = \\left(\\begin{array}{rrrrrrr}\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.01 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0045 & 0.0987 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0256 & 0.0382 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0192 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\n", "\\end{array}\\right)" ] }, "execution_count": 26, "metadata": { }, "output_type": "execute_result" } ], "source": [ "show(r\"C_3 - C = \" + latex((C3 - C).round(5)))" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\text{Eigenvalues of $C_3$:}\n", "\\end{math}" ], "text/plain": [ "\\text{Eigenvalues of $C_3$:}" ] }, "execution_count": 27, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}-0.13101 + 0.16979i\n", "\\end{math}" ], "text/plain": [ "-0.13101 + 0.16979*I" ] }, "execution_count": 27, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}-0.13101 - 0.16979i\n", "\\end{math}" ], "text/plain": [ "-0.13101 - 0.16979*I" ] }, "execution_count": 27, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}1.05704\n", "\\end{math}" ], "text/plain": [ "1.05704" ] }, "execution_count": 27, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.79315 + 0.2994i\n", "\\end{math}" ], "text/plain": [ "0.79315 + 0.2994*I" ] }, "execution_count": 27, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.79315 - 0.2994i\n", "\\end{math}" ], "text/plain": [ "0.79315 - 0.2994*I" ] }, "execution_count": 27, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.33159 + 0.18977i\n", "\\end{math}" ], "text/plain": [ "0.33159 + 0.18977*I" ] }, "execution_count": 27, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}0.33159 - 0.18977i\n", "\\end{math}" ], "text/plain": [ "0.33159 - 0.18977*I" ] }, "execution_count": 27, "metadata": { }, "output_type": "execute_result" } ], "source": [ "show(LatexExpr(r\"\\text{Eigenvalues of $C_3$:}\"))\n", "for evalue in C3.eigenvalues():\n", " show(round_complex(evalue, 5))" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\tilde{D}_3 = \\left(\\begin{array}{rr|r|rr|rr}\n", "-0.13101 & 0.16979 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "-0.16979 & -0.13101 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 1.05704 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.79315 & 0.2994 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & -0.2994 & 0.79315 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.33159 & 0.18977 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & -0.18977 & 0.33159\n", "\\end{array}\\right)\n", "\\end{math}" ], "text/plain": [ "\\tilde{D}_3 = \\left(\\begin{array}{rr|r|rr|rr}\n", "-0.13101 & 0.16979 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "-0.16979 & -0.13101 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 1.05704 & 0.0 & 0.0 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.79315 & 0.2994 & 0.0 & 0.0 \\\\\n", "0.0 & 0.0 & 0.0 & -0.2994 & 0.79315 & 0.0 & 0.0 \\\\\n", "\\hline\n", " 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.33159 & 0.18977 \\\\\n", "0.0 & 0.0 & 0.0 & 0.0 & 0.0 & -0.18977 & 0.33159\n", "\\end{array}\\right)" ] }, "execution_count": 28, "metadata": { }, "output_type": "execute_result" } ], "source": [ "T3 = transformation_matrix(C3)\n", "D3 = T3.inverse()*C3*T3\n", "show(r\"\\tilde{D}_3 = \" + latex(make_block_diagonal(D3.round(5))))" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\text{The absolute values of the eigenvalues:}\n", "\\end{math}" ], "text/plain": [ "\\text{The absolute values of the eigenvalues:}" ] }, "execution_count": 29, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| -0.131 + 0.1698i | = 0.2145\n", "\\end{math}" ], "text/plain": [ "| -0.131 + 0.1698i | = 0.2145" ] }, "execution_count": 29, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| -0.131 - 0.1698i | = 0.2145\n", "\\end{math}" ], "text/plain": [ "| -0.131 - 0.1698i | = 0.2145" ] }, "execution_count": 29, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}1.057\n", "\\end{math}" ], "text/plain": [ "1.057" ] }, "execution_count": 29, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| 0.7931 + 0.2994i | = 0.8478\n", "\\end{math}" ], "text/plain": [ "| 0.7931 + 0.2994i | = 0.8478" ] }, "execution_count": 29, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| 0.7931 - 0.2994i | = 0.8478\n", "\\end{math}" ], "text/plain": [ "| 0.7931 - 0.2994i | = 0.8478" ] }, "execution_count": 29, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| 0.3316 + 0.1898i | = 0.3821\n", "\\end{math}" ], "text/plain": [ "| 0.3316 + 0.1898i | = 0.3821" ] }, "execution_count": 29, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ], "text/latex": [ "\\begin{math}\n", "\\newcommand{\\Bold}[1]{\\mathbf{#1}}| 0.3316 - 0.1898i | = 0.3821\n", "\\end{math}" ], "text/plain": [ "| 0.3316 - 0.1898i | = 0.3821" ] }, "execution_count": 29, "metadata": { }, "output_type": "execute_result" } ], "source": [ "show(LatexExpr(r\"\\text{The absolute values of the eigenvalues:}\"))\n", "for evalue in C3.eigenvalues():\n", " if evalue.imag() or evalue < 0:\n", " show(r\"|\" + latex(round_complex(evalue, 4)) + r\"| = \" + latex(round(abs(evalue), 4)))\n", " else:\n", " show(round(abs(evalue), 4))" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "14b5a079cdc24c719212aa270cb87fd6", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Interactive function .update at 0x7f208e8890d0> with 1 widget\n", " …" ] }, "execution_count": 30, "metadata": { }, "output_type": "execute_result" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "70d3a9bb9af2483790bd5aa239809351", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FigureWidget({\n", " 'data': [],\n", " 'layout': {'annotations': [{'font': {'size': 18},\n", " …" ] }, "execution_count": 30, "metadata": { }, "output_type": "execute_result" } ], "source": [ "state = vector([100.0] * 7)\n", "discrete_linear_interactive(C3, state, pre_text=life_stages)\n" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8026b59a5fd94beaa17af5f3a1915ba7", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Interactive function .update at 0x7f208e889430> with 1 widget\n", " …" ] }, "execution_count": 31, "metadata": { }, "output_type": "execute_result" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6a3a694f0b6b4658b2cc71ea86e60872", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FigureWidget({\n", " 'data': [],\n", " 'layout': {'annotations': [{'font': {'size': 18},\n", " …" ] }, "execution_count": 31, "metadata": { }, "output_type": "execute_result" } ], "source": [ "state = vector([100.0] * 7)\n", "discrete_linear_interactive(C3, state, pre_text=life_stages, show_distribution=True)\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "# Success! ☺\n", "\n", "
\n", "
\n", "\n", "**New conclusion:** We must protect juveniles, and especially larger juveniles. \n" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "image/jpeg": "9fa9a3d0c9d017fe160a0bd94d13345a878180e9", "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 32, "metadata": { }, "output_type": "execute_result" } ], "source": [ "display(YouTubeVideo(\"hIJvSymWsCc\", start=62))" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "image/jpeg": "5424fa0b6f7e9fc778e1d8a2fff21ceed93c0c9a", "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 33, "metadata": { }, "output_type": "execute_result" } ], "source": [ "display(YouTubeVideo(\"y71cgxmyMO4\", start=246))" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "**The happy ending to this story:**\n", "\n", "This paper was published in 1987. That same year, the U.S. Congress passed a law requiring all shrimp trawling boats in the U.S. to use nets equipped with a *turtle excluder device* (TED). \n", "\n", "A few years later, an international treaty was signed, requiring shrimp fishers from most other developed nations to use TEDs on their nets. The U.S. also passed, with support from the World Trade Organization, a trade embargo that prohibits the import of shrimp from countries that do not require TEDs. \n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "slideshow": { "slide_type": "slide" } }, "source": [ "While loggerhead sea turtles are still considered a threatened species, the populations in the southeastern U.S. have recovered significantly since the 1980s. \n", "\n", "***In short:*** **This math paper has helped to save the loggerhead sea turtles!** " ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "collapsed": false }, "outputs": [ ], "source": [ ] } ], "metadata": { "celltoolbar": "Slideshow", "hide_input": false, "kernelspec": { "display_name": "SageMath 9.2", "language": "sagemath", "metadata": { "cocalc": { "description": "Open-source mathematical software system", "priority": 1, "url": "https://www.sagemath.org/" } }, "name": "sage-9.2", "resource_dir": "/ext/jupyter/kernels/sage-9.2" }, "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.3" } }, "nbformat": 4, "nbformat_minor": 4 }