\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{color}

%\usepackage[textheight=8.5in, margin=1.6in]{geometry}
\usepackage[total={6in,8in}]{geometry}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
%\tikzstyle{ball} = [circle,shading=ball, ball color=black,
%    minimum size=1mm,inner sep=1.3pt]
%\usetikzlibrary{arrows.meta}
%\tikzset{>={Latex[length=2mm,width=1.5mm]}}

%\usepackage{graphicx}

\usepackage{enumitem}
\setlist[enumerate]{leftmargin=*}

\usepackage[colorlinks=true,citecolor=black,linkcolor=black,urlcolor=blue]{hyperref}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\sn}{\mathfrak{S}}
\newcommand{\ve}{\varepsilon}
\newcommand{\ips}[2]{\langle{#1}, {#2}\rangle}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\Span}{\mathrm{Span}}
\DeclareMathOperator{\rk}{\mathrm{rank}}
\DeclareMathOperator{\trace}{\mathrm{tr}}
\DeclareMathOperator{\im}{\mathrm{im}}
\DeclareMathOperator{\Sym}{\mathrm{Sym}}
\DeclareMathOperator{\Hom}{\mathrm{Hom}}
\DeclareMathOperator{\diag}{\mathrm{diag}}
\DeclareMathOperator{\glb}{\mathrm{glb}}
\DeclareMathOperator{\lub}{\mathrm{lub}}

\parskip = 0.05in
\parindent = 0.0in

%\pagestyle{empty}

\begin{document}
\centerline{Math 322 lecture for Wednesday, Week 1}
\bigskip

\allowdisplaybreaks
{\sc 1.~A. Separable equations.}
\bigskip

{\bf Logistic growth model.}  Let~$P(t)$ be the size of a population at
time~$t$, and let~$r$ and~$K$ be positive constants.  The logistic growth model is the differential equation
\[
  P'(t) = rP(t)\left( 1-\frac{P(t)}{K} \right).
\]
The constant~$r$ is the \emph{growth rate} and $K$ is the \emph{carrying
capacity} of the population.  The differential equation says the growth in
population is proportional to the size of the existing population with an extra
factor to account for limited resources.  When the population is small (when~$P$
is much smaller then~$K$), we see~$P'\approx rP$, which we've already seen leads
to exponential growth.  However, as~$P$ gets close to~$K$ over time, the
factor~$1-P/K$ slows the growth.

{\em Solution.} The equation is separable and can be solved using integration using the
technique of partial fractions.
\[
  P'(t) = rP(t)\left( 1-\frac{P(t)}{K} \right) \quad\Rightarrow\quad
  \frac{P'(t)}{P(t)\left(1-\frac{P(t)}{K}\right)}=r.
\]
The technique of partial fractions requires us to find constants~$A$
and~$B$ such that
\begin{equation}
 \frac{1}{P(t)\left(1-\frac{P(t)}{K}\right)}=\frac{A}{P(t)}+\frac{B}{1-\frac{P(t)}{K}}.
  \label{eqn1}
\end{equation}
We have
\begin{equation}
  \frac{A}{P(t)}+\frac{B(t)}{1-\frac{P(t)}{K}}=\frac{A\left(1-\frac{P(t)}{K}\right)+BP(t)}{P(t)\left(1-\frac{P(t)}{K}\right)}.
  \label{eqn2}
\end{equation}
Comparing numerators in equations~\eqref{eqn1} and~$\eqref{eqn2}$, we need to adjust~$A$ and~$B$ so that
\[
  1 = A\left(1-\frac{P(t)}{K}\right)+BP(t).
\]
Or, rearranging:
\[
  1 = A + \left( -\frac{A}{K}+B \right)P(t).
\]
We get an equality if
\[
  A = 1\quad\text{and}\quad -\frac{A}{K}+B=0.
\]
So~$A=1$ and~$B=1/K$.  Therefore, we can write (double-check!):
\begin{equation}
 \frac{1}{P(t)\left(1-\frac{P(t)}{K}\right)}=\frac{1}{P(t)}+\frac{1/K}{1-\frac{P(t)}{K}}.
 \label{eqn3}
\end{equation}
Back to solving the differential equation:
\begin{align*}
  \frac{P'(t)}{P(t)\left(1-\frac{P(t)}{K}\right)}=r
  & \quad\Rightarrow\quad
  \int
  \frac{dP}{P\left(1-\frac{P}{K}\right)}=\int r\,dt\\[10pt]
  & \quad\Rightarrow\quad
  \int
  \frac{dP}{P(t)\left(1-\frac{P}{K}\right)}=rt+\text{constant}.
\end{align*}
For the left-hand side, use equation~\eqref{eqn3}:
\allowdisplaybreaks
\begin{align*}
  \int\frac{dP}{P(t)\left(1-\frac{P}{K}\right)}\,dt
  &= \int\left( \frac{1}{P(t)}+\frac{1/K}{1-\frac{P(t)}{K}}\right)dP\\[10pt]
  &= \int \frac{dP}{P(t)}+\frac{1}{K}\int\frac{dP}{1-\frac{P(t)}{K}}\\[10pt]
  &= \ln P(t)-\ln\left( 1-\frac{P(t)}{K} \right)+\text{constant}.
\end{align*}
Here, we have assumed that~$0<P<K$ (how?).
Exponentiate both sides to get
\[
  P(t) \left( 1-\frac{P(t)}{K}\right)^{-1}=ae^{rt}
\]
for some positive constant~$a$. We now need to solve this equation
for~$P(t)$:
\begin{align*}
 ae^{rt}
 &= P(t) \left( 1-\frac{P(t)}{K}\right)^{-1}= \frac{KP(t)}{K-P(t)}\\[10pt]
 &\Rightarrow ae^{rt}(K-P(t))=KP(t)\\[10pt]
 &\Rightarrow aKe^{rt}=ae^{rt}P(t)+KP(t)=(ae^{rt}+K)P(t)\\[10pt]
 &\Rightarrow P(t)=\frac{aKe^{rt}}{ae^{rt}+K}\\[10pt]
 &\Rightarrow P(t)=\frac{aK}{a+Ke^{-rt}}.
\end{align*}
We would like to express the arbitrary constant~$a$ in terms of the initial
population:
\begin{align*}
  &P(0)=\frac{aKe^{0}}{ae^{0}+K}=\frac{aK}{a+K}\\[10pt]
  &\Rightarrow P(0)(a+K)=aK\\[10pt]
  &\Rightarrow P(0)K=aK-P(0)a=a(K-P(0))\\[10pt]
  &a =\frac{P(0)K}{K-P(0)}.
\end{align*}
Substituting this expression for~$a$ and simplifying gives the final form for the
solution
\[
  \fbox{$\displaystyle
  P(t)=\frac{P(0)K}{P(0)+(K-P(0))e^{-rt}}$.\rule[-7mm]{0mm}{15mm}}
\]
({\bf Exercise:} How would things change if~$P>K$?)
It's easy to see from this equation that the limiting population is
\[
  \lim_{t\to\infty}P(t)=K.
\]
\begin{center}
\begin{tikzpicture}
  \begin{axis}[ 
      title style={at={(0.5,0)},anchor=north,yshift=-30},
      title={\mbox{\parbox{\textwidth}{Graph of~$P(t)$ with~$K=1000$ and~$P(0)=10$ and two different
      growth rates:~$r=0.5$ in red and~$r=0.2$ in blue.}}},
      axis lines = middle,
      axis line style={->},
      %axis equal image,
      %xmin=-0.2,
      %xmax=5,
      %ymin=-0.2,
      ymax=1100,
    ]
    %\fill[blue] (axis cs: 1,1) circle (2pt);  
    %\fill[draw=black,fill=white] (axis cs:1,0) circle (2pt);  
    \addplot[domain=0:50,thick, samples=100,blue] {(10000/(10+(1000-10)*exp(-0.2*x)))};
    \addplot[domain=0:50,thick, samples=100,red] {(10000/(10+(1000-10)*exp(-0.5*x)))};
    \draw[dashed,thick,orange] (axis cs:0,1000)--(axis cs:50,1000);
    \node at (axis cs:18,800) {$r=0.5$};
    \node at (axis cs:32,600) {$r=0.2$};
  \end{axis}
\end{tikzpicture}
\end{center}
\medskip

{\bf Exercise.} A state game commission releases~$40$ elk into a
  game refuge.  After~$5$ years, the elk population is~$104$.  The commission
  believes that the refuge can support no more than~$4000$ elk.  Use a logistic
  model to predict the elk population in~$15$ years.
\medskip

{\sc solution:} The carrying capacity is~$K=4000$, so the logistic model in this situation is
\[
  P'(t) = rP(t)\left( 1-\frac{P(t)}{4000} \right)
\]
where we can determine~$r$ from the additional information we're given.  The
initial population size is~$P(0)=40$.  From the solution to the logistic
equation we derived above, we have
\begin{align*}
  P(t) 
  &= \frac{4000P(0)}{P(0)+(4000-P(0))e^{-rt}}\\[8pt]
  &= \frac{160000}{40+3960e^{-rt}}\\[8pt]
  &= \frac{4000}{1+99e^{-rt}}\\[8pt]
\end{align*}
We are given that~$P(5)=104$.  Therefore,
\[
  104=P(5)=\frac{4000}{1+99e^{-5r}}.
\]
Solve for~$r$:
\begin{align*}
  104=\frac{4000}{1+99e^{-5r}}
  &\quad\Rightarrow\quad
  104(1+99e^{-5r})=4000\\[8pt]
  &\quad\Rightarrow\quad
  e^{-5r}=\frac{1}{99}\left(\frac{4000}{104}-1\right)=\frac{487}{1287}\\[8pt]
  &\quad\Rightarrow\quad
  -5r=\ln\left( \frac{487}{1287} \right)\\[8pt]
  &\quad\Rightarrow\quad
  r \approx 0.194.
\end{align*}
So our model for this population is
\[
  P(t) = \frac{4000}{1+99e^{-0.194\,t}}
\]
So we would predict the population after~$15$ years to be
\[
  P(15) = \frac{4000}{1+99e^{-0.194\cdot 15}}\approx 626.
\]
\bigskip

{\sc 1.~B. Separable---homogeneity trick.} 

An equation of the form
\[
  y'= F\left(\frac{y}{t}\right)
\]
can be turned into a separable equation using the following substitution:
let~$v=y/t$.  It follows that~$y=vt$, and thus,~$y'=v+tv'$ by the product rule.
Then,
\begin{align*}
  y'= F\left(\frac{y}{t}\right)
  &\quad\Rightarrow\quad v+tv'=F(v)\\
  &\quad\Rightarrow\quad \frac{v'}{F(v)-v}=\frac{1}{t}\\
  &\quad\Rightarrow\quad \int\frac{dv}{F(v)-v}=\int\frac{dt}{t}.
\end{align*}

{\bf Example.} Solve 
\[
  y'=\frac{y^2+2yt}{t^2}.
\]
Notice that in the fraction on the right, the degree of every term in the numerator and
denominator is~$2$.  That's a sign of homogeneity.  In fact, we have
\[
  \frac{y^2+2yt}{t^2}=\frac{y^2}{t^2}+\frac{2yt}{t^2}=\left(
  \frac{y}{t} \right)^2+2\left( \frac{y}{t} \right).
\]
Substitute~$v=y/t$ and~$y'=v+tv'$ to transform the original equation into:
\[
  v+tv'=v^2+2v.
\]
Separate variables and integrate.  For convenience, we will assume that
~$y>0$ and~$t>0$, and hence~$v>0$.  Other cases can be handled similarly:
\[
  \frac{v'}{v^2+v} =\frac{1}{t}
  \quad\Rightarrow\quad \int\frac{dv}{v^2+v}=\int\frac{dt}{t}.
\]
To integrate the left-hand side, use partial fractions:
\begin{align*}
  \int\frac{dv}{v^2+v}=\int\frac{dv}{v(v+1)}
  &= \int\left(\frac{1}{v}-\frac{1}{v+1}\right)\,dv\\[8pt]
  &= \ln(v)-\ln(v+1)+\tilde{c}\\[8pt]
  &= \ln\left(\frac{v}{v+1}\right)+\tilde{c}.
\end{align*}
We have found that
\[
  \ln\left( \frac{v}{v+1} \right)=\ln(t)+c.
\]
Exponentiate and solve for~$v$:
\begin{align*}
  \frac{v}{v+1}=at.
  &\quad\Rightarrow\quad v=\frac{at}{1-at}.
\end{align*}
Since~$v=y/t$, we get
\[
  y = \frac{at^2}{1-at}.
\]
Considering an initial condition at~$t=0$ doesn't make much sense (why?).  Let's
write our solution in terms of an initial condition~$I=y(1)$:
\[
  I=y(1)=\frac{a}{1-a}\quad\Rightarrow\quad a=\frac{I}{1+I}.
\]
Substituting gives
\[
  y = \frac{I\,t^2}{I+1-It}.
\]
For instance, if~$I=1$, we get the solution
\[
  y=\frac{t^2}{2-t},
\]
which is defined on the open interval~$(-\infty,2)$, however, recall that at
some point along the way, we assumed~$t>0$.   And, in fact, our original
equation is undefined at~$t=0$.  So the appropriate interval for this solution
is~$(0,2)$:
\begin{center}
\begin{tikzpicture}
  \begin{axis}[ 
      scale=1.0,
      title style={at={(0.5,0)},anchor=north,yshift=-30},
      title={Solution to~$y'=(y^2+yt)/t^2$ with~$y(1)=1$.},
      axis lines = middle,
      axis line style={->},
      %axis equal image,
      xmin=-0.2,
      xmax=2.3,
      ymin=-0.2,
      ymax=5,
    ]
    %\fill[blue] (axis cs: 1,1) circle (2pt);  
    %\fill[draw=black,fill=white] (axis cs:1,0) circle (2pt);  
    \addplot[domain=0.01:1.99,samples=100,thick, blue] {x*x/(2-x)};
  \end{axis}
\end{tikzpicture}
\end{center}
Here is the Sage code for solving this equation:
\begin{verbatim}
sage: t = var('t')
sage: y = function('y')(t)
sage: desolve(diff(y,t)-(y^2+2*y*t)/t^2,y)
-(t^2 + t*y(t))/y(t) &=  _C
sage: desolve(diff(y,t)-(y^2+2*y*t)/t^2,y,ics=[1,1])
-(t^2 + t*y(t))/y(t) &=  -2
\end{verbatim}
For the second call to desolve, I've included initial conditions,~$y$ first
and~$t$ second: \begin{verbatim} ics = [y(t_0), t_0].\end{verbatim}
\end{document}
