Python implementation of Lotka–Volterra Equations.

Lotka–Volterra Equations x = 10 y = 5 α = 0.9 𝛽 = 0.1 δ = 0.1 γ = 0.4
Lotka–Volterra Equations x = 10 y = 5 α = 0.9 𝛽 = 0.1 δ = 0.1 γ = 0.4
Lotka–Volterra Equations Phase-space plot
Lotka–Volterra Equations Phase-space plot
# © 2019 TheFlyingKeyboard and released under MIT License 
# theflyingkeyboard.net

from matplotlib import pyplot as plt
from matplotlib.ticker import FuncFormatter
from pylab import rcParams

x = 10
y = 5

a = 0.9
b = 0.1
c = 0.1
d = 0.4

step = 0.00001  # the smaller the more precise plots are
epochs = 100

xOverTime = []
yOverTime = []

for i in range(int(1 / step) * epochs):
    xOverTime.append(x)
    yOverTime.append(y)

    deltaX = a * x - b * x * y
    deltaY = c * x * y - d * y

    x += step * deltaX
    y += step * deltaY

rcParams['figure.figsize'] = 16, 9

plt.gca().xaxis.grid(True)
plt.gca().yaxis.grid(True)

plt.gca().get_xaxis().set_major_formatter(FuncFormatter(lambda x, p: format(int(x * step), ',')))

plt.xlabel("Epoch")
plt.ylabel("Population")

plt.plot(xOverTime, label="Prey")
plt.plot(yOverTime, label="Predator")

plt.legend(loc='upper right')
plt.show()

plt.gca().xaxis.grid(True)
plt.gca().yaxis.grid(True)

plt.plot(xOverTime, yOverTime)

plt.xlabel("Prey")
plt.ylabel("Predator")

plt.show()

 



Python Lotka–Volterra Equations
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. You can read more about it the Cookies&Privacy Policy Section Above. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this. You can read more about it the Cookies&Privacy Policy Section.

Close