{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# BEE 4750 Homework 2: Systems Feedbacks and Stability\n",
        "\n",
        "**Name**:\n",
        "\n",
        "**ID**:\n",
        "\n",
        "> **Due Date**\n",
        ">\n",
        "> Thursday, 09/17/26, 9:00pm\n",
        "\n",
        "## Overview\n",
        "\n",
        "### Instructions\n",
        "\n",
        "- Problem 1 asks you to find the equilibria of several 1-D systems\n",
        "  models and identify their stability.\n",
        "- Problem 2 asks you to draw a systems diagram and identify the type of\n",
        "  a feedback.\n",
        "- Problem 3 asks you to find and analyze the equilibria of a modified\n",
        "  predatory-prey system.\n",
        "- Problem 4 asks you to analyze a lake system experiencing phosphorous\n",
        "  loading, both feedbacks as well as equilibria and stability.\n",
        "\n",
        "### Load Environment\n",
        "\n",
        "The following code loads the environment and makes sure all needed\n",
        "packages are installed. This should be at the start of most Julia\n",
        "scripts."
      ],
      "id": "69702558-2468-454c-b772-3425b684318b"
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {},
      "outputs": [],
      "source": [
        "import Pkg\n",
        "Pkg.activate(@__DIR__)\n",
        "Pkg.instantiate()"
      ],
      "id": "2"
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {},
      "outputs": [],
      "source": [
        "using Plots\n",
        "using LaTeXStrings"
      ],
      "id": "4"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Problems (Total: 50 Points)"
      ],
      "id": "7e8da32f-0f3c-447c-8835-b5cac90392cb"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 1 (9)\n",
        "\n",
        "For each of the following systems models, find (i) any equilibria and\n",
        "(ii) their stabilities."
      ],
      "id": "492d6bf3-c4d6-487e-afe4-aeb9a7a69a67"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#### Problem 1.1 (3)\n",
        "\n",
        "$$\\frac{dx}{dt} = 4x^2 - 16$$"
      ],
      "id": "c3cbea10-0d22-4883-abbc-ffff52825292"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#### Problem 1.2 (3)\n",
        "\n",
        "$$\\frac{dx}{dt} = x - x^3$$"
      ],
      "id": "e4ae225c-e095-4636-bca5-48be60e789ff"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#### Problem 1.3 (3)\n",
        "\n",
        "$$\\frac{dx}{dt} = 1 - 2\\cos x$$"
      ],
      "id": "28c1d3a8-bda3-46a7-ba4d-da36d220b91b"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 2 (9)"
      ],
      "id": "566d868b-a5c9-4513-96bc-d45238051aab"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#### Problem 2.1 (5)\n",
        "\n",
        "Draw a systems diagram for the relationship between global mean\n",
        "temperature, atmospheric CO<sub>2</sub> concentrations, and ocean\n",
        "CO<sub>2</sub> concentrations. What are the signs of the interactions\n",
        "between these components and why? What does this suggest about the\n",
        "overall feedback between temperature and the ocean carbon cycle?\n",
        "\n",
        "> **Tip**\n",
        ">\n",
        "> Think about Henry’s law for CO<sub>2</sub>."
      ],
      "id": "af495dee-c49a-4561-8da8-4bf97d15464c"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#### Problem 2.2 (4)\n",
        "\n",
        "Of the following quantities related to this system, which are stocks and\n",
        "which are flows?\n",
        "\n",
        "1.  The absorbed mass of CO<sub>2</sub> in the ocean.\n",
        "2.  The rate at which CO<sub>2</sub> is absorbed by the ocean from the\n",
        "    atmosphere.\n",
        "3.  The yearly increase in global temperature.\n",
        "4.  The heat stored in the ocean."
      ],
      "id": "a4c6b6d6-2127-4391-99cb-dd5515499c31"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 3 (6)\n",
        "\n",
        "One criticism of the Lotka-Volterra predator-prey equations discussed in\n",
        "class is that the behavior of the system is entirely determined by the\n",
        "initial conditions of the model: a perturbation (like a disease among\n",
        "some of the prey) would permanently change the dynamics of the system\n",
        "and the populations would never recover to their “natural” levels.\n",
        "\n",
        "We can “fix” this by adding another term to the model, a\n",
        "population-dependent death rate which causes populations to recover more\n",
        "rapidly at lower populations and die off more rapidly at larger\n",
        "populations. This would take the following form:\n",
        "\n",
        "$$\\begin{aligned}\n",
        "\\frac{dH}{dt} &= b_h H_t - m_h H_t L_t - \\gamma_H H_t^2 \\\\\n",
        "\\frac{dL}{dt} &= b_L L_t H_t - m_L L_t - \\gamma_L L_t^2 \n",
        "\\end{aligned}$$\n",
        "\n",
        "What are the equilibria of the system (bearing in mind that all of the\n",
        "model parameters must be positive; **hint: you should get three**)? What\n",
        "are the stabilities of any non-trivial $(L_t=H_t=0$) equilibria?\n",
        "Comparing this result to the Lotka-Volterra analysis from class, what\n",
        "can you say about the impact of the population-dependent death term on\n",
        "the behavior of the system?"
      ],
      "id": "31a0ea1d-23c3-4d36-8ad0-ed4c244d4352"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 4 (26)\n",
        "\n",
        "A shallow, temperate, well-mixed lake receiving phosphorus from its\n",
        "catchment. In this lake, phosphorus (P) is the limiting nutrient for\n",
        "algal biomass and whether the lake is oligotrophic or eutrophic.\n",
        "\n",
        "The storage level of P in the sediment is primarily determined by the\n",
        "oxygen (O<sub>2</sub>) in the sediment and is thus related to the level\n",
        "of algal biomass (decomposition of dead algae consumes O<sub>2</sub>). P\n",
        "is also lost from the lake system through outflow and permanent\n",
        "deposition in the sediment."
      ],
      "id": "2fc19c2e-aed5-4b55-b5e3-7ee9c8113ff2"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#### Problem 4.1 (4)\n",
        "\n",
        "Draw a systems diagram for this lake system, capturing the feedback due\n",
        "to the impact of O<sub>2</sub> on sediment P recycling and its mediation\n",
        "by algal biomass. Is this an amplifying or a dampening feedback loop?"
      ],
      "id": "7792f86b-d0da-4847-b43e-8c3fd9e32546"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#### Problem 4.2 (3)\n",
        "\n",
        "Which of the following system quantities are stocks and which are flows?\n",
        "\n",
        "1.  The O<sub>2</sub> demand induced by decomposing biomass.\n",
        "2.  The sediment P pool.\n",
        "3.  The external P loading in a given year"
      ],
      "id": "fd25b18e-2933-4d68-bb81-4f4a60732233"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#### Problem 4.3 (5)\n",
        "\n",
        "The P concentration of the lake is determined by\n",
        "$$\\frac{dP}{dt} = L - sP + R(t),$$ where $P$ is the P concentration\n",
        "($\\mu\\text{g}/\\text{L}$), $L$ is external P loading from runoff\n",
        "($\\mu\\text{g}/(\\text{L} \\cdot \\text{yr})$), $s=1\\ \\text{yr}^{-1}$ is the\n",
        "first-order rate of combined P outflow and permanent deposition, and\n",
        "$R(t)$ ($\\mu\\text{g}/(\\text{L}\\cdot\\text{yr})$ is the sediment release\n",
        "rate at time $t$.\n",
        "\n",
        "Since the amount of algal biomass is limited by the P concentration, the\n",
        "sediment release rate $R$ can be written as a function of P instead of\n",
        "time. This can be thought of as consisting of three regimes: (1) when\n",
        "the lake is fully oligotrophic and sediment is fully oxidized, retaining\n",
        "all P; (2) a transitional regime where increasing algae reduces sediment\n",
        "oxygenation, increasing P recycling; (3) when the sediment is releasing\n",
        "at its maximum capacity due to maximum sediment P and/or the ability of\n",
        "bacteria to decompose biomass, and additional biomass will not increase\n",
        "the rate of recycling. We will assume the maximum recycling rate is\n",
        "$20\\ \\mu\\text{g}/\\text{L}$, and the transitional regime occurs between\n",
        "$25\\ \\mu\\text{g}/\\text{L}$ and $35\\ \\mu\\text{g}/\\text{L}$.\n",
        "\n",
        "Turning this into a piecewise linear model for $R$:\n",
        "$$R(P) = \\begin{cases}\n",
        "    0 & \\quad \\text{if} P \\leq 25\\ \\mu\\text{g}/\\text{L} \\\\\n",
        "    20 \\frac{P - 25}{10} & \\quad \\text{if} 25\\ \\mu \\text{g}/\\text{L} < P < 35\\ \\mu \\text{g}/\\text{L} \\\\\n",
        "    20 & \\quad \\text{if} P \\geq 35\\ \\mu\\text{g}/\\text{L}\n",
        "\\end{cases}.$$"
      ],
      "id": "3ca97dad-1c62-4f9e-9a25-717adf8ad170"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "What are the feedback gain(s) for this model in each sediment recycling\n",
        "regime? What does this implify about how a one-off P increase of\n",
        "$1 \\mu \\text{g}/\\text{L}$ would increase the P level of the lake?"
      ],
      "id": "8eabbd12-173d-4320-bc7f-7bae8551cfe6"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#### Problem 4.4 (6)\n",
        "\n",
        "Find the equilibria of this system assuming external loading of\n",
        "$L=20\\ \\mu\\text{g}/(\\text{L} \\cdot \\text{yr})$. Are they stable or\n",
        "unstable?"
      ],
      "id": "7be4befa-bafb-4174-bc66-1a9f6e5ad05a"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#### Problem 4.5 (8)\n",
        "\n",
        "What are the impacts to the equilibria of the lake if the external\n",
        "loading decreases to $L=10\\ \\mu\\text{g}/(\\text{L} \\cdot \\text{yr})$ or\n",
        "increases to $L=30\\ \\mu\\text{g}/(\\text{L} \\cdot \\text{yr})$? What does\n",
        "this tell you about how the lake could respond to these different levels\n",
        "of loading?"
      ],
      "id": "5bdab998-67ed-4e03-a3d7-034e05905cf9"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## References\n",
        "\n",
        "List any external references consulted, including classmates."
      ],
      "id": "f13cb04b-dad9-4851-b0b7-3e2e8262935a"
    }
  ],
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {
    "kernel_info": {
      "name": "julia"
    },
    "kernelspec": {
      "name": "julia",
      "display_name": "Julia",
      "language": "julia"
    },
    "language_info": {
      "name": "julia",
      "codemirror_mode": "julia",
      "version": "1.11.5"
    }
  }
}