Kernel: Python 3 (CoCalc)
Lab 1: Feedback Loops and Oscillations
Instructions for all labs (and programming in other assignments) in this course:
Write comments to help yourself and others looking at your code (including graders!)
understand your code. This should be at least 1 comment for every 5 lines of code in an
exercise, and you can see examples in our example code.
Label axes for all plots.
If you're plotting more than one time series or other items on the same axes, you should make
a legend with descriptive labels and a different color or style for each item.
We encourage you to collaborate with your team members and ask TAs and LAs for help, but
you should make sure you understand what is allowed cheating by reviewing the Academic
Integrity policy in our syllabus (including artificial intelligence).
In [4]: # Name:Gustavo Delgadillo
# I worked on this lab with: Sarai Garcia, Monica Ibrahim, Sandy Saat
# Have you read the instructions above and reviewed the Academic
Integrity policy in our syllabus? yes.
Throughout this course series, you have seen systems that oscillate. The purpose of this lab is to
take a closer look at such systems and to review important Python functions used for simulation
and plotting.
A Predator-Prey Model
Previously, we studied and simulated the Lotka-Volterra predator-prey model (which you initially
saw as the "shark-tuna model"). Now, we will study a different predator-prey model, termed the
Holling-Tanner model, that incorporates somewhat different (and more realistic) biological
assumptions.
As before, we will call our prey population N and our predator population P . We will assume that, in
the absence of predators, the prey population would grow logistically. The expression for this is the
familiar rN (1 − Nk ).
We also want an individual predator’s consumption rate to plateau as N increases so that there is a
limit to how much predators can eat. This can be done with the function f (N ) = CN +hN , where
max
Cmax is a predator’s maximum consumption rate and h is the half-saturation density, the prey
density at which consumption is half the maximum rate.
about:blank 1/13
, 4/7/26, 11:52 PM Lab 1 - Feedback Loops and Oscillations.ipynb
We can make plots by using np.linspace to generate a set of x values and then writing a formula
for the y values. We then use the pyplot function plot to generate the plot. Here is an example
that plots f (X) = 625+X
X
. 4
4
Note: most example code in this course will be given as images so you will practice typing it
yourself.
Exercise 1. Plot CN +hN for different values of Cmax and h (at least two values per parameter
max
ranging between 1 and 10), changing one value at a time. Use N range of 0-200. You can put your
plots on the same or different axes, but make sure to label which graph is which (using a legend as
shown above if you put them on the same axes). Also, label your axes.
In [4]: #write code here
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint
Cmax = 3
Cmax2 = 6
h1 = 3
h2 = 6
N = np.linspace(0,200, 1000)
y1 = (Cmax*N)/(N+h1)
y2 = (Cmax2*N)/(N+h1)
y3 = (Cmax*N)/(N+h2)
y4 = (Cmax2*N)/(N+h2)
about:blank 2/13