1.7: Applications to Compartmental Analysis

Open In Colab

Reading: Section 4.1 from Exploring Differential Equations with Boundary Value Problems by William F. Trench which is shared under a CC BY-NC-SA 3.0 license.

One-Compartment Systems


A one-compartment system consists of

  • \(x(t)\) that represents the amount of a substance (such as salt or population of rabbits) at time \(t\).
  • an input rate of \(x\).
  • an output rate of \(x\).

\[\color{dodgerblue}{\boxed{\large \frac{dx}{dt} = \mbox{input rate} - \mbox{output rate} }}\]

Question 1:


A brine solution of salt water that has concentration \(0.05\) kg per L flows at a constant rate of 6 L per minute into a tank which is initially contains 50 L of a 1% salt solution. The brine solution flows out of the tank at a rate of 4 L per minute. Let \(x(t)\) denote the mass of the salt in the tank at time \(t\) (in minutes).

Note

1% salt solution means 1 kg of salt per 100 L of solution.

Question 1a:


What is the input rate of \(x\)?

Solution to Question 1a:







Question 1b:


What is the output rate of \(x\)?

Solution to Question 1b:







Question 1c:


What is the initial mass of the salt in the tank?

Solution to Question 1c:







Question 1d:


Construct a model for this initial value problem (but do not solve it).

Solution to Question 1d:







Question 1e:


What method(s) can we apply to solve the equation in Question 1d (but don’t solve it)?

Solution to Question 1e:







Population Models


The Malthusian law of population growth says the rate of change of the population, \(\frac{dP}{dt}\), is directly proportional to the population present, \(P\), at time \(t\):

\[\color{dodgerblue}{\large \boxed{\frac{dP}{dt} = kP, \quad P(0)=P_0}.}\]

Question 2:


Let \(P\) denote the population of the world (in billions) \(t\) years since \(1960\). In 1960 the world’s population was approximately 3 billion, and the population growth is model by \[\frac{dP}{dt} =0.02P , \qquad \ P(0)=3.\]

Solving this model gives \(P(t)=3e^{0.02t}\), and predicts the population in 2025 is \(11.01\) billion.

Why do you think predicted value is different from the actual value?

Solution to Question 2:







The Logistic Model


We can construct our population model by considering:

\[\color{dodgerblue}{\large \frac{dP}{dt} = \bigg( \mbox{Birth Rate} \bigg) - \bigg( \mbox{Death Rate} \bigg).}\]

Competition within the population causes the populations to decrease (disease, murder, natural disasters, war, lack of food/water). If we assume the death rate is proportional to the total number of possible two-party interactions, we get:

\[ \mbox{Death rate} = k_2 \left( \begin{array}{c} P\\ 2 \end{array} \right) = k_2 \left( \frac{P(P-1)}{2} \right) .\]

Note

\(\left( \begin{array}{c} P\\ 2 \end{array} \right)\) denotes “\(P\) choose 2”, and in general we have \(\displaystyle \left( \begin{array}{c} n\\ k \end{array} \right) = \frac{n!}{k!(n-k)!}\).

Taking both the birth and death rates into account, we get the Logistic model for population change which we simplify:

\[\frac{dP}{dt} = \bigg( \hspace{1in} \mbox{??} \hspace{1in} \bigg) - \bigg( \hspace{1in} \mbox{??} \hspace{1in} \bigg) .\]

Question 3:


Replace the ?? in the formula above with an appropriate expression. Then show that the model above can be rewritten in the form \(\dfrac{dP}{dt} = -AP(P-L)\) where \(A\) and \(L\) are positive constants.

Solution to Question 3:






Enter your answers in place of the two ??’s in the previous Markdown cell.


Practice: Population Model for Rabbits


Rabbits in Australian Outback 1938 Map of Rabbit proof Fence Rabbit Proof Fence in 2005
CSIRO ScienceImage 1516 Rabbits around a Water Trough Rabbit proof fence in western australia Rabbit proof fence in 2005

Image Credits Wikimedia Commons,CC BY-SA 3.0

Question 4:


A population of rabbits changes over time \(t\) (in years) according to the logistic model \[ \frac{dP}{dt} = 3P-\frac{1}{20}P^2. \]

Question 4a:


For what initial population sizes \(P_0\) will the population grow at first?

Solution to Question 4a:







Question 4b:


For what initial population sizes \(P_0\) will the population decrease at first?

Solution to Question 4b:







Question 4c:


For what initial population sizes \(P_0\) will the population never change?

Solution to Question 4c:







Question 4d:


Explain, in practical terms, why answers in (a)-(c) makes sense.

Solution to Question 4d:







Question 4e:


If the initial rabbit population is \(P_0=P(0)=50\), find a solution to the initial value problem and find a formula for the population \(P\) as a function of time \(t\).

Solution to Question 4e:






You may solve “by hand” without technology or feel free to play around with the code cells below to help with some of the computations.


# Partial Fraction Decomposition 
import sympy as sym  # import sympy

# t, P are variables, B is constant of integration
t, P, B = sym.symbols('t, P, B')  

#################################
# STUDENT TO DO:
# Replace ?? with an expression
#################################
left = ?? # Left side of the equation after separating ODE

leftsimp = left.apart(P)  # Partial frac decomp left side

print(leftsimp)
# Integrate both sides after decomposing left side

leftint = sym.integrate(leftsimp, P)  # integrate left
rightint = sym.integrate(-1/20, t) + B  # integrate right with +B added

print("Integral on the left side with respect to P is", leftint,
      "\n \n Integral on the right side with respect to t is", rightint)
from sympy.solvers import solve

solP = solve(leftint - rightint, P)  # finds explicit solution

print("P = ", solP)  # Prints explicit solution

Practice: Chlorine Levels in Pool


Question 5:


A swimming pool whose volume is 10,000 gallons contains water that is \(0.01\)% chlorine. Starting at \(t=0\), city water containing \(0.001\)% chlorine is pumped into the pool at a rate of 5 gal/min. The pool water flows out at the same rate. Let \(x\) denote the amount of chlorine (in pounds) in the pool \(t\) minutes since water has begun being pumped into the pool.

A concentration of \(0.01\)% chlorine solution means \(0.01\) pounds of chlorine per 100 gallons of solution.

Question 5a:


Construct a differential equation for rate of change of the mass of chlorine (in pounds) \(x\) in the pool at time \(t\).

Solution to Question 5a:







Question 5b:


Solve the initial value problem using the differential equation in (a) and the given initial % concentration.

Solution to Question 5b:



Question 5c:


When will the pool water be \(0.002\)% chlorine?

Tip

Try using the solve function imported from the sympy.solvers package.

Solution to Question 5c:







#import sympy as sym  # already imported
#from sympy solvers import solve  # already imported

t = sym.Symbol('t')

###############################################
# STUDENT TO DO:
# Replace each ?? with an expression or value
###############################################

tsol = solve(?? - ??, t)  # solve for t

print(tsol)

Appendix: A General Formula for Solution to the Logistic Population Model


The Logistic Model in general has the form:

\[\dfrac{dP}{dt} = -AP(P-L) \quad \mbox{with $A$ and $L$ denoting constants.}\]

In Question 4, you found a solution to one such model using partial fraction decomposition. Let’s generalize the solution to find a convenient formula for solutions to logistic models that we can refer to.

One possible process could be:

  1. Separate the differential equation:

\[ \frac{1}{P(P-L)} \, dP = -A \, dt\]

  1. Rewrite the fraction on the left side as a sum of two fractions with undetermined coefficients denoted \(\color{dodgerblue}{M}\) and \(\color{dodgerblue}{N}\) that we find.

\[ \left(\frac{\color{dodgerblue}{M}}{P} + \frac{\color{dodgerblue}{N}}{P-L}\right) \, dP = -A \, dt\]

  1. Integrate both sides with respect to the appropriate variable.

  2. Solve for \(P\) to derive an explicit solution.

We break these steps up in the code cells below.

Partial Fraction Decomposition with SymPy


The code below performs partial fraction decomposition on the left side of the differential equation (after separating).

  • The function apart in the SymPy library is very handy for this!
import sympy as sym  # import sympy

t, P = sym.symbols('t, P')  # t and P are variables

L = sym.symbols('L', real = True, constant = True)  # Constants

left = 1/(P * (P-L))  # Left side of the equation after separating

left.apart(P)  # Partial frac decomp left side

Integrate Both Sides


The code cell below uses sympy.integrate to evaluate integrals.

frac1 = 1/(L * (P - L))
frac2 = -1/(L * P)

A, B = sym.symbols('A, B', real = True, constant = True)  # Constants

leftint = sym.integrate(frac1, P) + sym.integrate(frac2, P)  # integrate left
rightint = sym.integrate(-A, t) + B  # integrate right with +B added

print("Integral on the left side with respect to P is", leftint,
      "\n \n Integral on the right side with respect to t is", rightint)

Finding an Explicit Form: Solve for \(P\)


We use the solve function from the solvers library in SymPy to find an explicit solution for \(P\).

from sympy.solvers import solve

sol = solve(leftint - rightint, P)  # finds explicit solution

print("P = ", sol)  # Prints explicit solution
sym.latex(sol)  # convert solution to latex

Simplifying the Explicit Solution


The output above gives LaTeX code for an explicit solution for \(P\) in terms of \(t\) (as well as constants \(A\) and \(L\)).

  • The LaTeX in the output above uses a double backslash \\ instead of a single backslash \.
  • After replacing each \\ in the LaTeX code from the output above with \ we get the solution below.
  • Then we simplify the right side.

\[\begin{array}{lrc} P &=& \dfrac{L^{2} e^{L \left(A t - B\right)}}{L e^{L \left(A t - B\right)} - 1}\\ &=& \dfrac{L}{1- e^{-L(At-B)}}\\ &=& \dfrac{L}{1- e^{-ALt+LB}}\\ &=& \dfrac{L}{1 {\color{tomato}{-e^{LB}}}e^{-{\color{dodgerblue}{AL}}t}}\\ &=&\dfrac{L}{1+ {\color{tomato}{C}}e^{-{\color{dodgerblue}{k}}t}} \end{array}\]

From the work above, we have the following solution for the Logistic model:

\[\boxed{\large{P = \dfrac{L}{1+ {\color{tomato}{C}}e^{-{\color{dodgerblue}{k}}t}} \quad \mbox{with } {\color{dodgerblue}{k=AL}}}}.\]

Note

The constant \(\color{tomato}{C}\) depends on the initial condition. Set \(t=0\) and \(P=P_0\), and then solve for \(\color{tomato}{C}\).

Creative Commons License Information


Creative Commons License
Exploring Differential Equations by Adam Spiegler is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Based on a work at https://github.com/CU-Denver-MathStats-OER/ODEs and original content created by Rasmussen, C., Keene, K. A., Dunmyre, J., & Fortune, N. (2018). Inquiry oriented differential equations: Course materials. Available at https://iode.sdsu.edu.