Well, an equation with a name like this second grader thought. ** Transcendental cool. ** ** This time I would like to play with this equation with numerical calculation (python). The content of the equation itself looks like this.
\frac{dx}{dt}=\alpha x-\beta xy \\
\frac{dy}{dt}=\gamma x-\delta xy
It's a pretty good formula, but it's a formula that expresses the relationship between predation and prey **. Rest assured that it's not that difficult because it's a tinsel! !! This time, I will read it in the African setting of ** Lion vs Gazelle **.
There are many letters, but I will explain them one by one.
$ x $: Number of predators (number of gazelles), $ y $: Number of predators (number of lions)
$ \ alpha $: Predator-prey birth rate, $ \ beta $: Predator-prey rate, $ \ gamma $: Predator-prey birth rate, $ \ delta $: Predator-prey mortality rate
(Academically, there are some parts that are accurate, but we emphasize clarity)
Some people may have a ??? in their brain, but please wait for a while as it will be explained in the next section.
This is the most interesting place! !! Let's take a look at the original formula while looking at the meanings of the letters defined above.
\frac{dx}{dt}=\alpha x-\beta xy~~~~(1) \\
\frac{dy}{dt}=\gamma xy-\delta y~~~~(2)
First, let's think about (1).
\frac{dx}{dt}=\alpha x-\beta xy~~~~(1)
The left side means the rate of change over time of $ x $, that is, ** how much the gazelle increases **. So what can be thought of as an increase or decrease in gazelle? Yes, ** childbirth ** and ** death **, right? Birth corresponds to $ \ alpha x $ in the first term, and death corresponds to $ \ beta xy
Let's think about the same thing in equation (2).
\frac{dy}{dt}=\gamma xy-\delta y~~~~(2)
The left side is the time change rate of $ y
I hope you have deepened your understanding of gazelle and lion in the previous section and understood the formula. However, since differential equations cannot be handled directly by a computer, this time we will use the ** difference method ** for calculation. Suppose $ x, y $ at time $ n $ is represented as $ x_ {n}, y_ {n} $. This is
\frac{dx}{dt}=\alpha x-\beta xy~~~~(1) \\
\frac{dy}{dt}=\gamma xy-\delta y~~~~(2)
When you make a difference, it looks like this,
\frac{x_{n+1}-x_{n}}{\Delta t}=\alpha x_{n}-\beta x_{n}y_{n}~~~~(1) \\
\frac{y_{n+1}-y_{n}}{\Delta t}=\gamma x_{n}y_{n}-\delta y_{n}~~~~(2)
Solving the unknown values $ x_ {n + 1}, y_ {n + 1} $ at the next time $ n + 1 $
x_{n+1}=(\alpha -\beta y_{n})x_{n}\Delta t + x_{n}~~~~(1) \\
y_{n+1}=(\gamma x_{n} -\delta)y_{n}\Delta t + x_{n}~~~~(2)
Will be. Since the value on the right side consists of known values (constant or value at time n), the left side can be obtained simply by performing substitution calculation.
This time I wrote it in python. You can change the value of the constant as you like.
Lotka-Volterra.py
import numpy as np
import matplotlib.pyplot as plt
#coefficient
a, b, c, d = 0.3, 0.1, 0.3, 1.3
#initial value
init_x = 10
init_y = 2
#Time progress
dt = 0.01
n = 5000
#Array initialization
x = np.zeros(n)
x[0] = init_x
y = np.zeros(n)
y[0] = init_y
for i in range(1, n):
x[i] = (a - b * y[i - 1]) * x[i - 1] * dt + x[i - 1]
y[i] = (c * x[i - 1] - d) * y[i - 1] * dt + y[i - 1]
print(i, x[i], y[i])
t = np.arange(0, n * dt, dt)
plt.plot(t, x, label="Prey")
plt.plot(t, y, label="Predator")
plt.legend()
plt.show()
The result should look like the figure below.
It's interesting that the result vibrates. If you consider it in chronological order,
It has become.
Well, that's right. If the number of lions increases, the gazelle will be eaten and will decrease.
As a result of too many lions ** running out of food and starting to starve ** (I feel something like a suggestion ...). And as a result of the decrease in lions, Gazelle regains momentum and begins to increase.
As the number of gazelle increases, it becomes ** heaven ** for Lion. And the gazelle will decrease
Yes, this world goes around forever in this cycle. It makes me feel strange.
This time, I used a cool equation just named ** Lotka-Volterra equation ** to perform numerical calculations on the lion and gazelle ecosystems. I would be happy if anyone finds it interesting! I hope you like it! !!
Recommended Posts