See if we can come up with the correct parameters to model a falcon-mouse predator-prey interaction. Here is a nice Wikipedia entry on Lotka-Volterra, a thing of true beauty.
Let's try to line up with the Wikipedia article. Keep in mind they (Wikipedia) are using $x$ to be the number of prey, here mice. They are using $y$ to mean predator, here falcons. The lower-case Greek letter "delta" is $\partial$. In math, we used $\partial$ to mean "change in. So when I write $\partial x$ I mean "the change in the number of mice".
Also, in math, we like to be very precise about what exactly changed. I said the number of mice changed, but what do I mean by that? Do I mean it changed when the weather got hotter? Do I mean the number changed when I looked under a rock? What else changed to change the number of mice?
$$ \frac{\partial \mbox{Number of Rabbits}}{\partial \mbox{Number of Rocks I Looked Under}} $$This tells me: The number of mice changes when I look under more or fewer rocks. If I look under more, the number goes up, if I look under fewer, the number goes down. Typical we say "with respect to" in describing that relationship. So I'd say "The change in the number of rabbits with respect to the number of rocks I looked under."
Probably the most common thing to change "with respect to" is time. A lot of things change over time. Your height, your age, how hungry you are. Suppose $h$ is how hungry you are and $t$ is time. Then
$$ \frac{\partial h}{\partial t} $$is going up before dinner, since you are getting hungrier, and goes down at dinner, since you are getting full.
Above, I used the letter $h$ to mean how $h$ungry you are. Since $\partial$ means "change", I used $\partial h$ to mean "the change in hunger".
The notation $\frac{\partial x}{\partial t}$ means "the change in x over time". And they are using $x$ to be the number of prey, here mice. So we can interpret "the change in x over time" to be "how many mice were born today". What if $x$ is negative, like $-2$? Then, sadly, two mice died today. Don't worry, the mice will make more.
How is this guy $\frac{\partial x}{\partial t}$
The term dy/dt
means the "change in y over time", and they are using "y" to mean the number of predators, here falcons.
$$
\begin{eqnarray*}
\mbox{change in mouse population over time} &=& \mbox{mice surviving from yesterday} - \mbox{mice eaten}\\
\frac{d x}{dt} &=& \alpha x - \beta x y, \\
\end{eqnarray*}
$$
And the falcons are governed by
A | B | C | D |
---|---|---|---|
English | $\frac{dy}{dt}$ | = | $\delta x y - \gamma y$ |
First, set the working directory. Not actually sure we'll need to do this
In [ ]:
WD = "/Users/buddha/github/buddha314/predator-prey/src"
setwd(WD)
In [ ]:
# Decide how effective everyone is
falcon_hunting_success_rate = 0.005
falcon_reproductive_rate = 0.001
mouse_reproductive_rate = 0.4
# What does it look like on day one?
n_falcons_day_one = 10
n_mice_day_one = 300
n_days_to_run = 60
In [ ]:
results = data.frame(
day=1
, falcons=n_falcons_day_one
, falcons_fed = n_falcons_day_one
, falcons_born = 0
, mice=n_mice_day_one
, mice_born = 0
, mice_eaten = 0
)
In [ ]:
for (i in 2:n_days_to_run) {
print(paste("Evaluating day", i))
# Look at what we had yesterday
falcons_yesterday = results[(i-1),"falcons"]
mice_yesterday = results[(i-1), "mice"]
# Figure out how many survived from yesterday
falcons_born = falcons_yesterday * falcon_reproductive_rate # How many born yestery
falcons_fed = falcons_yesterday * falcon_hunting_success_rate * mice_yesterday # How many got to eat
# So today we have
falcons_today = falcons_fed + falcons_born
mice_born = mice_yesterday * mouse_reproductive_rate # How many born
# Below we use "min" to say that the falcons can't eat more mice than exist
mice_eaten = min(mice_yesterday, mice_yesterday * falcons_yesterday * (1-falcon_hunting_success_rate)) # How many did the falcons get
# So today we have
mice_today = mice_yesterday + mice_born - mice_eaten
# Add the new numbers to our results. We use the max(x,y) function to keep things above 0,
# you can't have -1 falcons
results = rbind(
results
, data.frame(day=i
, falcons=max(0,falcons_today)
, falcons_born = max(0,falcons_born)
, falcons_fed = max(0,falcons_fed)
, mice=max(0,mice_today)
, mice_born = max(0,mice_born)
, mice_eaten = max(0,mice_eaten)
)
)
}
In [1]:
print(results)
In [6]:
plot(falcons ~ day, type="l", col="gold", data=results)
lines(mice ~ day, col="blue", data=results)